Author Topic: Basic javascript code question...  (Read 237 times)

HeneryH

  • Full Member
  • ***
  • Posts: 229
Basic javascript code question...
« on: November 19, 2018, 03:21:16 PM »
I'm looking at some node.js code that is reading status from the gateway.js server.

I'm coming from a c++ world and the magical way java and javascript deals with certain things confuses me.  I am used to very strict definition of everything.

In the code below, both "entry" and "status" are structures with underlying elements.  Where can I find them defined?

The code was originally written for a GarageMot and I am trying to use it for a SwitchMot and now when I get an inbound status message from the SwitchMot node, the code run-time craps out on the line noted.

Code: [Select]
socket.on('UPDATENODE', function (entry) {
    var status = {};

    status.id = entry._id;
    status.label = entry.label;
    status.status = entry.metrics.Status.value;  <----  run time error here
    status.timestamp = entry.updated;
    lastStatus = status.status;
   .
   .
   .

Any pointers would be appreciated, thanks.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6279
  • Country: us
    • LowPowerLab
Re: Basic javascript code question...
« Reply #1 on: November 19, 2018, 03:45:32 PM »
I don't know where this is coming (copy/pasted?) from, there is a similar definition on the client side, in index.html, but nothing like that in gateway.js.
Can you clarify?

HeneryH

  • Full Member
  • ***
  • Posts: 229
Re: Basic javascript code question...
« Reply #2 on: November 19, 2018, 03:56:09 PM »
It is coming from the sample code from Brad who wrote an SMS to GarageMot server.

The sms_gateway I copied from him is taking SMS messages fine and telling the gateway to turn switches off or on, but on status updates from the server it is crashing on that code referenced.

https://lowpowerlab.com/forum/pi-gateway/sms-interface-to-garagemote/msg9600/#msg9600

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6279
  • Country: us
    • LowPowerLab
Re: Basic javascript code question...
« Reply #3 on: November 19, 2018, 04:00:28 PM »
Ok, that's a question for spark/Brad :)

I'd seriously consider doing everything within the gateway app, probably much safer too.