esp8266 webImport

This entry is part 2 of 2 in the series ESP8266

UPDATED and BUGFIXED!

MicroPython Repl command line is very nice, because you can telnet to the chip and read-and-evaluate python code. It is a great way of learning embedded IoT. The bad thing you cannot copy file while it is running, so experimenting get bad.

Also an automatic module update would be a very nice thing to have.

So I have created a small module called webImport which is able to

  1. download a module.py from a known http server
  2. write it in the esp8266 and import it
  3. enable your esp8266 to be hacked by a worm :) (see below for caveats)

The idea is to serve your remote module via a HTTP server and load it on the repl (or programmatically) with

After a while you edit your modulename.py and you make a newMethod. So you want to reload it…with…

The CODE

The code is below and was tested on esp8266. It should work on Pyboard and more powerful board too.

 

Optimization

As a bonus you can cross-compile the module, using the MicroPython cross compiler, which runs under any Unix-like system and compiles .py scripts into .mpy files.

https://github.com/micropython/micropython/tree/master/mpy-cross

This step is optional but offer to you less memory usage and better performance

 

Final thoughts

Be warned: having a remote download and execution code is a security risk. Node.js’ Npm package manager face this risk again and again, so you should consider some sort of password protection and / or https authentication using the ussl module which does not protect you but Man in the middle attack.

Series NavigationEsp8266 Music Machine

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.