How to send data from my LAN connected device to HubV2?


(St. John Johnson) #4

Okay, so I found these posts:

And I got to a pre-release version of the docs, I think:

But I still can't figure it out, I think I'm missing the subscribe portion, but the docs only talk about upnp.

(Kristopher Kubicki) #6

Hey @stjohn

Check this thread out where I create an endpoint for my camera system:

(St. John Johnson) #7

Thanks, @Kristopher! In this case, it looks like you're doing an OAuth web call. I was hoping to keep my calls inside my LAN. I'll save this for a last resort.

(Brice; #8

As far as I know, its not possible to send data over the LAN to the hub and have it received via a device/SmartApp except via UPnP. This is the reason that the current version of ObyThing Music only communicates hub -> Mac and not the other way, and the new version uses OAuth to communicate back to the hub.

(St. John Johnson) #11

Here is a piece of code I'm trying to play with to experiment:

To run it, just do:

npm install
npm start

It default uses port 8000, you can change it at the last line of the javascript.

(St. John Johnson) #14

Wow, this really needs to be in the documentation. Thank you so much for your help with this!

Is there anything I can do to support multiple device types for the same raspberry pi?

(Patrick Stuart [@pstuart]) #15

This isn't really a callback, its just a response to an outbound lan request. The hub still needs to open a port outbound and wait for a response.

The hub ip and port (or mac) will not remain open for any responses (wish it would) for longer then 10 seconds as well.

Hopefully these things will change one day.

(Patrick Stuart [@pstuart]) #18

I understand what the code is doing, it is opening up the port, but if it stays open then that is interesting.

If you set the DNI to your computer's mac (or IP:PORT) and hit this url and send something, I wonder if it will work without the refresh?

I'll check when I get home... This could be very useful if it stays open.

(Patrick Stuart [@pstuart]) #21

Confirmed, this does work.

(St. John Johnson) #22

Okay, so this works perfectly. But I still have the problem that I want to support multiple devices for the same Raspberry Pi. How can I do that and still send push events to it?

What if I have four motion sensors hooked up to the Pi and I want to send four different motion events?

(Dan) #23

@stjohn I have plenty examples of multiple similar devices attached to one Arduino that you can use as a starting point. Check out my Multiplexer SmartApps and virtual device types in my github repository. Lots of discussions here as well which you will find helpful.

My hope is to add LAN connected support to my ST_Anything project, so you'd have the option of either the ThingShield or an Ethernet Shield to communicate with the ST Hub.

Longer term, port ST_Anything to Raspberry Pi and possibly Windows.


[RELEASE] Absolute Simplest ESP8266 Smart Blinds, no mqtt, rest, bridge, or broker, just your board and your hub
ESP8266 TLS Communication
(Colin) #24

Just to clarify, the MAC address entered into the "Device Network Id" field must be uppercase without colons (i.e. 4D3005HB6334, not 4d:30:05:hb:63:34). The parse method seems to not be called otherwise.

(Michael) #26

I can get the esp8266 to post to smartthings when I press polling but no future updates without pressing polling again. I am just monitoring ST logs and not worried about the device value. I have the MAC address in the Device Network Id with out colons.

Device Type - Only worried about logging output

Arduino esp8266 sketch

(Joe Jarvis) #27

Did you solve the problem of multiple devices? I found that the device network id needs to be unique so if i wanted to support 4 different smart thing devices from the same machine (windows in my case) then i can only add one to device on that mac address.

(St. John Johnson) #28

I haven’t solved it yet, sadly. I’ve moved on for a bit and I’ll probably come back in a month or so.


Is this still working for everyone? I’m seeing very odd behavior with the “mac” field received/reported by my hub. I’ve been following along on some of these threads as I’m trying to create a custom LAN device. Ultimately, I’ll have a Raspberry Pi sending events to my hub, but for now I’m just trying to get things working on a Linux VM.

I’ve started with Charles_Schwer’s examples, and I’ve even gotten them working a few times. The problem is, it’s very inconsistent. When testing, I’m looking for the debug statements in parse() to show up. However, I find that more often than not, I see nothing for the device appear under ‘Live Logging’. Instead, I’ve found that these events are appearing in the “Events List” for the hub. Here, I’m able to see the event content, and I’m finding that the value in the “mac” field is not matching the MAC address of my Linux VM, but rather random devices on my network. Rebooting the hub sometimes causes things to work again, though they’ll eventually go awry again. Usually though, a reboot just causes a different invalid MAC address to appear here.

Here’s what’s really strange - if I change the network ID for the device to match this incorrect MAC address as reported by ST, the events are parsed correctly again and I see the debug messages appear in the “Live Logging.” I’ve tried sending these events from other VMs and hosts on my network, but I’m pretty consistently getting the same results.

I’m at a loss here. I’ve got a support ticket opened and I’m waiting for a response from ST, but I’m curious if anyone else has seen some odd behavior. It’s possible I’m doing something wrong, but I’ve checked things over thoroughly and I’m fairly confident in my work. I’m new to groovy and ST programming, but I’m a career software engineer, so this certainly isn’t uncharted territory for me.


@stjohn and others… just ran across this thread and wanted to share a nodejs service I wrote a while back to solve this exact problem. Basically it acts as a proxy and allows you to post data back to the ST Hub as you see fit; it’s built in such a way that all you have to do is write a connector (several available in git) to do what you want and communicate asynchronously and bi-directionally with the ST Hub. You need to write a SmartApp to handle all the inbound messages and route to the correct device, but the benefit is that you don’t need to deal with the pesky MAC address matching that takes place at the device level…

(codersaur) #31

Hi all, I’m just about to embark on a project to integrate my first Raspberry Pi Actuator/Sensor with SmartThings. Ideally I’d like my single Raspberry Pi device to be represented as several devices in SmartThings.

I’ve had a look at the official SmartThings documentation for LAN-connected devices (which seems much improved since I last looked at it):

Please can someone confirm (or correct) my understanding that using the official SmartThings method (as documented in the link above) limits you to a ‘one MAC address <-> one ST device instance’ relationship? Is this still the case?

If you want to have a LAN connected device represented as several device instances in SmartThings, then you can use @redloro’s smartthings-nodeproxy solution (or similar). The key thing in this implementation is the subscription to all location events (!):

subscribe(location, null, lanResponseHandler, [filterEvents:false])

This is great, but can anyone comment whether this is more of a hack or is it officially supported by SmartThings? I’m just worried that if it’s not an officially supported method then it runs a higher risk of being broken by an update in the future. Also, could this not result in performance issues?

[Update: obviously, the other solution is to use the Cloud-connected method and engineer a REST Endpoint that forwards the messages to the right device instances. But I’d rather keep all traffic to the LAN if possible]

[Update: @Aaron, can you offer any official guidance?]


I can’t speak to the nodeproxy solution that @redloro made as I haven’t had a chance to look at it yet (on my short list), but I’ve been trying to solve this problem for a while.

Getting the RPI to talk to the ST hub is easy, and like you’ve said, it does seem to be a relationship between the MAC address and a represented device on the platform. My understanding is that this is the official ST-supported implementation for local LAN devices.

Now, it is worth noting that ST supports IP connected devices like Ecobee that (to my knowledge) don’t rely on a MAC identifier. I think this is because they’re tied in to a cloud-based platform. I don’t know what the capability is for devices like these to push data to the hub.

I have considered doing some TAP/raw socket programming to send packets from the RPI with different SMACs for each virtual device, but the problem would arise when the hub polls these devices for updates. You’d have to do some ARP finessing to have the RPI register as each one of these MAC addresses. This would definitely be a “hack”, but the concept is sound (I think) and it should work.

(Victor) #33

I have many Devices in a single Raspberry Pi Zero W. I saw @redloro implementation and BTW it’s really good. Besically if you look at this code you will see a notify method that send request to ST HUB v2. This method is using a custom HTTP header to identify the plugin. So after saw his implementation I like the idea and I’m using the same logic on my personal projects. In the SmartApp you will have a lanResponseHandler where you can check using a custom HTTP header from which Device the request is coming. So basically I don’t care about the IP/Port and MAC instead I’m just parsing the HTTP header and checking if it has my custom header if it does I’ll accept the request if it doesn’t I just ignore it.
Here is an example that I’m working on to automate my fireplace:

Hope it helps. Regards.