Ok, So I would like to create a project using a bunch of connected micropython boards.
Each board will have a different combination of inputs/outputs, etc.
Example:
Board Style 1: 8 analog inputs, 8 relay outputs
Board Style 2: 16 analog inputs, 8 relay outputs, 4 analog outputs
etc, etc.
All boards will communicate likely using mqtt or mqtt-sn(possibly coap but I'll explore this later)
What I would like is to have 3 levels of code.
1) micropython firmware/interpreter
2) main python script that will handle the communication, pin setup, etc
3) scripts loaded basically as a configuration from the main controller over the network.
I obviously want to be able to also update 1 and 2 level code over the network but my question is are there any issues loading dynamic script content on level 3 on the fly and storing it on the device for reboots?
I'm planning a distributed automation system where you would program function in something similar to blockly and the exported code would be loaded into the board over the network on the fly.
I've done a ton of development in node.js and haven't touched python very much in the last couple years. I've been working on developing using another platform but its been on the side burner because of how involved it was on the micro controller but after finding micropython I have a new hope and would like to revive my project.
I do have a fair bit of experience in python as I used it extensively before I switched to node.js. I had thought of running node.js using embedded linux but this seems like a far better, lower energy, and better supported idea.
Last night I bought 6 development boards including 4 fipy(because why not have 5 radios to play with) and 2 pyboards(because a part of my project involves 9 bit serial) and while I wait I'm flashing some ESP32-wroom I have lying around.
Actually after finding micropython I plan to revive a number of small projects that will be much more attainable using python.
Thanks for any opinions(Hopefully positive, lol)
Running imported code
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Running imported code
I can't see any fundamental issue here, so long as the scripts were not too big to compile on the board. Each script would have to check for the arrival of its successor. The file would be saved to the filesystem as (say) script.py and a reboot issued. main.py would consist of
There is evidently scope for things going wrong if scripts were bad or became corrupted. The latter could be handled with CRC checking on arrival. Buggy scripts have the obvious potential to lock the board. If the board is accessible an SD card swap would fix it, otherwise you might need a watchdog timer.
Code: Select all
import script
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Running imported code
Ok Thank you for the answer.
I'd probably want to keep the old file on the board until the new file is verified working.
I was hoping I could have multiple files (imports) that would be able to handle different things such as.
1.py This program monitors 2 inputs runs some calculations and toggles an output
2.py this program watches a network variable (mqtt) and when changed compares to a local input and varies an analog out
3.py Setup some variables to store basic setpoints that the other files can access.
4.py etc etc etc
I was hoping I would be able to have a main process that would manage additional processes and each program would more or less run independently and be terminated and restarted if a new program was received. Doesn't look to be possible with micro python but thats not the end of world. I'll just have to make sure any boards that run an important program don't have anything else that could prompt a reboot at an inopportune time.
Thank you
I'd probably want to keep the old file on the board until the new file is verified working.
I was hoping I could have multiple files (imports) that would be able to handle different things such as.
1.py This program monitors 2 inputs runs some calculations and toggles an output
2.py this program watches a network variable (mqtt) and when changed compares to a local input and varies an analog out
3.py Setup some variables to store basic setpoints that the other files can access.
4.py etc etc etc
I was hoping I would be able to have a main process that would manage additional processes and each program would more or less run independently and be terminated and restarted if a new program was received. Doesn't look to be possible with micro python but thats not the end of world. I'll just have to make sure any boards that run an important program don't have anything else that could prompt a reboot at an inopportune time.
Thank you