Receiving notifications from LAN devices

Yes, in v1.0.6. My WeMo driver has been working properly since then.

any suggestions on how to troubleshoot my issue then?

If you're willing to help here is my thread on what's going on

I am getting something in the logs, but it's not what I am sending. (I am trying to port this app from smartThings and it's the last piece I need)

Here is what I see:

parsedEvent = [mac:001788227989, networkAddress:0A000102, deviceAddress:50, ssdpPath:/description.xml, ssdpUSN:uuid:2f402f80-da50-11e1-9b23-001788227989, ssdpTerm:urn:schemas-upnp-org:device:basic:1, ssdpNTS:null]

Is there anyway for me to tell what is sending this?

Here is the code that sends the message:

It never reaches HE. I never see it in the log

                if (device.id && device.name && device.type) {
                        try {
                            var data = {
                                module: module,
                                id: device.id,
                                name: device.name,
                                type: device.type,
                                event: event.name,
                                value: event.data.value
                            };
                            for (attr in device) {
                                if (attr.substr(0, 5) == 'data-') {
                                    data[attr] = device[attr];
                                }
                            }
                            log({
                                info: 'Sending event to SmartThings: ' + (event.data.description || '')
                            });
                            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
                                        });
                                    }
                                });
                            log({
                                info: 'Event should have been sent by now'
                            });

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

Turns out this is my Hue bridge.

I've never tried sending messages directly to the HE, so I'm not 100% sure what's required. I believe the MAC address of the sending device has to match up with the device network ID of the device in HE; is that the case in your setup?

Yes, if a driver has a dni which is the source device Mac or ip in hex, sans separators, and said device directs it's output to the hub ip address on port 39501 then any data the device sends will be forwarded to the drivers parse method.

I have a nodejs module that connects to AT&T digital life and sends a discovery data to my HE App to create the Devices if they are not already in HE. I monitor the log and that initial call never shows up. If I use curl to pass a similar command I receive a 200 return, but still nothing in the logs of HE.

This is an app I am porting over from SmartThings, and it works fine over there. I have the HE app working, it's just the communication between nodejs and HE that isn't working.

im not sure how this was supposed to work previously, but why not modify the node js app to have it send it's output directly to an he driver, this has less system overhead than subscribing to location events.

Wouldn't I still need an app to create the devices in HE as they are discovered in ATTDL?

yes, but the driver that receives and parses the messages can create child devices directly (component devices), or more logically, send these requests to the parent app to create child 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?