mqtt_udp icon indicating copy to clipboard operation
mqtt_udp copied to clipboard

Feature request: micropython implementation

Open mdef opened this issue 6 years ago • 13 comments

Bug or feature

Feature: port code base to "new platform" / "specific python language implementation"

What is wrong / not implemented

Consider micropython implementation

How should it be

mqtt_udp should be ported to MicroPython / Circuitpython (supported by adafruit) / BBC micro:bit MicroPython is strong platform and micro:bit is used in school computer education in the UK. it is running on multiple boards e.g esp8266 / esp32 / stm series, linux port is available

more details about supported boards https://github.com/micropython/micropython/wiki/Boards-Summary

From my side I could provide testing on bare-metal

mdef avatar Feb 22 '19 00:02 mdef

I was thinking about trying nodemcu with python, and it looks like a good idea. Can you, please, try current python3 code on some micropython device and tell me where is the most obvious problem?

dzavalishin avatar Feb 22 '19 10:02 dzavalishin

(Just a reference for me on working with micropython)

https://m.habr.com/ru/post/345912/

https://m.habr.com/ru/post/341716/

dzavalishin avatar Feb 22 '19 10:02 dzavalishin

https://github.com/chrisroedig/nodemcu_python

dzavalishin avatar Feb 22 '19 10:02 dzavalishin

I've tied to run random_to_udp.py example on my esp8266.

results and actions

  • I've got 'no module named 'struct' ' - replaced with import ustruct as struct.
  • no module named 'Enum' replaced with simple class Enum: pass. just to proceed further.

I've ended up with module hashlib, as some official modules exists in separate repo and could be used by need. but in existing module ,md5 is not implemented only sha224/256/384/512 listed.

mdef avatar Feb 22 '19 10:02 mdef

Thanx. It seems that for the first try we need to strip off digital signature.

dzavalishin avatar Feb 22 '19 11:02 dzavalishin

Some details on above I've stripped off digital signature and ended in function __make_send_socket(): File "engine.py", line 469, in __make_send_socket AttributeError: 'module' object has no attribute 'SO_BROADCAST' esp8266/esp32 Sockets implementation using modlwip. Is anything could be done at mqtt_udp side related to above?

mdef avatar Feb 22 '19 16:02 mdef

Just try to remove corresponding code line (option set). It is possible that underlying IP stack does not need it.

dzavalishin avatar Feb 22 '19 21:02 dzavalishin

I've removed it: Linux port of micropython / python3 reported "OSError: [Errno 13] EACCES" / "PermissionError: [Errno 13] Permission denied." esp8266 acting without an errror by listen.py does not observe any traffic.

mdef avatar Feb 23 '19 00:02 mdef

Can you, please, publish your current code on github for me to take a look? Possibly, best way is to fork this repo, add lang/upython dir and put it there?

dzavalishin avatar Feb 24 '19 10:02 dzavalishin

Here is it: https://github.com/mdef/mqtt_udp/tree/master/lang/micropython/examples to test it, copy required py files to board. compile engine.py (python -m mpy_cross engine.py) into mpy and copy too. run from repl: import random_to_udp.py

mdef avatar Feb 28 '19 22:02 mdef

Thanx. I'm trying but no success yet. "MemoryError: memory allocation failed, allocating 72 bytes" on engine import :(

dzavalishin avatar Mar 09 '19 23:03 dzavalishin

And it is not a mem problem, as I see:

gc.mem_free()
gc.mem_free()
19200
>>> 
import mqttudp
import mqttudp
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "mqttudp/__init__.py", line 3, in <module>
MemoryError: memory allocation failed, allocating 72 bytes
>>> 
gc.mem_free()
gc.mem_free()
18880

dzavalishin avatar Mar 09 '19 23:03 dzavalishin

The memory is a main isssue in your case. To succeed you have to follow my instructions: compile engine.py (python -m mpy_cross engine.py) into engine.mpy and copy it to the board, at folder mqttudp should be engine.mpy but not engine.py

mdef avatar Mar 11 '19 17:03 mdef