Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

LaMetric with EG

If you have a question or need help, this is the place to be.
Post Reply
User1306
Experienced User
Posts: 53
Joined: Sat Oct 13, 2012 4:37 pm

LaMetric with EG

Post by User1306 »

HI Guys
i backed a project on Kickstarter Called LaMetric. it's basiclly an LED display that shows all kind of info from different sources.
it can display a couple of letter (i think around 12) and an icon image in RGB colors. please have a look https://lametric.com

they have a developer platform so you can create your own feed and send whatever text you want to the device, its a neat idea and i think with the power of eventghost you can do quite a lot with it.

if you create an account on (https://lametric.com/creators) (it will take less than a minute) then you can create your own feeds
they provide you with a simple code, i'm try to turn this code into Python script and have the text field fed with different info from EG, but for some reason i keep getting errors when i try to test it. the code i modified is below, please have a look and let me know why its not working?


this is the sameple code they give you

Code: Select all

curl -X POST \
-H "Accept: application/json" \
-H "X-Access-Token: [MY-TOKEN]" \
-H "Cache-Control: no-cache" \
-d '{
    "frames": [
        {
            "index": 0,
            "text": "xxx",
            "icon": "a87"
        }
    ]
}' \
https://developer.lametric.com/api/V1/dev/widget/update/com.lametric.(API)/1

and this is my code turned into Python

Code: Select all

import requests

headers = {
    'Accept': 'application/json',
    'X-Access-Token': 'MY-TOKEN',
    'Cache-Control': 'no-cache'
}

payload = {
    "frames": [
        {
            "index": 0,
            "text": "<TEXT FROM EG GOES HERE>",
            "icon": "null"
        }
    ]
}

requests.post('https://developer.lametric.com/api/V1/dev/widget/update/com.lametric.(API)/1', headers=headers, json=payload)



if anyone have any clue please let me know, maybe in the future we could create a plugin, it's very handy at displaying quick info

Thank you in advance
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: LaMetric with EG

Post by Pako »

What kind of error you get?
You used the latest version EventGhost?

Pako
User1306
Experienced User
Posts: 53
Joined: Sat Oct 13, 2012 4:37 pm

Re: LaMetric with EG

Post by User1306 »

thanks for taking a look at it. below is the error i get (i just removed my API)

Traceback (most recent call last):
Python script "2", line 19, in <module>
requests.post('https://developer.lametric.com/api/V1/d ... tric.(API)', headers=headers, json=payload)
File "C:\Program Files (x86)\EventGhost\lib26\site-packages\requests\api.py", line 88, in post
return request('post', url, data=data, **kwargs)
File "C:\Program Files (x86)\EventGhost\lib26\site-packages\requests\api.py", line 44, in request
return session.request(method=method, url=url, **kwargs)
TypeError: request() got an unexpected keyword argument 'json'



the Eg version i have is this (0.4.1.r1700)

thanks

Edit: i just saw there's a new version, i will update it now and try again
Edit 2: after updating (r1706) i still have the same issue
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: LaMetric with EG

Post by Pako »

Here I see bug:
User1306 wrote:requests.post('https://developer.lametric.com/api/V1/d ... tric.(API)', headers=headers, json=payload)
TypeError: request() got an unexpected keyword argument 'json'
It is likely to be as follows:

Code: Select all

requests.post('https://developer.lametric.com/api/V1/dev/widget/update/com.lametric.(API)', headers=headers, data=payload)
Pako
User1306
Experienced User
Posts: 53
Joined: Sat Oct 13, 2012 4:37 pm

Re: LaMetric with EG

Post by User1306 »

Thank you very much for your reply Pako.

i actually had it set to Data at first and it didnt not work, i checked with LaMetric support and they suggested to make switch it to json.
the good news i'm not getting an error in EG anymore, the bad it's not displaying the message. i need to figure out if its from my code or their end.
Doktor J
Posts: 2
Joined: Fri Oct 09, 2015 5:15 pm

Re: LaMetric with EG

Post by Doktor J »

You could try making your payload a string, e.g.

Code: Select all

egoutput = "<DATA FROM EG GOES HERE>"
payload = """{
    "frames": [
        {
            "index": 0,
            "text": "%s",
            "icon": null
        }
    ]
}""" % (egoutput)
In my PHP script I found it played much nicer when I stringified the JSON and kept it pretty-printed. Note that, when stringified, "null" should not be in quotes if you want no icon.

DISCLAIMER: I haven't used EventGhost, and am a bit rusty on my Python. I'm a new LaMetric app developer, and discovered that they're very fussy about the JSON formatting.
Doktor J
Posts: 2
Joined: Fri Oct 09, 2015 5:15 pm

Re: LaMetric with EG

Post by Doktor J »

I actually just wrote a Python push script for my LaMetric (inspired by your post!) and confirmed that stringified, pretty-printed JSON seems to be happy:

Code: Select all

import json
import requests

# Put in your access token of course
headers = {
    'Accept': 'application/json',
    'X-Access-Token': '',
    'Cache-Control': 'no-cache'
}

#
# Your code that gets data and puts it into JSON goes here
#

payload = json.dumps(myJSONVar, indent=4, separators=(",", ": "))

# Your app ID and version should go here, e.g. "com.lametric.abcdefabcdef12341234" and "3"
appid = "xxxxxxx"
ver = "3"

try:
    q = requests.post("https://developer.lametric.com/api/V1/dev/widget/update{0}/{1}".format(appid, ver), data=payload, headers=headers)
except (ConnectionError, HTTPError, Timeout, TooManyRedirects) as e:
    print "Error {0}: {1}".format(e.errno, e.strerror)
    pass
else:
    print q
Of course you can knock off the "else" part of the try if you don't need it to print the output; otherwise you should get <200 success> as your output.
User1306
Experienced User
Posts: 53
Joined: Sat Oct 13, 2012 4:37 pm

Re: LaMetric with EG

Post by User1306 »

Thank you very much for checking it out. i'm very new to python my self too, so no worries.

i tried your code but i'm getting a 404 response.

this is the complete code without Token and app ID

Code: Select all

import json
import requests

# Put in your access token of course
headers = {
    'Accept': 'application/json',
    'X-Access-Token': 'xxxxxx',
    'Cache-Control': 'no-cache'
}

egoutput = "Testing123"
myJSONVar = """{
    "frames": [
        {
            "index": 0,
            "text": "%s",
            "icon": "a1036"
        }
    ]
}""" % (egoutput)


payload = json.dumps(myJSONVar, indent=4, separators=(",", ": "))

# Your app ID and version should go here, e.g. "com.lametric.abcdefabcdef12341234" and "3"
appid = "com.lametric.xxxxxxxxxx"
ver = "1"

try:
    q = requests.post("https://developer.lametric.com/api/V1/dev/widget/update{0}/{1}".format(appid, ver), data=payload, headers=headers)
except (ConnectionError, HTTPError, Timeout, TooManyRedirects) as e:
    print "Error {0}: {1}".format(e.errno, e.strerror)
    pass
else:
    print q

how did you parse the JSON exactly?
really appreciate your help, i'm looking forward to be able to send all kind of info to LaMetric

Edit: i realized their site is acting super slow and sometimes just hangs there, dunno if that's related

Edit 2:

Turning the json into string like you mentioned first with the code i posted did the trick :).
that's good enough for now.

thanks for your help
Post Reply