Node-red-mcu-plugin v1.0: Integrating Node-RED MCU Edition into the Node-RED editor

I thought I had better try it with the simulator first, without the contrib node, and I can't get that to go. I set it to Simulator, Node MCU and when I build I get

Starting build process...
Host system check: #64-Ubuntu SMP Thu Jan 5 11:43:13 UTC 2023
MCU Build system check: p1.1.2-post + #14cd68e @ m3.7.0-0-g74aa31c
HOME directory check: /home/colinl
Creating build environment for platform sim/nodemcu.
Working directory: /home/colinl/.node-red/mcu-plugin-cache/xbu2qex629n
> cd /home/colinl/.node-red/mcu-plugin-cache/xbu2qex629n
Creating build script file...
> /bin/bash ./build.sh
# nodered2mcu flows
# xsc main.xsb
# mcrez resources
# xsc flows.xsb
# xsl modules
Total resource size: 4760 bytes
# cc mc.resources.c
### 2262 instances, 2341 keys, 109 colors, 0 holes
### warning: wifi: default() timer: no const
### warning: wifi: default() state_next: no const
### warning: wifi: default() state: no const
### warning: wifi: default.get mode() mode: no const
### warning: wifi: default.scan() scanning: no const
### warning: nodered: Node.prototype.send() RED.#compatibility: not frozen
### warning: nodered: Node.prototype.send() RED.#compatibility[0]() DelayNode() maxKeptMsgsCount() _maxKeptMsgsCount: no const
### warning: nodered: Node.prototype.send() RED.build() msgQueue: no const
### warning: nodered: Node.prototype.send() RED.build() compatibilityClasses: no const
### warning: mustache: default: not frozen
### warning: mustache: default.tags: not frozen
### warning: mustache: default.clearCache() defaultWriter: not frozen
### warning: mustache: default.clearCache() defaultWriter.templateCache: not frozen
### warning: mustache: default.clearCache() defaultWriter.templateCache._cache: not frozen
### warning: WebSocket: default() URLParts() urlRegExp: no const
### warning: WebSocket: default() URLParts() authorityRegExp: no const
### warning: embedded:network/http/server/options/serversendevents: default: not frozen
### warning: embedded:network/http/server/options/webpage: default: not frozen
### warning: embedded:network/http/server/options/websocket: default: not frozen
### warning: httpserver: default.add() server: no const
### warning: securesocket: default() Session() cacheManager: not frozen
### warning: fetch: fetch() Client() clients: no const
# cc mc.xs.c
# ld mc.so

Then it brings up the mcsim window with a picture of a node MCU, but then a "Mcsim is not responding" popup appears with Force Quit and Wait. If I wait then it just reappears a few seconds later, and the simple flow is not running.

If I add the contrib node and build it shows a similar output and the mcsim window appears, but this time it doesn't say not responding. The flows still aren't running though. I don't get the missing module error though.

On the null message sending, it isn't unusual to send a null message, which in the normal node-red does nothing. That particular bit of code is pretty silly though. Quite what I was thinking when I wrote that I don't know.

I am not too worried about the simulator not running at the moment.

Sorry, I had no intension to blame you for anything - but report my observations. The runtime needs a bit of additional polishing to handle as well those cases with ease.

I can confirm that there's something strange w/ the sim; I keep you posted...

I have tried to investigate the build problem with esp8266, but I don't know enough about the tools to work out what is going on. I installed the esp32 toolset and it does build ok for esp32, but not for esp8266 (hardware rather than sim, the sim does build).

So I am stuck for the moment, sadly.

[Edit] I tried a couple of other contrib nodes and I get the same error with them, so it seems that for some reason I can't build contrib nodes for esp8266.

"the same error" means this one?

Yes, module "file" not found. The line number in the makefile moves about a bit but the rest is the same.

Can you share what steps you are following to try the contrib nodes? I have one I would like to try and get working.

I'm not sure, what @Colin did - but take it, create a flow, build & see what happens.
Despite the strange effects when building for ESP8266 Colins node worked without modification...

Yes, as @ralphwetzel said, just place it on the flow and build.

ok I will try that again. I was trying the n2n node by dceejay and it seemed to lock the ESP up. But let me do some more testing with it.

@Colin
I think I've found the cause for the "file" not found error & committed a small fix to the GitHub repo.

Well the good news is that it now builds ok, and the inject nodes work ok :slight_smile:
Unfortunately if I have any contrib node (well, I have tried three) then after flashing, the target immediately crashes.

...
Writing at 0x0007d000... (100 %)
Wrote 931716 bytes (516193 compressed) at 0x00001000 in 8.3 seconds (effective 894.8 kbit/s)...
Hash of data verified.
Compressed 128 bytes to 75...

