Receiving notifications from LAN devices

This doesn't sound like a device notification issue. I mean, it sounds like there should just be an app running on HE with an open endpoint that the node app can communicate with.

yup, can be done that way as well.

I was thinking about rewriting the app to do that, but I'd like to understand why this works in smartThings but not in HE. I have the app part of it working, I just never see anything from nodejs. nodejs does send the notification.

I would like to know as well! :slight_smile: can you point me to the nodejs code you are running? and if you know the relevant lines of code you are expecting to send a message to HE?

This is the nodejs code:

Here is some relevant troubleshooting I've done:

If I reload the app in HE, I can get it to go past the section of the nodejs code listed in the above thread, but then it stops at the section listed below:

node.request.put({
                                        url: 'http://' + config.server.ip + ':' + config.server.port + '/event',
                                        headers: {
                                            'Content-Type': 'application/json'
                                        },
                                        json: true,
                                        body: {
                                            event: 'event',
                                            data: data
                                        }
                                    },
                                    function (err, response, body) {
                                        if (err) {
                                            log({
                                                error: 'Failed sending event: ' + err
                                            });
                                        }
                                    });

                            } catch (e) {
                                log({
                                    error: 'Error parsing event data: ' + e
                                });
                            }
                        }
                    }
                }
            } catch (e) {
                error('Failed to send event to SmartThings: ' + e);
            }
        },

This is the repo to the HE app:

why do you mean by "stops" do you get an exception? or does the code hang somewhere in there?

It shows the devices being discovered in ATTDL, at which point it is sending the information to HE. However, HE never logs an event.

It doesn't error, it just waits for a response I think.

Alright, so I did a little digging into that code. It will not work because the Lan messages are not sent to apps as location events. It appears that ST implemented a 2nd way for Lan messages to processed by the system, although I've never seen that used until now. The App is subscribing to all location events and it is expecting any incoming Lan messages to be sent as location events, HE does not do that so you will never see those messages.

You have two options.
Option 1: the App can create a child device with the DNI set to the mac address or ip address of the nodejs server, and that child device will receive the messages that the nodejs server is sending to port 39501.
Option 2: the Hubitat App creates endpoint mappings that the nodejs can send the messages to, this would require that you enable OAuth on that App and then generate an access token for the nodejs app to use to talk to the Hubitat App.

I would recommend option 1, it will be easier than setting up endpoints and passing the token to the nodejs app.

Here is some test code I created just now to see if the request.put worked:

nodejs app: (note that my hub ip was hard coded)

var request = require('request');

var data = { 
    module: 'myModule',
    id: 'myDeviceId'
};

request.put({
    url: 'http://' + '192.168.1.161' + ':' + '39501' + '/event',
    headers: {
        'Content-Type': 'application/json'
    },
    json: true,
    body: {
        event: 'event',
        data: data
    }
},
function (err, response, body) {
    if (err) {
        log({ error: 'Failed sending event: ' + err });
    }
});

device driver:

/*
Copyright 2018 Hubitat, Inc.  All Rights Reserved
*/
metadata {
    definition(name: "testIncomingLanMessage", namespace: "hubitat", author: "cschwer") {
        capability "Sensor"
    }
}

def installed() {}

def uninstalled() {}

def parse(String description) {
    log.debug description
}

The DNI of my device was set to the ip address of my laptop that I was running nodejs on:

and the log debug message from the logging page:

debug mac:, ip:c0a801b3, port:eb42, headers:UFVUIC9ldmVudCBIVFRQLzEuMQ0KQ29ubmVjdGlvbjogY2xvc2UNCkhvc3Q6IDE5Mi4xNjguMS4xNzk6Mzk1MDENCkFjY2VwdDogYXBwbGljYXRpb24vanNvbg0KQ29udGVudC1MZW5ndGg6IDY0DQpDb250ZW50LVR5cGU6IGFwcGxpY2F0aW9uL2pzb24NCg==, body:eyJldmVudCI6ImV2ZW50IiwiZGF0YSI6eyJtb2R1bGUiOiJteU1vZHVsZSIsImlkIjoibXlEZXZpY2VJZCJ9fQ==

1 Like

Dude! You are awesome! I have been so stumped by this. I will work on the change that you've suggested!

1 Like

@chuck.schwer - I feel pretty dumb here. So I assumed I could just copy your code and modify the IP to test this out. When I execute node /var/node/homecloudhub.local/hubitat.js I still do not see anything in hubitat.

What am I doing wrong?

Are you setting the DNI of the IP address in hex of your node server?

I was using MAC address, but I can try IP.

Did you have the MAC address in all uppercase and with no colons in it?

Not in upper. I'll try that also.

