Micropython

Hey rioters,

has anyone heard about Micropython[1] yet? Seems like an interesting project and I would love to give it a try on RIOT. There's "STM version" version that comes with "stmhal", so I guess it shouldn't be too difficult (sic!) to port it to RIOT. However, I guess it makes only sense for some of the more powerful boards, since the stmhal firmware already consumes almost 300kB ROM and 30kB RAM.

Cheers, Oleg

[1] http://micropython.org/ [2] http://www.st.com/web/catalog/tools/FM116/SC959/SS1532/LN1847/PF260000

If you want to do python, sure that's ok.

I've done a lot of Python programming and just come to the personal conclusion that it's not as nice to develop in for an embedded device as is C++.

If somebody really tries hard (and knows Python), it's possible to get C++ to be not too much bigger than Python in code length.

Here's an example I wrote of an IoT switch: https://github.com/clixx-io/clixx.io/blob/master/examples_eventframework/remoteswitch/remoteswitch.cpp

That's in C++, all it does is switches a GPIO pin On/Off when an IoT message "On" / "Off" is received.

I haven't found a way to do it as nicely in Python as C++. And there are many devices where Python is never going to be an option such as the MSP430/AVR/PIC. Add to that, one IoT customer requirement can be ultra-low power - running on a solar cell etc.

That's just my 2c

David

Hi, Appart from web projects or an “advanced calculator” I use python primarily as means to prototype an idea I have (or if shell script would be just too complicated ^^) and then go to C (others probably would go to C++, but that is a matter of personal taste, I think), if I need performance, so for this (and as a low entry point for absolute beginners) I would welcome python (or some other easy-to-learn scripting language) as a feature in RIOT.

As I am a huge Python fan-girl and for arguments sake I felt inclined to provide a similar example as presented by David. But since I do everything embedded in C and everything else is not really comparable, I envisioned how something similar as David’s example could look like in a dreamed-up RIOT-ported (micro)python (assuming we map RIOT modules to python modules) :-D: https://gist.github.com/authmillenon/cf748f9525d8a3cfa34e (mind that the RIOT.thread module might even be replaced by a RIOT-specific implementation of python’s own threading module)

An eyewinkling cheers from, Martine

PS: Mind that micropython is completely written in C and the RIOT-backend would probably also be written in C, so I’m not sure how valid the size argument is without in-depth testing.

Hi!

I haven't found a way to do it as nicely in Python as C++. And there are many devices where Python is never going to be an option such as the MSP430/AVR/PIC. Add to that, one IoT customer requirement can be ultra-low power - running on a solar cell etc.

That's probably true and I'm not sure either if things like micropython or elua will be really useful for IoT applications in the end, but I envision it more as a kind of "advanced configuration" possibility. That means, that the whole system is written in highly efficient C or C++ code, but giving the application the possibility to execute python code to perform easy modifications of the system's behavior at runtime in cases where real software updates are not feasible/desirable and the simple replacement of some parameters is not enough.

All in all, I'm just curious how things like that would perform on RIOT on IoT device.

Cheers, Oleg

.. I need performance, so for this (and as a low entry point for absolute beginners) I would welcome python (or some other easy-to-learn scripting language) as a feature in RIOT.

True. And if you look at some Python<->C networking performance comparisons, Python can come out ahead of C. All the best webservers are no longer written in C, afaik.

I envisioned how something similar as David's example could look like in a dreamed-up RIOT-ported (micro)python (assuming we map RIOT modules to python modules) :-D: https://gist.github.com/authmillenon/cf748f9525d8a3cfa34e [3]

Definitely!

I actually assembled my C++ EventFramework after seeing/using https://pypi.python.org/pypi/circuits

As a micro-python option, there's also LUA. Which is already popular on Routers. It's not as memory or stack hungry. It's halfway between Python and C++. LUA just doesn't have the wow factor of Python for me unfortunately. But it would be better suited imho than Python and known to work on small processors.

Python would be a very good language to have as a friend of Riot, but there are *so* many compatability issues to solve downstream Operating-System wise, ie filesystems, databases, timers, pyrserial. I just can't see enough of those basic pythonic functionality items implemented for Python to be viable.

Unless that is, the 'Python for DOS' concept is used as a starting point.

One other way, is to say, 'ok, everything else can run Python (our notebooks/phones/pc's) and we'll use that to talk to our Riot devices'.

In that case things are much simpler.

But to restate, having small code applications like https://gist.github.com/authmillenon/cf748f9525d8a3cfa34e is the way to go. Nobody has 3 weeks to code stuff these days and small, fast and short is a great way to go.

Regards

David

Hi,

I looked again at your example and took the opportunity to do some trimming. The python goes to 21 lines in length and I could get the C++ down to 22 lines of code. So I would say, directly comparable?

The advantage of the C++ is that it would run on Linux and anything with GCC such as the MSP430, whereas the Python will only run on the larger machines.

While I’m not a python fan, I acknowledge the power that it has for newbies. The pull request from 2015 for RIOT-OS port has yet to be merged. I imagine it needs rebasing from both the RIOT-OS and Micropython sides.

Long thread here about C/C++/micropython, and it’s not about lines of code. It’s about allowing newbies to do useful things without shooting themselves in the foot quite so easily. A reason I’d want to run micropython on RIOT-OS is because the other RTOS haven’t got particularly good networking. Depending upon which branch, you probably get no IPv6, no RPL, CoAP, etc.

What I’d like to see is a way to delve into the RPL, IPv6 and CoAP pieces from micropython. But, I’m actually totally ignorant on how to do networking with micropython, on RIOT-OS. “import network” doesn’t work. So what does work?

@mcr did you take a look at the example which pulls in this micropython fork from @Kaspar which has support for some RIOT apis? (xtimer, adc, GPIO iirc)

(no network support that I know of so far though)

@Karpar’s pull request into micropython is 6 year old. It was last touched two years ago when we pulled in the code, but what about the flow of patches the other way?

I used micropython on M3 boards for a major dGPS trial in Iceland… as it is so much easier to patch in the cold/rain. It would be great to have RIOT on a board doing serious stuff like CoAP coms and schedule but have a page of micropython for the top level code :wink: Ideal on a dual core rp2040 I think!!