If second message is not received then resend message

  1. Node-RED sends a message [M1] (via MQTT) to the Join/Server
  2. Join/Server stores [M1] in a queue time passes
  3. LoRa wakes up and sends a message to Join/Server [M2 data, wb=0] (wb - watchdog bit)
  4. Join/application server sends the sensor data and watchdog bit “0” via MQTTT to my Node-Red application [M2]
  5. Join/Server sends [M1] (via radio) to LoRa ...delay 5 seconds and LoRa sets wb=1
  6. LoRa goes to sleep for a period of time (how long?) (I need to do it on message base, as time can be a set period or a sensor interrupt can send a message)
  7. LoRa wakes up and sends message [M3 data, wb=1] to Join/Server
  8. Join/Server sends message [M3 data, wb=1] (via MQTT) to Node-RED
  9. Node-red need to check if it’s M2 (wb=0) or M3 (wb=1) as if LoRo never received M1 the wb can’t be 1 in M3
  10. If M1 were not received by LoRa, node-red needs to resend the M1

questions:
• What does NR do with the message [M2] it receives? Sensor data display on graph and stored in db.
• sWhat does NR do with the message [M3] it receives? Sensor data display on graph and stored in db. And have the wb to confirm that M1 were received.
• At step 10 who (NR, Join/Server) is waiting for a message with the watchdog bit=1? Here the decision needs to be made if this were M2 or M3, as M3 will have wb=1
• when did the waiting start? Message based and not time
• How long is the wait? Message based and not time
• what message is to be sent? The message is not as important as to where it received

So the idea is that NR is requests data that will come from the LoRa. But the LoRa could be asleep so the Join/Server has to wait till the LoRa announces that it is awake which it does by sending data to the Join/Server.

At that point why doesn't the Join/Server just send the data to Node-RED?

What happens if NR hasn't requested any data but the LoRa wakes up and sends data to the Join/Server? Should that data be sent to NR and NR should process it?

Everytime I look at this and think I understand what you are trying to do, another question pops up and I'm once again confused.

[I'll be off line for about 2 hours at this point - we are in a snow storm and I need to do some shoveling]

Paul, yes it is confusing but I think its like this...
overall
Node-RED end wants to send something to Lora device and get an ack back. (and if not then resend).
so
Node-RED sends initial request to LORA gateway. it sits there.
Lora device wakes up - sends whatever data it is designed to send - gateway says thanks for that- and by the way here is something for you... and sends the Node-RED request. Lora device goes to sleep (as it has already done its send cycle first).

  • at this point the gateway would send on the data from the device - and could send a message back to Node-RED saying "OK I've let them know" - but it wouldn't have got the actual ack from the device as the receive (from gateway POV) happens before the transmit.

Next time the Lora device wakes up - it sends its data packet to the gateway - this time including the ack from the original Node-RED request - (and then maybe receives next thing to do from gateway) - so now the gateway can send the real ack back to Node-RED - hence why it is the second packet back that is important.

Yes that is the just of it.

It is about 25C here and about to start drizzling, enjoy you shoveling :slight_smile:

(Back from shoveling and doing a couple other things)

Question 1:
So what should happen if the LoRa is woken because of a sensor interupt but NR hasn't sent out a message?

Question 2:
As I understand it, the LoRa is in charge of turning the watchdog bit on and off...correct?
If 'yes' how does the LoRa decide to turn it off?

If 'no' how is it shut off?

Queston 3:
What happens if the LoRa has gone back to sleep and wakes because of a sensor interupt but the watchdog bit is 1?

Not sure any of these need to worry the Node-RED side of things. It just needs to somehow align requests going out with acqs coming back 2 messages later

@dceejay you're probably right. I’m just trying to get a handle on the whole process.

Send a message, if the previous message received were M1, then it first sends M2 then sends it's M3 message, other wise it's normal message. (Sheduled/interupt message)

Lora turns on the watchdog bit on because it received the M1. The next message Lora turns the watchdog off.

Node-red need to resend M1 if M3 is not received - That is the part I need to solve.

PS - Time might be regular here at 1 min but it can be as long as 1 hour, so done rely on the time factor)

Does my earlier suggested approach not work? Why not?

Need to get my head around this.

Inject press sequence

  1. M1 - then you get a "Downlink - msg"
  2. M2
  3. M3 - no out put at "Resend Downlink"

Inject press sequence

  1. M1 - then you get a "Downlink - msg"
  2. M2
  3. M2 - out put at "Resend Downlink" triggering "Downlink - msg"

Inject press sequence

  1. M2 - out put at "Resend Downlink"
  2. M2 - out put at "Resend Downlink"
  3. M2 - out put at "Resend Downlink" ......
