r/MicroPythonDev • • Aug 24 '24

How to use the asymmetric ciphers from SSL module to encrypt data?

2 Upvotes

I'm creating a MicroPython-based device that is supposed to log data in an encrypted form. The idea is that even if the device gets lost, the data can't be read by the unauthorized person. So the data before storing on the SD card will be encrypted with randomly generated AES key. The key itself will be encrypted with the public key of the intended recipient, and stored on the SD card.
The cryptolib module provides the AES implementation. However the asymmetric ciphers are available only in the SSL module.

>>> import ssl
>>> s1=ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
>>> s1.get_ciphers()
['TLS-ECDHE-ECDSA-WITH-AES-256-GCM-SHA384', 'TLS-ECDHE-ECDSA-WITH-AES-256-CCM', 'TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA384', 'TLS-ECDHE-RSA-WITH-AES-256-CBC-SHA', 'TLS-ECDHE-ECDSA-WITH-ARIA-256-GCM-SHA384', 'TLS-ECDHE-ECDSA-WITH-ARIA-256-CBC-SHA384', 'TLS-ECDHE-ECDSA-WITH-AES-128-GCM-SHA256', 'TLS-ECDHE-ECDSA-WITH-AES-128-CCM', 'TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA256', 'TLS-ECDHE-RSA-WITH-AES-128-CBC-SHA', 'TLS-ECDHE-ECDSA-WITH-ARIA-128-GCM-SHA256', 'TLS-ECDHE-ECDSA-WITH-ARIA-128-CBC-SHA256', 'TLS-RSA-WITH-AES-256-GCM-SHA384', 'TLS-RSA-WITH-AES-256-CBC-SHA256', 'TLS-ECDH-RSA-WITH-AES-256-GCM-SHA384', 'TLS-ECDH-RSA-WITH-AES-256-CBC-SHA', 'TLS-ECDH-ECDSA-WITH-AES-256-CBC-SHA384', 'TLS-RSA-WITH-AES-256-CCM-8', 'TLS-ECDH-RSA-WITH-ARIA-256-GCM-SHA384', 'TLS-ECDH-ECDSA-WITH-ARIA-256-CBC-SHA384', 'TLS-RSA-WITH-ARIA-256-CBC-SHA384', 'TLS-RSA-WITH-AES-128-CCM', 'TLS-RSA-WITH-AES-128-CBC-SHA', 'TLS-ECDH-RSA-WITH-AES-128-CBC-SHA256', 'TLS-ECDH-ECDSA-WITH-AES-128-GCM-SHA256', 'TLS-ECDH-ECDSA-WITH-AES-128-CBC-SHA', 'TLS-ECDH-ECDSA-WITH-ARIA-128-GCM-SHA256', 'TLS-RSA-WITH-ARIA-128-GCM-SHA256', 'TLS-ECDH-RSA-WITH-ARIA-128-CBC-SHA256']
>>> 

Is it possible to use those ciphers outside the ssl module, to encrypt the AES key with (e.g.) the RSA public key?


r/MicroPythonDev • • Aug 11 '24

Windows 11 - Do I need to install a USB to Serial driver ?

2 Upvotes

I am setting up PyMakr 2 in VS Code on Windows 11 to work with a Esp32 dev board

I installed this USB to Serial driver : https://www.silabs.com/developers/usb-to-uart-bridge-vcp-drivers?tab=downloads

But I have trouble connecting - is busy.


r/MicroPythonDev • • Aug 01 '24

PIO-based touch capacitance sensor with three inputs

Thumbnail reddit.com
2 Upvotes

r/MicroPythonDev • • Jun 10 '24

I2C Sensor Returning 0's on Pico but works Perfectly on RPi 3

2 Upvotes

I'm at my wits end over an ENS160 sensor I have working perfectly with a Raspberry Pi 3 (running full Linux OS and Python), but refuses to return any data when interfacing through a Raspberry Pi Pico with MicroPython.

Long story short, I purchased ENS160 + AHT21 breakout boards (two sensors, one board). All of them worked quite well with the Raspberry Pi Pico through MicroPython... for a period of time. After a number of days of continuous reading, the ENS160 readings would eventually start returning 0's for all three readings (AQI, TVOC, and ECO2). Initially, it was intermittent and I was able to do some configuration to get it back to life again. But as time went on, they grew more and more unreliable with the 0's coming back more frequently. At this point, many of the sensors simply don't return any data at all, no matter how I configure them. There is also no sign of any error being logged by the ENS160 from what I can tell. The AHT21 sensors all continue to work perfectly, so I don't think it is a problem involving the I2C lines.