Writing at 0x003fc000... (100 %)
Wrote 128 bytes (75 compressed) at 0x003fc000 in 0.0 seconds (effective 250.6 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...
Exception (3):
epc1=0x40220e4d epc2=0x00000000 epc3=0x00000000 excvaddr=0x402a3328 depc=0x00000000
ctx: cont 
sp: 3ffe9b10 end: 3ffea1e0 offset: 01a0
>>>stack>>>
3ffe9cb0:  00000001 3fff8d54 3fff701c 40220df4  
3ffe9cc0:  00000000 00000000 00000020 0000000b  
3ffe9cd0:  3fff700c 3fff8d54 3fff701c 402205cc  
3ffe9ce0:  40220c60 00000000 00000230 40107838  
3ffe9cf0:  3fff6e7c 3fff8d54 3ffe9f30 40107e10  
3ffe9d00:  0000000b 3fff8d54 3fff700c 40221136  
3ffe9d10:  3fff869c 00000004 3fff0cbc 40107e10  
3ffe9d20:  0000000e 40220c60 3fff8d54 4025c769  
3ffe9d30:  ffffff80 3fff7011 00000000 4022a0de  
3ffe9d40:  00000000 3fff6e81 3fff86a0 00000018  
3ffe9d50:  3ffe9dc0 3fff8d54 3fff8d54 40221179  
3ffe9d60:  3fff8840 3fff881c 00000001 3fff86bc  
3ffe9d70:  3fff86ec 00000002 3fff86fc 402319a8  
3ffe9d80:  00000000 3fff881c 4026a615 00000018  
3ffe9d90:  3ffe9dc0 3fff8d54 00000000 402215dc  
3ffe9da0:  00000000 3fff884c 3fff8d54 00000001  
3ffe9db0:  00000018 402a3310 3fff8d54 402218ef  
3ffe9dc0:  00000001 00000000 000003a8 402422ea  
3ffe9dd0:  40107e10 402a3310 402a3310 3fff700c  
3ffe9de0:  3fff701c 402a3310 3fff8d54 402415f1  
3ffe9df0:  402a3330 00000001 00000010 4020378c  
3ffe9e00:  3fff874c 00000000 3fff0cbc 3fff868c  
3ffe9e10:  3fff8d54 00000001 3fff8d54 40206c47  
3ffe9e20:  00000000 00000001 3fff86bc 4020a8a9  
3ffe9e30:  00000001 00000000 000002a2 4022d0c9  
3ffe9e40:  00000001 3fff9254 00000530 3fff872c  
3ffe9e50:  00000000 3fff86ec 4027d6ef 3fff868c  
3ffe9e60:  3fff86ac 00000001 3fff86bc 402319a8  
3ffe9e70:  00000000 00000000 0000066a 4010182d  
3ffe9e80:  3fff8d54 3fff869c 3fff875c 3fff869c  
3ffe9e90:  4027d6f4 000000ab 3fff870c 3fff872c  
3ffe9ea0:  00000000 000000a6 3fff8d54 4022288d  
3ffe9eb0:  0000000a 00000000 3fff8d54 4024369d  
3ffe9ec0:  3fff642c 3fff661c 3fff65ac 3fff669c  
3ffe9ed0:  00000000 3fff66dc 3ffe9f30 40223a2a  
3ffe9ee0:  3fff641c 3fff6e2c 3fff66a0 00000004  
3ffe9ef0:  3fff6e3c 000001d4 3fff641c 3fff88cc  
3ffe9f00:  40262e8d 3fff8d54 3fff641c 00000000  
3ffe9f10:  fffff8f0 00000005 3fff67ac 40226d8f  
3ffe9f20:  40103062 0000002b 7fffffff 00000002  
3ffe9f30:  4022699e 3ffe9f20 00000000 00000002  
3ffe9f40:  40262e8d 3fff88cc 3ffe9fb0 3fff88bc  
3ffe9f50:  3fff88dc 3fff88fc 3fff8d54 00000000  
3ffe9f60:  00000000 3fff8d7c 3fff8d54 402218ef  
3ffe9f70:  3fff8d54 3fff641c 3fff636c 3fff88cc  
3ffe9f80:  00000676 00000677 00000008 3fff5e4c  
3ffe9f90:  3fff91a0 3fff131a 3fff929f 3fff88cc  
3ffe9fa0:  40262e8d 00000002 00000000 40227501  
3ffe9fb0:  402274a7 3ffe9fb0 3fff8d54 00000000  
3ffe9fc0:  40262e8d 3fff88cc 3ffea010 3fff88cc  
3ffe9fd0:  3fff88dc 3fff88fc 5f469be7 00000000  
3ffe9fe0:  00000000 0000000c 4f77c000 3fff894c  
3ffe9ff0:  3fff8d54 3fff88cc 3fff5e4c 00000001  
3ffea000:  3ffea030 00000000 3fff8d54 4024a9aa  
3ffea010:  4024a971 3ffea010 3fff896c 00000000  
3ffea020:  3fff5f51 3fff894c 3ffea140 3fff894c  
3ffea030:  3fff894c 3fff896c 00000000 00000000  
3ffea040:  00000000 427863fe f3618000 40213fca  
3ffea050:  3fff8d54 3fff9254 00000282 3fff89dc  
3ffea060:  00000020 0000002f 3fff8d54 3fff894c  
3ffea070:  3fff5f51 00000000 3fff896c 40231701  
3ffea080:  00000022 40102e91 3fff12f4 fffffffe  
3ffea090:  3fff8d54 3fff895c 3fff8a9c 3fff895c  
3ffea0a0:  3fff0e27 000000ab 3fff89dc 3fff8a5c  
3ffea0b0:  00000000 4010570c 3fffc200 00000022  
3ffea0c0:  3ffea0d0 00000000 3fff8d54 00000001  
3ffea0d0:  00000010 3fff8d7c 3fff8d54 402218ef  
3ffea0e0:  00000001 3ffe91c0 3ffea140 00000000  
3ffea0f0:  00000001 3fff620c 3fff8d54 00000006  
3ffea100:  402632fa 3fff8d7c 3fff1288 40204054  
3ffea110:  00000000 3fffdad0 3ffea20c 3ffea20c  
3ffea120:  00000000 3fff8d7c 3fff8d54 402045cc  
3ffea130:  000000d0 3fff04c4 3fff8d54 40251538  
3ffea140:  40251440 3ffea140 3fff0ac4 3fff04c4  
3ffea150:  00000000 3ffea20c 00000000 3fff8c7c  
3ffea160:  00000000 00000000 00000000 00000000  
3ffea170:  00000000 001566f3 3fff045c 4025d860  
3ffea180:  3fff8d54 402632fa 00000003 3fff0784  
3ffea190:  3fffdad0 3fff04c4 3fff0ac4 4024a604  
3ffea1a0:  402019a2 000003b6 3ffea204 3ffea20c  
3ffea1b0:  3fffdad0 00000000 3ffea204 4025d71f  
3ffea1c0:  3fffdad0 00000000 3ffea204 4025d548  
3ffea1d0:  feefeffe feefeffe 3ffe91c0 40100114  
<<<stack<<<

It is still ok if I don't have a contrib node.
Would it tell me if I didn't have enough memory in the device?

According to my experience: No. [Edit:] ... for runtime memory; Yes if the flow build doesn't fit into the flash memory - which I've never seen so far with standard builds.

Welcome to the world of XS :wink: : You may define the "Creation Params" to change the (runtime) memory layout of your device. Here's a starting point in the documentation...

Is that what the problem is then? I don't really understand about the different memory layouts on the devices.

I don't think it is memory, I have taken out the MQTT nodes, which I am sure will use more than a simple contrib node.

Should I be able to set breakpoints in xsbug in this situation? If so, is the source of the contrib node the one in the .node-red/node_modules folder?

Yes, it is.
The log displays the working directory.
The manifests.jsons in there reference all used modules...

Not necessarily. MQTT is natively supported by the runtime, thus optimized to the MCU environment...

A bit more information. If I don't enter a wifi SSID then I can add my contrib node and it runs correctly. I have put breakpoints on the RED.nodes.createNode() line in my node and also in the trigger node (from the mcu folder) and on startup it hits the trigger node and then my node and all is well. In the xsbug log it says No Wi-Fi SSID. If I provide the ssid and pwd then in xsbug it says wifi connected and gives the ip address and then crashes before it gets to the createNode breakpoints.

Without the contrib node wifi (and MQTT if I add a node) works ok.

Does that give you any ideas where the problem might be? If not can you tell me where I might put some breakpoints to try and work out where it is going wrong?

xsbug provides a setting to Break on Start.
That gives you the earliest option to stop the flow and walk with the debugger through the generated code.
If it crashed before, it's an issue in the host code & thus a case for the Moddable team.

It seems to be some sort of timing issue. If I put a breakpoint here

image

in node-red-mcu/setupwifi.js, then it hits it on startup and when I tell it to continue it runs ok, but if I don't have a breakpoint somewhere in that area then it crashes. I am trying to tie it down further.