Both Suggestions worked!

Thanks everyone!

1 Like

awesome to see you are making progress on this.

The nice thing about using the MAC address is that if your device uses DHCP, and gets a new IP address, it will still work.

Of course, if your hub needs to “talk” to your device, it needs the IP address+port to do so.

So, both options have pros and cons.

1 Like

Is there some other code I can follow to help me through this? Now that I can get this:

mac:B827EB7B3AF8, ip:0a000131, port:9d90, headers:UFVUIC9ldmVudCBIVFRQLzEuMQ0KQ29ubmVjdGlvbjogY2xvc2UNCkhvc3Q6IDEwLjAuMS40NjozOTUwMQ0KQWNjZXB0OiBhcHBsaWNhdGlvbi9qc29uDQpDb250ZW50LUxlbmd0aDogMjgwDQpjb250ZW50VHlwZTogYXBwbGljYXRpb24vanNvbg0KQ29udGVudC1UeXBlOiBhcHBsaWNhdGlvbi9qc29uDQo=, body:eyJldmVudCI6ImV2ZW50IiwiZGF0YSI6eyJtb2R1bGUiOiJkaWdpdGFsbGlmZSIsImlkIjoiU1UwMjAwOTVEQyIsIm5hbWUiOiJTbW9rZSBEZXRlY3RvciIsInR5cGUiOiJzbW9rZS1zZW5zb3IiLCJldmVudCI6ImRpc2NvdmVyeSIsImRhdGEtYmF0dGVyeSI6IjkwIiwiZGF0YS1yc3NpIjoiMCIsImRhdGEtYWxhcm0tdmVyaWZpZWQiOiJ2ZXJpZmllZCIsImRhdGEtbG9jYXRpb24iOiIwMDA0MDEyMDMwIiwiZGF0YS10ZXN0LW1vZGUtZXhwaXJ5IjoibnVsbCIsImRhdGEtc3RhdHVzIjoiMCJ9fQ==

How do I read it?

I expected to see something more like this:

Received discovery event for module digitallife, device Rosiak Control Panel of type digital-life-controller, value null, data: [data-rules-set:application/json, data-dlc-control:0, data-dlc-status-bitmask:0, data-operation-mode:0, type:digital-life-controller, data-appliance-ip2:null, id:0, data-proxy-port:49156, data-timezone:CST6CDT, event:discovery, data-subscription-features:DLBASCPKG, name:Rosiak Control Panel, data-connectivity:3, data-livevideoonalarmtoken:Loukse7HBbXt44rguC1v74PEHavsB8Vr, data-header-ip:98.144.102.103, data-test-request:null, data-discovery-status:null, data-discovery:0, module:digitallife, data-dl-flags:23, data-policycaps:G=16,K=16,SP=1,T=1,IIWC=1,HP=2,N=1,RD=1,ER=4,AM=2,TMH=1,DTM=1,AQS=1,VE=1,SC=1,EVT=1,PE=1,REST=1,EndExitDelay=1, data-battery:100, data-change-rules-set-row:application/json, data-inbound-port:32000, data-livevideoonalarmpolicy:never, data-schedule:application/json, data-locale:en_US, data-location:0003013034, data-schedule-change:null, data-token:XW7pmWZAIWLIL4G5fqQKl7fXruIsVAJ4, data-power-source:AC, data-test-mode-expiry:,auto-dla, data-tampered-device-list:null, data-policyrules:10, data-proxy-ip:a-nps1-da.dlife.att.com, data-appliance-ip:10.0.1.44, data-status:0]

Decode it

the headers:UFV... Base64 decodes to:

PUT /event HTTP/1.1
Connection: close
Host: 10.0.1.46:39501
Accept: application/json
Content-Length: 280
contentType: application/json
Content-Type: application/json

the part that begins "body:ey..." Base64 decodes to:

{"event":"event","data":{"module":"digitallife","id":"SU020095DC","name":"Smoke Detector","type":"smoke-sensor","event":"discovery","data-battery":"90","data-rssi":"0","data-alarm-verified":"verified","data-location":"0004012030","data-test-mode-expiry":"null","data-status":"0"}}

jsonlint.com validates it's json:

{
	"event": "event",
	"data": {
		"module": "digitallife",
		"id": "SU020095DC",
		"name": "Smoke Detector",
		"type": "smoke-sensor",
		"event": "discovery",
		"data-battery": "90",
		"data-rssi": "0",
		"data-alarm-verified": "verified",
		"data-location": "0004012030",
		"data-test-mode-expiry": "null",
		"data-status": "0"
	}
}

There is a helper method:

Map parseLanMessage(String)

pass it the description string and it will parse out the values and decode them into a Map.

1 Like