I’m testing my system from the CLI. I’ve got one terminal window open that is subscribe to all of my events using the following command:
particle subscribe mine
In another terminal window I’m attempting to publish an event. My Photon already has the code to subscribe and process the incoming data, so I’m trying to verify the CLI to Particle Cloud to Photon connection and processing.
In the CLI I want to input something like the following:
particle publish machineRequest {“mode”:0,“setPoint1”:100,“setPoint2”:100}
However, when I look at the terminal window showing the events, I get the following showing up:
{“name”:“machineRequest”,“data”:"“mode”:0",“ttl”:“60”,“published_at”:“2016-05-18T18:27:34.633Z”,“coreid”:“001”}
It appears the JSON isn’t escaped properly and not getting passed through in whole. I though I had this figured out a week ago, but now for the life of me I can’t remember how I did it. Any guidance is certainly appreciated.
This should work:
particle publish machineRequest "{mode:0,setPoint1:100,setPoint2:100}"
If not, this should:
particle publish machineRequest "{'mode':0,'setPoint1':100,'setPoint2':100}"
Thank you, that is helpful and in fact exactly what I needed. Also I found out the “notepad” I was copy/pasting from must have been including extra characters or data as it was making the command line perform a continuation instead of executing the command.
Thank you again!
1 Like
Thanks for the webhook tutorial @rickkas7- it explains things well.
Unfortunately, I’m unable to the get the Moustache variables working. What am I missing?
webhook.json
{
"event": "turkey",
"url": "http://requestb.in/wadhojwa",
"requestType": "POST",
"json": {
"name": "{{PARTICLE_EVENT_NAME}}",
"value": "{{PARTICLE_EVENT_VALUE}}",
"a":"{{a}}",
"b":"{{b}}",
"c":"{{c}}"
},
"mydevices": false,
"noDefaults": true,
"responseTopic": "{{PARTICLE_DEVICE_ID}}/hook-response/{{PARTICLE_EVENT_NAME}}"
}
On the Particle CLI:
particle webhook create webhook.json
particle publish turkey {"a":12,"b":34,"c":"testing"}
requestb.in response showing empty values:
{"c":"","b":"","a":"","value":"a:12","name":"turkey"}
It’s a shell escaping problem, not a webhook problem. The double quotes are being taken out by the shell, so you need to escape the whole data string with single quotes:
particle publish turkey '{"a":12,"b":34,"c":"testing"}'
1 Like
That did the trick. Thank you @rickkas7.
1 Like