ralphwetzel / node-red-mcu-plugin

Plugin to support the Node-RED implementation for microcontrollers
MIT License
35 stars 8 forks source link

clear node status on restart? #37

Open phoddie opened 1 year ago

phoddie commented 1 year ago

This is mostly a cosmetic issue but it has caused me some confusion, so I thought I'd report it so perhaps a solution could be found before others are also confused.

When Node-RED restarts a flow, it clears the status of all nodes. By "status" here I mean the small status message displayed below a node. In the flow below, the Debug node has been configured to display the most recent payload as its status ("27" here).

image
counter flow ```json [ { "id": "8dbc54f41c619c50", "type": "tab", "label": "demo", "disabled": false, "info": "", "env": [], "_mcu": { "mcu": true } }, { "id": "f58f644683fe9686", "type": "inject", "z": "8dbc54f41c619c50", "name": "", "props": [], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "_mcu": { "mcu": true }, "x": 250, "y": 140, "wires": [ [ "cab82b2da436408d" ] ] }, { "id": "c65c01a8e70b3e57", "type": "debug", "z": "8dbc54f41c619c50", "name": "", "active": true, "tosidebar": true, "console": false, "tostatus": true, "complete": "payload", "targetType": "msg", "statusVal": "payload", "statusType": "msg", "_mcu": { "mcu": true }, "x": 530, "y": 140, "wires": [] }, { "id": "cab82b2da436408d", "type": "function", "z": "8dbc54f41c619c50", "name": "counter", "func": "msg.payload = ++globalThis.counter;\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "globalThis.counter = 0;", "finalize": "", "libs": [], "_mcu": { "mcu": true }, "x": 380, "y": 140, "wires": [ [ "c65c01a8e70b3e57" ] ] } ] ```

To see the problem, use the MCU plug-in to deploy the counter flow to an MCU (I used an ESP8266 but ESP32 should be the same). When the flow is running, notice that the initial status on the Debug node is blank. Press the button on the Inject node a few times to run up the status counter on the Debug node. Then press the Reset button on the MCU. That will restart the flow. Notice that the status counter is unchanged. Then press the Inject button once and the status displays 1.

If you do the equivalent to this in Node-RED itself, choosing "Restart Flows" in place of pressing the Reset button, the status on the Debug node is cleared. When using the MCU plug-in, I think it should do the same.

I'm not entirely sure how to do that. There's a clear signal when the xsbug connection for the old VM disconnects and the new VM connects, so perhaps that can be used in some way.

phoddie commented 8 months ago

Thanks for working on this!