Multiple Device Handlers talking to a single Rest API


#1

I have a single RPi that has a berryio rest api with rest commands for monitoring multiple different functions. I would like to have multiple ST device handlers (one for each separate function) all talking to that single IP:port (or MAC) rest interface. I use HubAction to send the rest commands. I can get it to work with one Device handler, however, when I try to have a second one, I get into trouble with the unique Device Network ID since it gets set to the same rest device. Once you try to do a second device handler using the same rest api endpoint, then it does not work and causes the first device handler to stop working. They both can send rest commands and the rest device gets them and responds, but I no longer get any parse responses in either device handler. Once it is in this mode, none of them work again, even when one of them is deleted, or the hub is reset.

  1. is there any way to do multiple device handlers to the same rest device (I have seen a few things on randomizing the deviceNetworkId after using it, or talk about possible new callback functions but I don’t think ST ever implemented them)

  2. Once in this mode of no device handler will receive parse responses, how do I get out of it so that at least one device handler will work again? (Without just retiring the impacted IP address and changing to another IP)

Thanks


(Eric) #2

Not sure if you ever got an answer to this but I was searching for something else and come across your question. Are you using oauth? I didn’t think you called device handlers through REST you are actually calling the device. It associates the MAC address from the client (your RPi) with the device.deviceNetworkId which is how ST things knows which device is associated with the incoming request which then the devicehandler gets executed based on the device it’s associated with. So I don’t see how you’d set 2 device.devicesNetworkIds to the same MAC address and even if you could how would ST know which device’s devicehandler to execute?

Look at oauth and use a SmartApp instead and that will allow you to call whichever SmartApp you want to from 1 RPi. Sorry if you already figured this out, just thought I’d throw my 2 cents in when I found this. You can look at this thread for an example of calling oauth from an esp8266. The thread is deprecated but the information is still valid.