phoddie / node-red-mcu

Node-RED for microcontrollers
124 stars 18 forks source link

MCU Builder node: Initial commit. #12

Closed ralphwetzel closed 2 years ago

ralphwetzel commented 2 years ago

This is the initial attempt to support / automate the node-red-mcu building process. This PR proposes a MCU builder node that is able to perform the building process from the node-red editor. Minimal usecase:

image

The build parameters can either be provided as a parameter in msg.mcu or defined in the node config panel:

image

A short description of how to install this package was added to the readme.

No intensive testing has been performed ... thus: Expect the unexpected! :wink:

phoddie commented 2 years ago

Interesting idea to integrate this as a node. I'm excited to try this out. After doing the npm install, I get this error launching Node-RED.

10 Jul 22:55:58 - [warn] [node-red-contrib-mcu/mcu] Error: Cannot find module 'fs-extra'
Require stack:
- /Users/hoddie/Downloads/node-red-mcu-main/mcu.js

Maybe it is just a dependency problelm?

ralphwetzel commented 2 years ago

I was unsure, if that was necessary - yet it seem to be (once):

cd <path to your cloned directory>
npm install
phoddie commented 2 years ago

That eliminates the error. I will try this out as soon as I can.

phoddie commented 2 years ago

I'm getting closer. ;)

When running the flow, I get this error:

11 Jul 12:16:44 - [error] [node-red-mcu:2226b30fe881e9d5] TypeError: Cannot read properties of undefined (reading 'flows')

Here' the flow set-up:

image

I created an empty directory for the working directory at node-red-mcu-test. Is that correct?

ralphwetzel commented 2 years ago

Sorry - I‘ve been a bit short yesterday describing the idea:

I‘ll check if I can locate the issue you encountered…

ralphwetzel commented 2 years ago

I‘ll check if I can locate the issue you encountered…

Ok. I think I found the issue. As a workaround, please inject an empty object msg.mcu via the inject node. I‘ll provide a fix later this week.

phoddie commented 2 years ago

@ralphwetzel – that works! Very nice.

The "working directory" is where you create the Moddable SDK project.

I'm not sure what "Create Build Environment" does. I haven't had a chance to read your sources yet to understand what it does.

ralphwetzel commented 2 years ago

If you uncheck the option "Create Build Environment", only flows.js will be created (in the working directory) - yet the rest of the files not. BTW: Feel free to propose a better wording for those labels - at best derived from the naming conventions used by XS.

phoddie commented 2 years ago

I really like your focus on trying to make things as easy as possible for users. I have a some suggestions for the configuration dialog with the goal of making it more accessible for casual users while maintaining access to more powerful capabilities for more advanced users.

For most users, it will be enough to just run the project. They don't need to know the path. Maybe it would be enough to create a temporary directory, put flows.js there, copy the necessary files, and build.

For more advanced users, an option to choose a path would be great. In that case, it could always just write write flows.js only.

The "build command line" is a bit esoteric for users getting started. For most users, it would be enough to choose either "simulator" (to run on thee local device) or give the platform ("esp32/moddable_two", "esp", "pico", etc). For device targets, you could provide boxes to enter Wi-Fi SSID and password and add those to the command line. An advanced option to provide the full command line would be a fallback for special cases.

ralphwetzel commented 2 years ago

As of now, the dialog matches the description you provided to build projects for XS. I agree, that it's currently quite technical - yet as well ultimately flexible. For the time being, I would like to focus on adding functionality ... knowing there's plentitude of opportunities to make things nicer. That said, I propose to merge things as they are for now & put your valid comments on the ToDo-List.

phoddie commented 2 years ago

That's fine. I would prefer not to make the root of the node-red-mcu project specifically for the MCU builder. Maybe that is the right answer in the long term, but it seems too early to make that assumption. the nodes directory is for nodes that run on the MCU. What do you think about moving the content of this PR to tools/mcubuilder? It is pretty easy to imagine that there will be other tools eventually.

ralphwetzel commented 2 years ago

You're right. In the end, my proposal is just one way to integrate this idea into the NR editor. Thus I'll close this PR & keep things seperated - to not create too much interference.

phoddie commented 2 years ago

...my proposal is just one way to integrate this idea into the NR editor. Thus I'll close this PR & keep things separated - to not create too much interference

I still think it would be good to have as part of this repository. It is useful and provides an example for others who may with to explore other approaches.