k0m37
September 17, 2017, 8:13pm
1
Hi,
I try to send data via TCP API with nested objects, but can’t access them within a rule.
Example:
echo ‘{“k”: “key_here”,“d”: {“data1”: “1”, “data2” : “2” }, “t”: “TOPIC1”}’ | nc -i1 cloudsocket.hologram.io 9999
ist accepted by API.
But I can*t access data in rule with <<decdata.data1>>.
RAW-view is showing that data was’nt encoded
"data": "{\"data1\": \"1\", \"data2\": \"2\"}"
result_data":"Error decoding data for variable ‘decdata.data1’
What’s wrong?
Kind regards
Kai
Reuben
September 17, 2017, 8:21pm
2
Hmm can you try sending data as a json-encoded string like:
"d":"{\"data1\":\"1\"}"
k0m37
September 18, 2017, 3:10pm
3
Works!!!
echo ‘{“k”: “key_here”,“d”: “{"data1": "1","data2": "1"}”, “t”: “TOPIC1”}’ | nc -i1 cloudsocket.hologram.io 9999
Thank you
Kai
Reuben
September 18, 2017, 3:13pm
4
Ok cool, glad that’s working. We’re going to add better nested json support in there in the future
I was not able to get this working with nested JSON nor data as a JSON-encoded string. Any ideas how I might get this working? Here is the payload (w/ data as JSON-encoded string):
const char *tpl = "{ \"k\": \"%s\", \"t\": \"STATS\", \"d\": \"{ \"lat\": \"%s\", \"lon\": \"%s\" }\" }";
snprintf(state.getBuffer(), 256, tpl, HOLOGRAM_DEVICE_KEY, latBuf, lonBuf);