Currently, I have multiple Particles. variables(<class ‘sseclient.Event’>, format) and each is returning a single value. I would like to combine all of them into one JSON formatted variable. Any good tutorial you guys can recommend that goes over this? As always appreciate all the help!
particle events:-
<class ‘sseclient.Event’>
{“data”:"{“cmd”:“loc”,“time”:1615447060,“loc”:{“lck”:1,“time”:1615447062,“lat”:17.36686325,“lon”:78.50415039,“alt”:430.215,“hd”:180.76,“h_acc”:2.500,“v_acc”:4.900,“cell”:76.2,“batt”:93.1,“temp”:34.6},“trig”:[“time”],“req_id”:130846}",“ttl”:60,“published_at”:“2021-03-11T07:17:43.229Z”,“coreid”:“e00fce689aeaba685bcfe465”,“userid”:“5fe99e8e8d4b305a39783fdc”,“version”:11,“public”:false,“productID”:12878}
convert it to json or python dictionary
Thanks
Just a clarification here: Particle.variable()
s are not server sent events.
However, in order to transport multiple values in a single Particle.variable()
you’d go for string variables which you can format as you wish, including JSON format.
You can either do that “manually” via snprintf()
, use the JSON Writer class(es) provided by device OS or use one of the JSON generator libraries .
I am using the Tracker one device, I am not sure it’s programmable.
If it is please share some blog or documentation to customize it.
I am trying to implement this in python using SSEClient python library
from sseclient import SSEClient
sparkURL = ‘https://api.particle.io/v1/products/tracker-one-12878/devices/xxxxxxxxxaeaba685bcfe465/events?access_token=52xxxxxxxxxxxxxxxxxxxxx ’
messages = SSEClient(sparkURL)
for msg in messages:
print(msg)
print(type(msg))
output of above code is :-
<class ‘sseclient.Event’>
{“data”:"{“cmd”:“loc”,“time”:1616398771,“loc”:{“lck”:1,“time”:1616398773,“lat”:17.36680412,“lon”:78.50416565,“alt”:443.677,“hd”:262.12,“h_acc”:3.500,“v_acc”:5.500,“cell”:60.3,“batt”:98.4,“temp”:37.2},“trig”:[“time”],“req_id”:1566}",“ttl”:60,“published_at”:“2021-03-22T07:39:34.918Z”,“coreid”:“e00fce689aeaba685bcfe465”,“userid”:“5fe99e8e8d4b305a39783fdc”,“version”:11,“public”:false,“productID”:12878}
<class ‘sseclient.Event’>
it’s in server sent format
@mohammednisar623 This is an old post but I think exactly what you are looking for. Subscribe to spark events using python - #7 by jgskarda It has the snippet of code I used to parse the JSON formatted string MSG to be a python dictionary. Hope that chunk of code helps!
Yes, TrackerOne is fully programmable but you need Particle Workbench and the Tracker Edge firmware as a base.
https://docs.particle.io/tutorials/asset-tracking/tracker-edge-firmware/
Thank you very much @ScruffR
system
Closed
December 13, 2021, 6:56pm
7
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.