Skip to main content

Posts

 Hi, This just to keep this blog going, more coming up soon.
Recent posts
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|| D 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
Multi-threading : I previously used an uasyncio webcam server. This time around, I am testing a multi-thread webcam server. The result is promising. A multi-thread server seems to give a better throughput. The program logic is simpler when compared to the server based on uasyncio. The server is a four threaded application, two for port 80, one for port 81, and port 82 runs on the main thread, which blocks the REPL.  You can start a dedicated thread for port 82 if you do not want to block the REPL. I found pix/7 gives the best performance. A spe/2 will reduce the image size but give you a grayscale image. Please see my previous blog if all these seem mysterious to you. I have compiled a new firmware, MicroPython v1.11-571-g7e374d231.  You can download the new firmware from my repository at GitHub. The soft reset is not functioning properly. You need to do a hard reset. I also include four new functions in modcamera.c: pixformat agcgain aelevels aecvalue The pixformat chan
Micropython - v1.11-498 introduced a few changes in the source-code directory structure. Changes to specific files, as previously described in esp32-cam , will no longer work. A simple working summary on how to build esp32-cam firmware is described below: Make a recursive copy of ports/esp32 to ports/esp32-cam, and you will need to modify the following files: 1) ports/esp32-cam/main.c 2) ports/esp32-cam/Makefile 3) ports/esp32-cam/modcamera.c 4) ports/esp32-cam/mpconfigport.h 5) ports/esp32-cam/boards/manifest.py 6) ports/esp32-cam/boards/sdkconfig.base Or, you can just download a precompiled Micropython v1.11-498 from firmware.bin at GitHub if you want to save some work. However, I encourage you to compile the firmware yourself. You will learn a lot and you can choose to modify anything to your liking. The modcamera.c includes something new. The still photo was taken using these settings; pix =8, con =2, qua =10, and spe =2. You will understand those parameters, later