0

I'm using Thonny, if there are better IDE's for working with python on microcontrollers definitely open to suggestions.

I have a node.js server using socket.io and express websocket server, that is correctly responding to clients.

For instance if I wrote a standard python socketio script like this, everything behaves as expected

import socketio
import asyncio
import requests

sio = socketio.Client()
uri = "ws://127.0.0.1:443"


@sio.event
def message(data):
    print(f'{data}')

@sio.event
def connect():
    print("I'm connected!")

@sio.event
def connect_error(data):
    print("The connection failed!")

@sio.event
def disconnect():
    print("I'm disconnected!")

sio.connect('ws://localhost:443')

This logs the messages as expected when I connect to the server.

However, I want this code to run on my Raspberry Pi Pico W so the standard interpreter and way importing third party modules doesn't work.

If I try to regularly import it, and use the microcontroller interpreter

import socketio

I get this error

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/lib/socketio/__init__.py", line 3, in <module>
  File "/lib/socketio/client.py", line 1, in <module>
ImportError: no module named 'itertools'

Which leads me to believe the module is being ran without it's dependencies because my local python interpreter runs this fine.

I came across this install tool called mip

However I can't get it working for third party packages. For instance this:

import mip
mip.install("https://github.com/miguelgrinberg/python-socketio/tree/main/src/socketio", mpy=False)

Throws the error below

Installing https://github.com/miguelgrinberg/python-socketio/tree/main/src/socketio/package.json to /lib
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "mip/__init__.py", line 1, in install
  File "mip/__init__.py", line 1, in _install_package
  File "mip/__init__.py", line 1, in _install_json
  File "urequests.py", line 180, in get
  File "urequests.py", line 76, in request
OSError: -6

I tried doing this in the actual script and in the REPL.

I'm hoping for a solution to use my microcontroller as a socket.io client and write to my pins based on messages from a nodejs server

SaintPreston
  • 103
  • 6

2 Answers2

1

The python-socketio package is for regular Python. There is no version that runs on MicroPython.

Miguel Grinberg
  • 65,299
  • 14
  • 133
  • 152
0

It fails at urequest in mip module. Most likely an issue with network connection. Is your device connected to the Internet?

Sliwa
  • 61
  • 8