Node-RED MCU - unhandled exceptions causing endless loop?

Not sure if this is an issue inside moddable or node-red-mcu, but anytime the generated node-red flows running on my ESP-32 hit an error, the whole unit restarts... and fails again.

In my particular flow, I just added a node-red-node-serial-in node, which causes this stack trace in xsbug-log:

#xsbug-log connected to "main"
Wi-Fi connected to "S&J-Poolhouse"
IP address 192.168.1.107
# Break: importNow: module "events" not found!
  #0: importNow
  #1: require /home/srickus/develop/node-red-mcu-plugin/mcu_modules/require/require.js:5
  #2: (anonymous-522) /home/srickus/.node-red/node_modules/node-red-node-serialport/25-serial.js:5
  #3: forEach
  #4: RED.build /home/srickus/develop/node-red-mcu-plugin/node-red-mcu/nodered.js:156
  #5: (anonymous-243) /home/srickus/.node-red/mcu-plugin-cache/sqd9j8rnmna/main.js:20
  #6: (host)
XS abort: unhandled exception

I know the support for the node-red-node-serial collection is still wet behind the ears, so I'm not totally surprised it did not work out of the gate. Any idea when we can read/write serial data through the gpio Tx/Rx pins? The bigger question is whether this is the right node to use, I suppose. :*(

But this topic is more about error handling when something like this goes wrong on the MCU code -- right now my mcu is reconnecting to the wifi network like every 5 seconds! As soon as the connection is established, there is this unhandled expection -- perhaps the generated code should catch all of these and just stop? Or at least impose a logarithmically increasing delay before trying again.

Seems like the closer I get to getting my MCU device deployed, the more obscure the errors -- but this is all very exciting, especially for those of us who only get to write code in the "bits-n-bytes" world, not in the world of "events-n-atoms".

Well - it's not wet behind the ears, it's just still work in progress. :wink: No way the standard node will work out of the box...

You could make yourself familiar with the Serial interface in Moddable and use this via a function node. Not that elegant - but do-able.

That's not the nature of MCUs. When they hit a (severe) error, they reset and retry. For development purposes, xsbug may support you - as it is supposed to halt the MCU at the exception!

Yeah, I saw that @phoddie suggested the serial in and serial out nodes could be ported to use the moddable Serial library. I could maybe help with that if I knew where/how to even start. If that hill is too steep, I'd be happy to test someone else's commits!

So does this mean that the function node code is passed to the mcu as-is? I see in the docs that the function node is supported (except for async onStart functions). So do i just need to npm install the moddable Serial library, import it into my function, and develop code to read/write the tx/rx pins? I assume I'll need to plug an rs-485 ttl -> uart board into those mcu pins, to handle the serialization of the data?

Ok, good thing to know... I'm currently using xsbug-log to see the errors on the console. Let me try running the full debugger on my RPi desktop.

I'm already down that road! :wink: I've spent the last hour to put together a simple (= non optimized) implementation of a serial node. I'd need another day to find a way to test this a bit.

It is.

No need to install anything! It's much easier: The host is preconfigured with interface modules for its hardware capabilities (example), put in a global object called devices. You just needed to initialize your port and are ready to go (example).

1 Like

Quick update on that: I've stumbled over an issue with the serial driver in Moddable SDK. We need to investigate what's happening there first, before it can be used for a node.
Sorry for the delay...

@shrickus
As advertised, I've created an implementation of node-red-node-serialport for node-red-mcu.
As it's a shim, it's going to be used as soon as you build a flow with serial in or serial out node for a MCU.
Serial request node is not supported.
For further details, you should refer to the short documentation.
As this is part of node-red-mcu-plugin, you need to install / update this currently from the GitHub repo. After some time for testing (Your feedback is welcome!) I'll create a new release...

1 Like

Hi Ralph,
I finally had some time to update and test the serial in/out nodes -- thanks for getting that testable in such short order.