[
    {
        "id": "367a225a9f310aeb",
        "type": "debug",
        "z": "066b6e4829326d09",
        "name": "Uplink - msg",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "true",
        "targetType": "full",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 430,
        "y": 480,
        "wires": []
    },
    {
        "id": "ebad25c384b3e6a0",
        "type": "comment",
        "z": "066b6e4829326d09",
        "name": "Uplink - msg from node (device)",
        "info": "",
        "x": 150,
        "y": 320,
        "wires": []
    },
    {
        "id": "c8cb5928620e50dd",
        "type": "comment",
        "z": "066b6e4829326d09",
        "name": "Downlink -  - msg to node (device)",
        "info": "",
        "x": 150,
        "y": 220,
        "wires": []
    },
    {
        "id": "8e3a2f3e66d06d4a",
        "type": "function",
        "z": "066b6e4829326d09",
        "name": "Resend Downlink",
        "func": "",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 450,
        "y": 400,
        "wires": [
            [
                "8d081365deeb06fa",
                "367a225a9f310aeb"
            ]
        ]
    },
    {
        "id": "8d081365deeb06fa",
        "type": "function",
        "z": "066b6e4829326d09",
        "name": "Downlink - msg",
        "func": "msg.payload = {\n    \"downlinks\": [\n        {\n            \"f_port\": 100,\n            \"frm_payload\": Buffer.from(msg.payload, 'hex').toString('base64'),\n            \"priority\": \"NORMAL\"\n        }\n    ]\n}\n\nmsg.topic = \"v3/msg.app/devices/msg.dev/down/push\"\n\nflow.set('waitcount', 1)\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 440,
        "y": 260,
        "wires": [
            [
                "22198531415b2963"
            ]
        ]
    },
    {
        "id": "79902647c6ad0e8a",
        "type": "inject",
        "z": "066b6e4829326d09",
        "name": "M1",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "dev",
                "v": "eui-ababcbcbdcdccdcd",
                "vt": "str"
            },
            {
                "p": "app",
                "v": "sotracking@ttn",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "C0",
        "payloadType": "str",
        "x": 110,
        "y": 260,
        "wires": [
            [
                "8d081365deeb06fa"
            ]
        ]
    },
    {
        "id": "22198531415b2963",
        "type": "debug",
        "z": "066b6e4829326d09",
        "name": "Downlink - msg",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "true",
        "targetType": "full",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 640,
        "y": 260,
        "wires": []
    },
    {
        "id": "20c47365017aea85",
        "type": "inject",
        "z": "066b6e4829326d09",
        "name": "Sheduled/Interrupt or M2",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{\"door\":1,\"tempA\":21.81,\"watchdog\":0}",
        "payloadType": "json",
        "x": 170,
        "y": 360,
        "wires": [
            [
                "8e3a2f3e66d06d4a",
                "367a225a9f310aeb"
            ]
        ]
    },
    {
        "id": "a389e6f96e1b3c96",
        "type": "inject",
        "z": "066b6e4829326d09",
        "name": "M3",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{\"door\":1,\"tempA\":21.81,\"watchdog\":1}",
        "payloadType": "json",
        "x": 110,
        "y": 400,
        "wires": [
            [
                "8e3a2f3e66d06d4a",
                "367a225a9f310aeb"
            ]
        ]
    }
]

image

So looking at this strictly from Node-RED

  • Node-RED sends out a msg via MQTT

    • is it possible that NR will send out a second or more msg before the first is replied to?
  • Node-RED receives a msg via MQTT. The msg contains a 'watchdog bit' (a 0 or 1)

    • What should NR do it the 'watchdog bit' is 0?
    • What should NR do it the 'watchdog bit' is 1?

In the button push flow I removed it so you can manually simulate the sequence of events

No it will be a user input that initiate the msg.

The first returning msg nothing, on the second retuning msg if 'watchdog bit' is 0 send the msg again.

This indicates to node-red it received M1 and don't send any more messages

Ok, based on what you said, try this flow

[{"id":"3b2d75ffeaced257","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"367a225a9f310aeb","type":"debug","z":"3b2d75ffeaced257","name":"Uplink - msg","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":510,"y":280,"wires":[]},{"id":"ebad25c384b3e6a0","type":"comment","z":"3b2d75ffeaced257","name":"Uplink - msg from node (device)","info":"","x":230,"y":180,"wires":[]},{"id":"c8cb5928620e50dd","type":"comment","z":"3b2d75ffeaced257","name":"Downlink -  - msg to node (device)","info":"","x":230,"y":80,"wires":[]},{"id":"8d081365deeb06fa","type":"function","z":"3b2d75ffeaced257","name":"Downlink - msg","func":"msg.payload = {\n    \"downlinks\": [\n        {\n            \"f_port\": 100,\n            \"frm_payload\": Buffer.from(msg.payload, 'hex').toString('base64'),\n            \"priority\": \"NORMAL\"\n        }\n    ]\n}\n\nmsg.topic = \"v3/msg.app/devices/msg.dev/down/push\"\n\nflow.set('msgcount', 1)\nflow.set('M1', msg.payload)\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":780,"y":120,"wires":[["22198531415b2963"]]},{"id":"79902647c6ad0e8a","type":"inject","z":"3b2d75ffeaced257","name":"M1","props":[{"p":"payload"},{"p":"dev","v":"eui-ababcbcbdcdccdcd","vt":"str"},{"p":"app","v":"sotracking@ttn","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"C0","payloadType":"str","x":190,"y":120,"wires":[["8acd09bceb17ab68"]]},{"id":"22198531415b2963","type":"debug","z":"3b2d75ffeaced257","name":"Downlink - msg","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"payload","statusType":"auto","x":980,"y":120,"wires":[]},{"id":"20c47365017aea85","type":"inject","z":"3b2d75ffeaced257","name":"Sheduled/Interrupt or M2","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"door\":1,\"tempA\":21.81,\"watchdog\":0}","payloadType":"json","x":230,"y":240,"wires":[["367a225a9f310aeb","8065e1c8324d652e"]]},{"id":"a389e6f96e1b3c96","type":"inject","z":"3b2d75ffeaced257","name":"M3","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"door\":1,\"tempA\":21.81,\"watchdog\":1}","payloadType":"json","x":170,"y":280,"wires":[["367a225a9f310aeb","8065e1c8324d652e"]]},{"id":"8065e1c8324d652e","type":"switch","z":"3b2d75ffeaced257","name":"has NR sent a request?","property":"M1","propertyType":"flow","rules":[{"t":"null"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":230,"y":380,"wires":[["f3dc60191efcb361"],["fc5805a8373e5f57"]]},{"id":"f3dc60191efcb361","type":"change","z":"3b2d75ffeaced257","name":"ERROR Condition - no original msg","rules":[{"t":"set","p":"payload","pt":"msg","to":"ERROR Condition - Request from server but no msg sent to it","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":360,"wires":[["4217547f7965c94b"]]},{"id":"4217547f7965c94b","type":"debug","z":"3b2d75ffeaced257","name":"ERROR Condition","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":850,"y":360,"wires":[]},{"id":"fc5805a8373e5f57","type":"switch","z":"3b2d75ffeaced257","name":"Test watchdog","property":"payload.watchdog","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"0","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":3,"x":220,"y":560,"wires":[["b93c71c1ef340115"],["d49f6a622f5d6378"],[]]},{"id":"b93c71c1ef340115","type":"change","z":"3b2d75ffeaced257","name":"MSG received - all done","rules":[{"t":"set","p":"payload","pt":"msg","to":"MSG received - all done","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":490,"y":480,"wires":[["68ef1c690a534b10"]]},{"id":"68ef1c690a534b10","type":"debug","z":"3b2d75ffeaced257","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":730,"y":480,"wires":[]},{"id":"d49f6a622f5d6378","type":"switch","z":"3b2d75ffeaced257","name":"Check msg count","property":"msgcount","propertyType":"flow","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":470,"y":560,"wires":[["f324f8487bf0c66f"],["51fca492a7117226"]]},{"id":"e4a9b1e2d22c1f26","type":"debug","z":"3b2d75ffeaced257","name":"First returned MSG, do nothing","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1050,"y":540,"wires":[]},{"id":"f324f8487bf0c66f","type":"change","z":"3b2d75ffeaced257","name":"First returned MSG, do nothing","rules":[{"t":"set","p":"payload","pt":"msg","to":"First returned MSG, do nothing","tot":"str"},{"t":"set","p":"msgcount","pt":"flow","to":"$flowContext('msgcount')+1\t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":750,"y":540,"wires":[["e4a9b1e2d22c1f26"]]},{"id":"51fca492a7117226","type":"link out","z":"3b2d75ffeaced257","name":"go to RESEND MSG","mode":"link","links":["01b855f5f6470142"],"x":730,"y":620,"wires":[],"l":true},{"id":"01b855f5f6470142","type":"link in","z":"3b2d75ffeaced257","name":"RESEND MSG","links":["51fca492a7117226"],"x":460,"y":60,"wires":[["8acd09bceb17ab68"]],"l":true},{"id":"8acd09bceb17ab68","type":"change","z":"3b2d75ffeaced257","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"C0","tot":"str"},{"t":"set","p":"dev","pt":"msg","to":"eui-ababcbcbdcdccdcd","tot":"str"},{"t":"set","p":"app","pt":"msg","to":"sotracking@ttn","tot":"str"},{"t":"delete","p":"msgcount","pt":"flow"},{"t":"delete","p":"waitcount","pt":"msg"},{"t":"delete","p":"M1","pt":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":120,"wires":[["8d081365deeb06fa"]]}]
1 Like

90 % there :slight_smile:

Inject sequence

  1. M1
  2. M2
  3. M3
  4. M2 this M2 press generates a M1 again, not suppose to.

Inject sequence

  1. M1
  2. M2
  3. M2 this M2 press generates a M1, 100% correct

Ahh, missed resetting things. Change this node:
Screen Shot 2022-01-08 at 5.42.11 AM
to this:
Screen Shot 2022-01-08 at 5.44.53 AM

1 Like

Thank you @zenofmud I appreciate your help

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.