Skip to main content

Posts

Showing posts from December, 2019
Time - multiplexing  - The _threads modules for esp32 is a time-multiplex multi-threading implementation on a single CPU (APP-CPU) where the tasks take turns to run. Let say we have four tasks A , B , C , and D . Each task takes 100 microseconds to complete. If these tasks are arranged to run in sequence A -> B -> C -> D then the whole process will take 400 microseconds. What if we run these tasks concurrently in 4 separate threads, A || B || C || D . How long the process takes to complete? The answer is 400 microseconds also. We have not made our concurrent tasks running any faster. What is the point of multi-threading then? The ability to use multi-threading in our codes will make our programs more responsive to external events. Consider this; let say our threads scheduler allocates a 25-microsecond slot to each running task, in a round-robin style. Each tasks are allocated 4 slots of 25 microseconds. What happen conceptual is like this; A 1|| B 1|| C 1|| ...
CryptoXo - pronounce crypt oxo, is a simple XOR encryption/decryption. MicroPython includes two security modules out of the box; 1) cryptolib and, 2) ussl. $ micropython MicroPython v1.11-631-gb76f0a73b-kaki5 on 2019-12-09; linux version Use Ctrl-D to exit, Ctrl-E for paste mode >>> import cryptolib >>> dir(cryptolib) ['__class__', '__name__', 'aes'] >>> import ussl >>> dir(ussl) ['__class__', '__name__', 'wrap_socket'] >>> CryptoXo is meant as an experiment and not as a replacement to cryptolib.aes. Please use it in your codes if you find it to be good enough. Basically, there are two ways to do xor encryption in micropython: 1) ''.join(chr(ord(a) ^ ord(b)) for a,b in zip(s1, s2)) 2) bytes([_a ^ _b for _a, _b in zip(ba1, ba2)]) Bytes xor is faster than strings xor. We use bytes xor in the CryptoXo module. XOR provides is a very week encryption scheme, but it i...
Frozen Modules : The custom made firmware mentioned in my previous blog includes a froze module CryptoXo, which is just a simple XOR encryption. The esp8266 port does not support threading. I want to incorporate concurrent codes in esp8266, so I have modified uasyncio modules from two files; __init__.pt and core.py to one uasyncio.py file, and include a frozen uasyncio module for esp8266. A micropython running on Unix is a nice thing to have. It is useful for developing and testing scripts. Of course, we can not test scripts using some specific parts of hardware boards' electronics. Unix port micropython will find modules under the 1) current directory, 2) '$HOME/.micropython/lib' and 3) '/usr/lib/micropython'. Nevertheless, all frozen modules are only visible in REPL. If you try to import a frozen module in a script executing outside of REPL then you will get an ImportError message. A shebang micropython, that is to say, a script with #! execute mech...
Custom made - Sometimes, it is nice to be able to build custom made things. Thanks to Damien George and all the clever people at micropython.org for making it easy. So that, to custom build a micropython is not that difficult. Why do you want to build customize firmware anyway? Well, you might want to include some functionalities of your own and removed some functionalities from the standard distribution. The choices are there for you to make. I have a few changes that I want to make in micropython. version header -kaki5 (pronounce kaki-lima) an additional thread cleanup function for esp32 add frozen modules CryptoXo and uasyncio remove help, upip, and webrepl camera C module for esp32 camera board These are accomplished by modifying and adding files. py/makeversionhdr.py py/modthread.c extra/CryptoXo.py, extra/uasyncio.py, and manifest.py mpconfigport.h main.c and modcamera.c I also want to remove some modules specifically, help, upip, and webrepl from esp32...