Help receiving HTTP Events from Raspberry Pi


(Stuart) #1

I have built a two door Garage Door controller using a Raspberry Pi. I can open close/doors using HubAction. It works well except I have to poll the status, what I need is real-time events when the door status changes.

On an event I want to make HTTP requests from the RPi to the Hub. Inbound HTTP Requests are mentioned very very briefly at the bottom here:

http://docs.smartthings.com/en/latest/cloud-and-lan-connected-device-types-developers-guide/building-lan-connected-device-types/building-the-device-type.html

Not much info, but I’ve added a endpoint mapping to the device type:

mappings {
  path("/GarageController/1/status") {
    action: [
      GET: "updateStatus"
    ]
  }
}

And I get a callback address like this (which I pass to the RPi using HTTP):

def ip= device.hub.getDataValue("localIP")
def port= device.hub.getDataValue("localSrvPortTCP")

This gives me e.g. 192.168.0.101:39500 which does suggest that this port is ready to go. But when the RPi makes the HTTP status request a TCP SYN is sent, there is no ACK (checked with Wireshark) - it’s closed.

Why isn’t open? How do I open it?

Has anybody got HTTP events working? Or ideas? Or is there an example close to this that uses incoming HTTP requests?

Thanks.


How to send data from my LAN connected device to HubV2?
SmartThings Labs and LAN Devices
(Geko) #2

Just curious, if you actually called HubAction(method: "SUBSCRIBE", ...
I suspect this where the the inbound port might get open. This is guessing, of course. Documentation is horrible indeed.


(Stuart) #3

I will try that. It’s an interesting thought.


(Stuart) #4

Indeed that did result in the socket. However I am fairly certain this is for upnp subscriptions, whereas I want simple Inbound HTTP Requests. Still it’s progress.


(Geko) #5

UPnP events are sent as HTTP NOTIFY messages with SOAP payload. But I don’t think that the hub does any parsing. If true, then entire response should be base64-encoded and handed to the SmartApp in the location event. So with some luck you should be able to use GET or POST. Keep us posted (pun intended :slight_smile: )


(Stuart) #6

Thanks for the help. But in the end I gave up and did it via OAuth instead. It is a rather long winded way to move a message two inches across a shelf, but it’s relatively well documented and didn’t take long to integrate and get working.

OAuth is not too painful on an RPi either.


(zraken) #7

Stumbled on this thread while I was banging my head against a brick wall trying to get Inbound HTTP to work! Anyway, I would appreciate it very much if you could post your code for how you got ST to listen to events from RPi. Thanks.


(Stuart) #8

It’s here: https://github.com/lttlrck/smartthings/tree/master/garageController

It’s not quite fit for human consumption, but it has been running perfectly since I last visited this thread. The latency from RPi > Smartthings > Hub is < 1 second so perfectly acceptable for this application.

garageController.js line 102 onwards is the OAuth notification.

Note: there are some hardcoded modifications in upnp-ssdp.


(trac starr) #9

Any chance anyone has figured out how to call the local ip with get/post ? I really don’t want to have my LAN service calling via the WAN url.


(Garnet) #10

@tracstarr: The WeMo Motion device code uses the LAN events…from what I can tell. I have been trying to figure it out, but so far it’s beyond my ability. Hopefully someone can figure this out.


(trac starr) #11

Thanks, i’ll check it out. If it doesn’t cause me convulsions like everything else - I’ll post back my results.


#12

Did anybody look further into the Wemo motion device type (or find some other bi-directional HTTP framework) as an example of push+pull Raspberry Pi integration?

I see a few other examples of Wemo UPNP listeners out there (not for ST). This is a good post that should help us decipher what the Wemo Motion template is doing in the Groovy/ST context.

WEMO EVENT NOTIFICATIONS

Here’s an RPi library that might provide similar (to the WEMO) features:

PiPoint - A simple DLNA control point


(Andy Rawson) #13

I have been playing a little with this and it works for a day or two and then stops updating in ST. It uses UPNP/SSDP. https://github.com/rllynch/pi_garage_smartthings


#14

Are you seeing this message logged when you run the app in the IDE?

log.debug "subscribeToDevices() called"

I notice that he did a commit only a few hours ago with this comment:

Unschedule all jobs prior to rescheduling subscribeToDevices

It looks, from the comment, as if the author intended it to run every ten minutes. This was changed in the most recent commit too.

schedule("0 */10 * * * ?", "subscribeToDevices")

I’m not so cron-savvy so I might try this form in my app:

runEvery10Minutes(handlerMethod)