What makes this absolutely puzzling: as soon as I wire one of these sensors (that were proven to not work on the Pico) to a Raspberry Pi 3 (running full Linux OS), it works perfectly. Data comes in, fully reliable, never misses a beat. I've tracked the exact register reads and writes by the Raspberry Pi 3 to the sensor and mimicked them completely with the Pico in MicroPython, both at initialization and read; no luck.

What I've tried:

  • Maybe the Pico's 5V (or 3.3V which I tried too) power supply is unstable. I tried external power. Same results.

  • Adding I2C pull-up resistors when interfacing with the Pi Pico, 10k ohms and 220 ohms. Same results.

  • Using a range of clock speeds (frequencies) - everything from 50,000 Hz to 400,000 Hz. Same results.

I've spent weeks now trying to figure out the issue. I've documented a lot of my trials in this GitHub repo here.

How could this be? I was going to chalk this up as a faulty sensor from a poor manufacturer, but this can't be the case as it works perfectly as soon as I hook it up with the Raspberry Pi 3. Any thoughts are appreciated, thank you!


r/MicroPythonDev • • Jun 07 '24

MicroPython and deploying library files

Thumbnail self.pycharm
2 Upvotes

r/MicroPythonDev • • May 30 '24

CASE

2 Upvotes

Does MicroPython have Match-Case yet?


r/MicroPythonDev • • May 08 '24

10 Zone ESP32 Sprinkler Controller using micropython

2 Upvotes

I just finished the code for this sprinkler controller if anyone is interested. The reason I made it is to have sprinkler scheduling kept locally in case of network connection failure. However, I included MQTT integration so you can monitor and control each zone from home assistant if you choose. This is my first real github project that I'm sharing with people so feel free to let me know what you think and where I can improve!

https://github.com/TannerNelson16/sprinkler_controller


r/MicroPythonDev • • May 05 '24

74hc165n PISO on raspberry pico

2 Upvotes

Hi everyone!

I'm building a raspberry pi pico based drum-machine/sequencer (whis is kinda the same thing xD)

the idea is to have 16 pairs of button/led for the steps, I managed succesfully to use the 595 to drive the led's (for now a single register I will attach a second one later) but I'm struggling a bit with the PISO 165n, by going through documentation and copying from arduino sketches (this one) I've came up with the following code to read from the register:

def in_shift_update(data,clock,clockE,latch):
val = 0
clockE.value(0)
clock.value(0)
latch.value(1)
utime.sleep(0.00005)
clock.value(1)
utime.sleep(0.00005)
latch.value(0)
for i in range(8):
val = val<<data.value()
clockE.value(1)
print(val)

data= pi:9 165:QH, latch= pi:10 165:SHLD,clock= pi:11 165:CLK,clock_e=pi:19 165:CLK INH

I also tried reading 8 times and concatenating into a string but I'm getting either 11111111 or random strings of bits, I think that I'm close to the solution but I'm failing at interpreting the clocking

component schematics here


r/MicroPythonDev • • Apr 30 '24

My open source, ESP32-S3 based, multi-RAT (cellular LTE-M and NB-IoT and WiFi/BLE) module Walter is featured on the IoT show from Oliver Bloch.

2 Upvotes

Hi fellow MicroPython developers,
I'm so glad to share that my project Walter will be featured in the IoT Show from Olivier Bloch. It will air coming Wednesday at 7AM PDT, make sure to subscribe to his channel to sit on the first row: https://www.youtube.com/obloch

I can already share some sneak peak:

Walter is an open source (https://github.com/QuickSpot) module that combines an ESP32-S3 together with a Sequans monarch 2 cellular modem. This gives Walter LTE-M, NB-IoT, WiFi, BLE, GPS and GLONASS capabilities. It is pin and software compatible with the former Pycom GPy and thus a drop-in replacement for it. We opted to go with mainstream MicroPython support for Walter and made the complete asyncio based modem library open source on github. We have tested Walter with various beta testers all over the world: https://walterdemo.quickspot.io/

The open source Walter cellular and WiFi/BLE/GPS module crowd funding is only running for two more days. Now is your chance to get Walter at the early bird price of 70USD: https://www.crowdsupply.com/dptechnics/walter


r/MicroPythonDev • • Mar 12 '24

Has anyone implemented A*, D*, D* Lite algorithms in ESP32? Is it possible to implement these algorithms using micro python in ESP32?

2 Upvotes

r/MicroPythonDev • • Mar 03 '24

Solving the CORS error in Javascript with MicroPython

2 Upvotes

I was building a project in which some Javascript code needed to access my Raspberry Pi Pico wich was programmed with micropython. And I could not get the data from the Pico. By examining the Javascript console I saw there was a CORS error. This error occurs when a different computer tries to access your webserver.
I found out how to solve this and that may be handy for you all:

http://lucstechblog.blogspot.com/2024/03/solving-cors-error-in-micropython.html


r/MicroPythonDev • • Feb 08 '24

please help me im new in coding!!!

2 Upvotes

so I have this object (its in MicroPython for ev3)
EV3 = EV3Brick()
left_motor = Motor(Port.A)
right_motor = Motor(Port.B)
WHEEL_DIAMETER = 55.5
AXLE_TRACK = 104
robot = DriveBase(left_motor, right_motor, WHEEL_DIAMETER, AXLE_TRACK)

and the last line is saying that its an a error and when I'm trying to put something else in this line its still doesn't working


r/MicroPythonDev • • Jan 02 '24

Micropython sockets seems to be using more and more RAM with every socket timeout

2 Upvotes

I have a Pi Pico W running Micropython. The code creates a socket and awaits a connection. After 10 seconds it times out and re-opens the socket. With each timeout it seems to be using more and more RAM until it crashes the Pico. I have the socket set to timeout because the device on the other end may move out of WiFi range after it connects but the Pico is unaware that the socket is not in use and keeps it open forever without the timeout. The Full code below:

import network
import socket
import time
import gc

ssid = 'myssid'
password = 'mypassword'

def connect():
    wlan = network.WLAN(network.STA_IF)
    wlan.active(True)
    wlan.connect(ssid, password)
    ErrCount = 0 
    while wlan.isconnected() == False:
        ErrCount += 1
        if ErrCount > 12:
            ErrCount = 0
            print("Retrying")
            wlan = network.WLAN(network.STA_IF)
            wlan.active(True)
            wlan.connect(ssid, password)
        print('Waiting for connection...')
        time.sleep(1)
    ip = wlan.ifconfig()[0]
    print(f'Connected on {ip}')
    return ip

ip = connect()

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host = ip
port = 49662
s.bind((host, port))
s.settimeout(10)
s.listen()
while True:
    try:
        c, addr = s.accept()
        print(f"Connection from {addr}")
        time.sleep(0.5)
        data = c.recv(1024).decode()
    except:
        print("Socket Timeout, re-trying")
        print(f"Memory: {gc.mem_alloc()} used with {gc.mem_free()} bytes remaining.")
        gc.collect

The result is this:

Connected on 192.168.1.77

Socket Timeout, re-trying

Memory: 6288 used with 186480 bytes remaining.

Socket Timeout, re-trying

Memory: 6464 used with 186304 bytes remaining.

Socket Timeout, re-trying

Memory: 6640 used with 186128 bytes remaining.

Socket Timeout, re-trying

Memory: 6816 used with 185952 bytes remaining.

etc...

Any ideas how to stop this as I need the Pico W to run reliably for a week without stopping?


r/MicroPythonDev • • Oct 26 '23

OutGauge and MicroPython

Thumbnail self.beamng
2 Upvotes

r/MicroPythonDev • • Sep 29 '23

ili9488 and micropython

2 Upvotes

I have a 3.5 inch ili9488 SPI display, and I'm trying to get it working with micropython and esp32. I tried using this ili9341 driver but none of the methods did anything. I can't find a micropython driver specifically for the ili9488. if you have this display and you got it working, please tell me the driver you used. thanks.


r/MicroPythonDev • • Sep 18 '23

Micropython for DSP

2 Upvotes

I have an STM32F407VE black board with Micropython configured….

Im not familiar with bare metal language or embedded C, just Python. I’m interested in carrying out Signal processing using micropython on board. I dont want to use the CMSIS module,,,, has anyone managed to do DSP using micropython on stm32???


r/MicroPythonDev • • Sep 16 '23

Help needed for Bluetooth w/ MicroPython

Thumbnail self.raspberrypipico
2 Upvotes

r/MicroPythonDev • • Sep 15 '23

Ummm, where’d the docs go? “MicroPython Documentation Not Found!”

Thumbnail docs.micropython.org
2 Upvotes

Micropython documentation seems to be down. 🧐 Hopefully it’s only temporary.


r/MicroPythonDev • • Sep 11 '23

I need tips on how to best use garbage collection in MicroPython

2 Upvotes

Can someone give me a primer or an example of how to best implement the garbage collection funtion in MicroPython? Suppose I have some code that is running a loop for 24hrs on a thread, how can it best be implemented to make sure that the memory does not run out?


r/MicroPythonDev • • Sep 03 '23

Is there a good tool or something that allows you to convert some python code into Micropython code?

2 Upvotes

I've written some code in python and i want to use it on my casio cg50 that uses Micropython. I've tried using chatgpt to convert the code but it gives me a Syntax error: invalid syntax (it doesn't say the line). Do you have any idea.

For reference, this is the original code:

def max_num(head, sequence):
for i in sequence:
if i > head:
return i

def min_num(head, sequence):
for i in range(len(sequence) - 1, -1, -1):
if sequence[i] < head:
return sequence[i]

def CLOOK(N, head, sequence):
seek_sequence = []
stop_condition = min_num(head, sequence)
seek_operations = 0
seek_sequence.append(head)
near_num = max_num(head, sequence)
for i in range(len(sequence)):
if near_num > head:
difference = near_num - head
seek_operations += difference
head = near_num
seek_sequence.append(head)
near_num = max_num(head, sequence)
if head == stop_condition:
break
if head == max(sequence):
difference = head - min(sequence)
head = min(sequence)
near_num = max_num(head, sequence)
seek_operations += difference
seek_sequence.append(head)
print("Seek Sequence :  ", end=" ")
for i in seek_sequence:
if i == stop_condition:
print(i)
else:
print(i, " ==> ", end=" ")
return seek_operations

if __name__ == "__main__":
Number_disk = int(input("Enter the number of disks: "))
if Number_disk > 0:
head = int(input("Enter initial header position :   "))
while not head in range(Number_disk + 1):
head = int(input("Please enter valid initial head position :"))
sequence = []
sequence = list(map(int, input("Enter the sequence :    ").split()))
sequence.sort()
if min(sequence) < 0 or max(sequence) > Number_disk:
print("Sequence out of range")
exit(0)
seek_operations = CLOOK(Number_disk, head, sequence)
print("Total number of seek operations : ", seek_operations)


r/MicroPythonDev • • Jul 25 '23

How to use 'execfile' command with mpy files

2 Upvotes

i can import it but i cannot run it using execfile

example

execfile("/system/sysuser/prgm/helloWorld.py") 

works while

execfile("/system/sysuser/prgm/helloWorld.mpy") 

does not


r/MicroPythonDev • • Jun 18 '23

Thonny having issues uploading to esp on Windows

2 Upvotes

I uploaded all 3 sizes of micro Python to this esp8266 and a model 01. Thonny says it was a successful install yet this happens everytime and makes the thonny terminal spit junk.


r/MicroPythonDev • • May 20 '23

Micropython with Thonny and a Raspberry Pi Pico

2 Upvotes

have pin14 setup to react to a rising IRQ upon which time it prints "button pushed". Now how would I have those rising IRQ's caused by a button push increment to a given count and when that count is reached make pin13 high to light an LED? I have pin14 setup and its working I have pin13 setup with a led. But i am new and trying to tie together an IRQ and a Count to make pin13 go high is eluding me. Coffee isnt helping.... Following is what I currently have...

import machine

import utime

button = machine.Pin(14, machine.Pin.IN, machine.Pin.PULL_DOWN)

led = machine.Pin(13, machine.Pin.OUT)

count = 0

def button_handler(pin):

utime.sleep_ms(100)

if pin.value():

print("button pushed")

print(count)

led.toggle()

button.irq(trigger=machine.Pin.IRQ_RISING, handler=button_handler)


r/MicroPythonDev • • May 18 '23

micropython exec dont work with try: catch: if its a syntax error, bug or not?

2 Upvotes

r/MicroPythonDev • • May 17 '23

Create virtual USB serial device on RP2040 using micropython

2 Upvotes

Currently, I am using micropython to prototype a simple measurement device using a Pi Pico. While micropython certainly isn't my preferred way to do it, it is actually nice, I'm enjoying it, and it's not like I have a choice :)

I am obviously connecting via microUSB. I have a /dev/ttyACM0 or something like it to connect thonny or ampy. However, because uPython requires that connection, I can't get, for example, sensor data out of my device via that serial connection.

Is it possible to register a second USB serial device, something like /dev/ttyUSB1, with a custom vendor ID etc.?

If not, what other ways are there to get the data off my device? I don't have any free pins and wireless is my last resort. Ideas? I really appreciate your help!