Help with HTTP Post JSON - Particle Photon

I’m trying to send commands to a Particle Photon using an HTTP Post; I’m building a Particle powered “vacation monitor” that I can take to hotels or anywhere with a wifi network that can trigger audible and visual feedback in response to OH switches that are defined in an item file; the main use case is letting me know about intrusion alarms or other issues without relying on my phone (which could be on do not disturb, etc.)

My point is that I don’t want to use MQTT or a similar service; I’d rather send an HTTP Post command to the Particle web service to trigger these Particle functions. I tried using IFTTT: it works but with an unacceptably long delay.

@guessed, I looked at your example in a different thread as a starting point. It’s not working as expected. I don’t have experience working with JSON so I’m looking for someone to tell me if there’s something glaringly wrong with my code.

particle.rules:


val String MY_URL = 'https://api.particle.io/v1/devices/mydeviceid'
var String myData = '{
    "ohc": {
    "access_token": mytoken,
    "args": "AlarmOn",
    }
}'

rule "Openhab Particle Monitor"
	when
		Item OHMonitor changed to ON
	then
		sendHttpPostRequest(MY_URL, "application/x-www-form-urlencoded", myData)
end

My Particle function is ohc, the argument I’m looking to trigger is AlarmOn. Obviously mydeviceid and mytoken are stand-ins for my actual tokens.

You can use the existing Garadget binding to talk to your Particle devices. It handles all the OAuth and messages already!

I will contribute a Particle binding for openHAB 2 that does device discovery, etc., partially based on the Garadget binding.

I saw the Garadget binding but didn’t realize it worked with other Particle applications - thanks!

1 Like

Let me know if you hit any issues, but it’s “straight Particle” in terms of device ID, functions, variables, and dynamically adjusts to the item types it’s bound to, so it ought to work for any Particle application. The OH2 version will support SSE events for near real-time item updates, but the Garadget binding has an adjustable polling cycle in the meantime.

I won’t have a chance to try it for a few days; I’ll update you when I’ve had a chance to dig in.

1 Like

@watou I am trying to use this on oh2, (it was available in Paper) but I don’t see anything in the Particle Console.

I set up the account username/password in the Paper config. I am just trying to send a simple command to the core which is listening via a function. (Spark.function(“color”, color);Spark.function(“color”, color):wink:

String neoPixelTest “Neopixel [%s]” { garadget=">[xxxxxxMYDEVICEIDxxxxx#color]" }

Any thoughts? Should this work in Openhab2? I don’t see any problems to why its not.

B

Hi Bill,

All I can offer are:

  • suggestion to turn on trace (verbose) logging, which you can do from the openHAB console:
openhab> log:set TRACE org.openhab.binding.garadget

and then

openhab> log:tail

(end with Control-C) to see if you see any activity from the binding every refresh cycle. You should see “Polling Garadget devices” every cycle.

Hope this helps!

@Billmans, I don’t ever see anything in the Particle Console from this binding. At least in my case it doesn’t seem to affect functionality and I can’t speak to whether this is intended or not. Good luck!

@watou, I forgot to thank you for your help. I got it working and, thanks to your binding, released my work as the “Openhab Particle Monitor” on Github. It uses an Internet Button to make notifications.