[solved] Does anyone have sendMessageToNode() working?

Started by HeneryH, December 23, 2018, 10:09:09 PM

HeneryH

I've been struggling with a serial port problem in my gateway.js and cannot for the life of me figure it out.  Starting a new thread because my other thread seems to be on everyone's ignore list.

Basic question.....

Does anyone have any scenarios where they have an event defined that sends any messages to another node?

Anything?  Bueler?  Bueler?

I change the code in my gateway.js so that sendMessageToNode() just simply sends the serial port a dummy string "dummy".  The first time it always gets echoed by the MightyHat sketch just fine.

The second call to sendMessageToNode() always has a corrupt message gets echoed back to the gateway truncated to two or three chars.

The first call to sendMessageToNode() with 5 hardcoded lines of jamming "dummy" down the serial port.
[12-23-18_21:56:19.919] [INFO]   LOADING USER METRICS...
[12-23-18_21:56:19.988] [INFO]   LOADING USER METRICS MODULE [ExitButton.js]
[12-23-18_21:56:24.766] [INFO]   AUTHORIZING CONNECTION FROM ::1:34686
[12-23-18_21:56:24.850] [INFO]   NEW CONNECTION FROM 192.168.1.237
[12-23-18_21:56:36.449] [LOG]    >: [96] BUTTON:ON BAT:4.16v   [RSSI:-66][ACK-sent]
[12-23-18_21:56:36.545] [LOG]    post: /home/pi/gateway/data/db/0096_EXIT.bin[1545620196,1]
[12-23-18_21:56:36.579] [LOG]    post: /home/pi/gateway/data/db/0096_V.bin[1545620196,4.16]
[12-23-18_21:56:36.591] [LOG]    post: /home/pi/gateway/data/db/0096_RSSI.bin[1545620196,-66]
[12-23-18_21:56:36.647] [LOG]    Trying to debug this stinking thing, here is the json of the node: {"nodeId":95,"action":"EXT:0"}
[12-23-18_21:56:36.654] [LOG]    1) Literally about to jam this string down the serial port, value of stinking is 95:EXT:0
[12-23-18_21:56:36.675] [LOG]    1) value of node.node is 95 and the value of node.action in the port write is EXT:0
[12-23-18_21:56:36.682] [LOG]    1) NODEACTION: {"nodeId":95,"action":"EXT:0"}
[12-23-18_21:56:36.745] [LOG]    >: GTWCMD:dummy
[12-23-18_21:56:36.755] [LOG]    >: Len:5
[12-23-18_21:56:36.763] [LOG]    >: GTWCMD:dummy
[12-23-18_21:56:36.771] [LOG]    >: Len:5
[12-23-18_21:56:36.779] [LOG]    >: GTWCMD:dummy
[12-23-18_21:56:36.787] [LOG]    >: Len:5
[12-23-18_21:56:36.795] [LOG]    >: GTWCMD:dummy
[12-23-18_21:56:36.802] [LOG]    >: Len:5
[12-23-18_21:56:36.810] [LOG]    >: GTWCMD:dummy
[12-23-18_21:56:36.818] [LOG]    >: Len:5


The second attempt always does this:
[12-23-18_21:56:56.018] [LOG]    >: [96] BUTTON:ON BAT:4.16v   [RSSI:-67][ACK-sent]
[12-23-18_21:56:56.030] [LOG]    post: /home/pi/gateway/data/db/0096_EXIT.bin[1545620216,1]
[12-23-18_21:56:56.040] [LOG]    post: /home/pi/gateway/data/db/0096_V.bin[1545620216,4.16]
[12-23-18_21:56:56.048] [LOG]    post: /home/pi/gateway/data/db/0096_RSSI.bin[1545620216,-67]
[12-23-18_21:56:56.064] [LOG]    Trying to debug this stinking thing, here is the json of the node: {"nodeId":95,"action":"EXT:0"}
[12-23-18_21:56:56.069] [LOG]    1) Literally about to jam this string down the serial port, value of stinking is 95:EXT:0
[12-23-18_21:56:56.077] [LOG]    1) value of node.node is 95 and the value of node.action in the port write is EXT:0
[12-23-18_21:56:56.083] [LOG]    1) NODEACTION: {"nodeId":95,"action":"EXT:0"}
[12-23-18_21:56:56.106] [LOG]       [96] DB-Updates:1
[12-23-18_21:56:56.117] [LOG]    >: GTWCMD:du
[12-23-18_21:56:56.128] [LOG]    >: Len:2

HeneryH

Warning - 115200 baud for MightyHat <--> Pi Model A+

Running at that speed caused me data corruption.

Felix

Saw your other thread and request to remove (done).
Was the solution a lower baud? Did that solve the other thread problems?
BTW - default is 19200.

For a future version I may implement a serial buffer/queue mechanism, to stagger serial communications and randomize their throughput to the MightyHat/Moteino. This is useful when there are multiple messages (say sunset causes 5 SwitchMotes to turn off). While listen-before-speak is implemented in the RFM69 library, it is not completely bullet proof especially when ACKs are involved.

HeneryH

Don't know why but most of my motes were set to 115200 so that is what I went with for my Pi/MH. 

Big mistake as I wasted many days chasing ghosts related to serial comms.

Finally lowered the rate and all of the problems went away.

Felix

Good point. I should do that in all the sample sketches, since lots of users might just assume its the same.
It used to be 115200 on the gateway, but I lowered it at one point in time.