I have not yet been successful reading any data from the TTL to RS-485 module connected to my ESP-32 module, but I suspect it's due to my lack of understanding, or just user error. Plus it is not easy to debug since it is running disconnected from the RPi-4 USB (only connected to MQTT broker via Wifi). Do you have any tricks for remote debugging in this case?

I did want to verify that I'm choosing the right configuration for the serial in node... as you suggested in the docs, I created a new serial-port node using Port/Rx/Tx values of /P2/R33/T19:

It seems the ESP-32 pin numbers don't necessarily match the GPIO numbers -- so which ones should I be using here? And does it matter that the generated "name" of the Serial port
contains the trailing characters :19200-8N2?

image

The code appears to ignore that stuff (and I'm not interested in Transmitting right now). I'm mostly wondering if Rx on pin #33 is referring to GPIO-33 or the pin in slot #33.

Pin refers to the GPIO pin-number according to the hardware definition of your board.
I've chosen 2 pins that were available on my dev board - completely random. The only criteria: They were accessible easy and sitting next to each other.

When wiring those pins, keep in mind, that what the MCU understands as TX is RX for your Serial Port monitor.

Until you've successfully crated a first running flow, I'd try to eliminate any complexity. This is my "development setup": An MCU & a SH-U07A TTL to USB adapter (as Serial Port monitor), both plugged into the same laptop.

The laptop runs Node-RED with the node-red-mcu-plugin and a serial port terminal application that allows me to monitor the data & loop it back to the MCU. If there's an issue, it has to be within this square feet on my table! :wink: That said, it's not clear for me where you're trying to capture the serial data with your setup. A simple sketch would help me a lot...

Here's an easy flow to test your setup. The only thing you need to change is the pin setup. And no - the trailing characters don't matter.

[
    {
        "id": "8c8d2482a20754c2",
        "type": "tab",
        "label": "Serial Port Test",
        "disabled": false,
        "info": "",
        "env": [],
        "_mcu": {
            "mcu": true
        }
    },
    {
        "id": "a2a935c2741add0a",
        "type": "serial in",
        "z": "8c8d2482a20754c2",
        "name": "",
        "serial": "631a61ee97b5a76a",
        "_mcu": {
            "mcu": true
        },
        "x": 470,
        "y": 240,
        "wires": [
            [
                "e236523df59a71e6"
            ]
        ]
    },
    {
        "id": "1f8d02cf73ff87a3",
        "type": "serial out",
        "z": "8c8d2482a20754c2",
        "name": "",
        "serial": "631a61ee97b5a76a",
        "_mcu": {
            "mcu": true
        },
        "x": 470,
        "y": 180,
        "wires": []
    },
    {
        "id": "e236523df59a71e6",
        "type": "debug",
        "z": "8c8d2482a20754c2",
        "name": "debug in",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "true",
        "targetType": "full",
        "statusVal": "payload",
        "statusType": "msg",
        "_mcu": {
            "mcu": true
        },
        "x": 640,
        "y": 240,
        "wires": []
    },
    {
        "id": "a84f667a636fbc57",
        "type": "debug",
        "z": "8c8d2482a20754c2",
        "name": "debug out",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "_mcu": {
            "mcu": true
        },
        "x": 490,
        "y": 120,
        "wires": []
    },
    {
        "id": "4c39157de56783ee",
        "type": "inject",
        "z": "8c8d2482a20754c2",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "_mcu": {
            "mcu": true
        },
        "x": 260,
        "y": 120,
        "wires": [
            [
                "a84f667a636fbc57",
                "1f8d02cf73ff87a3"
            ]
        ]
    },
    {
        "id": "631a61ee97b5a76a",
        "type": "serial-port",
        "serialport": "/P2/R33/T19",
        "serialbaud": "115200",
        "databits": "8",
        "parity": "none",
        "stopbits": "1",
        "waitfor": "",
        "dtr": "none",
        "rts": "none",
        "cts": "none",
        "dsr": "none",
        "newline": "1000",
        "bin": "false",
        "out": "interbyte",
        "addchar": "",
        "responsetimeout": "10000",
        "_mcu": {
            "mcu": false
        }
    }
]

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