network module for micropython ports/unix

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
picpic020961
Posts: 15
Joined: Thu Feb 18, 2021 4:24 pm

network module for micropython ports/unix

Post by picpic020961 » Wed Apr 28, 2021 7:14 am

Bonjour ,

I have ports/unix [ lv_ ]micropython , works fine , like python.

now I want to connect to wifi but network module not exists. why ?

for example 'import asyncio' in python , 'import uasyncio' in micropython.

how to write [ u ]network ?

the idea : maximum compatible source script with ports/unix and ports/esp32 ( I am waiting
ESP32 with PSRAM)

thanks for help and regards

PS : sorry for bad english

stijn
Posts: 735
Joined: Thu Apr 24, 2014 9:13 am

Re: network module for micropython ports/unix

Post by stijn » Wed Apr 28, 2021 7:27 am

picpic020961 wrote:
Wed Apr 28, 2021 7:14 am
how to write [ u ]network ?
Either you'd have to implement unix/ports/modnetwork.c to mimick what ports/esp32/modnetwork.c does. And to do that you'll need to find a C library which works across the many different unix flavours out there, something like https://www.hpl.hp.com/personal/Jean_To ... Tools.html

Alternative is to just write a network.py which has the same classes and funtions as the ESP32 version but build it on top of e.g. https://github.com/joshvillbrandt/wireless. Probably the simplest solution.

Or if you don't actually need the wireless functionality, you could just create a network.py which has all functions/classes but which do not actually do anything. E.g.

Code: Select all

class WLAN:
  def __init__(*args, **kwargs):
    pass
  def active(*args):
    pass
# and so on

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: network module for micropython ports/unix

Post by kevinkk525 » Wed Apr 28, 2021 7:49 am

On Unix port your Unix distribution is in control of the network, so there is nothing to control for micropython. So whatever your scripts try to do with the network module won't work.

If your goal is just to write and test code until your Esp32 arrives and then move it to the Esp32, you can of course write an "empty" network module that just offers empty functions, you can do that but I think it is quite some effort to emulate the existing network module.

Sorry this is basically the same answer.. I just kept it open on my phone and got interrupted answering, now I can't delete it
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

Post Reply