How can i get the 'ussl' module for my microPython project?

258 Views Asked by At

I'm using microPython on a Arduino Nano Connect RP2040 and I'm trying to request an https website using the "urequests" library. Every time I try, I get the error message: "ImportError: no module named 'ussl'". I thought microPython would contain the ussl module. However, somehow that doesn't seem to be the case. I've tried several micropython versions and searched everywhere but could not find a way to fix this.


MY CODE:

import urequests as requests

url = "https://api.spotify.com/v1/me/player/next?device_id=****"
token = '****'

headers = {
    "Authorization": "Bearer" + token,
    "Accept": "application/json",
    "Content-Type": "application/json"
}

result = requests.post(url, headers=headers)
print(result.status_code)

MY SETUP:

MicroPython: v1.18-omv-r13

IDE: OpenMV (v4.3.3)

HAL: v1.3.0

BOARD: Arduino Nano RP2040 Connect-RP2040


1

There are 1 best solutions below

0
On

I finally find the solution for my problem!

first of all:

  1. The ussl modul can not be added after the firmware is created
  2. The module must be set active in the firmware files

With these insights, I cloned the micropython repo and modified the firmware files for my Arduino Nano RP2040 Connect. With the new modification i build a new firmware.

You need to clone the repo to build a firmware. The .git is necessary for the build process

micropython repo: https://github.com/micropython/micropython


File modification

arduino folder: micropython/ports/rp2/boards/ARDUINO_NANO_RP2040_CONNECT/

I just added

  • "set(MICROPY_PY_USSL 1)" in the mpconfigboard.cmake

  • "#define MICROPY_PY_USSL (1)" in the mpconfigboard.h


Build & Deployment

  1. Build the MicroPython cross compiler as described in the README of: https://github.com/micropython/micropython/tree/master/mpy-cross
  2. Build and deploy your firmware as described in the README of: https://github.com/micropython/micropython/tree/master/ports/rp2

After deployment, it is no longer possible to use an IDE to boot the board. You can edit the main.py normally while the board is connected to your PC. However, you must disconnect the power briefly after editing to allow a reboot.