fizista / micropython-umqtt.simple2

MIT License
74 stars 35 forks source link

ussl wrapped socket has no settimeout method #2

Closed dir-ableton closed 4 years ago

dir-ableton commented 4 years ago

Trying to use MQTT with ssl=True results in

>>> 
MPY: soft reboot
Traceback (most recent call last):
  File "main.py", line 97, in <module>
  File "main.py", line 92, in main
  File "/lib/umqtt/robust2.py", line 55, in publish
  File "/lib/umqtt/simple2.py", line 72, in publish
  File "/lib/umqtt/simple2.py", line 43, in _sock_timeout
AttributeError: 'ussl' object has no attribute 'settimeout'
MicroPython v1.12-464-gcae77daf0 on 2020-05-24; ESP32 module with ESP32
Type "help()" for more information.
fizista commented 4 years ago

There is indeed a problem here. We need to try to rewrite the code using uselect.

An example in micropython documentation: https://docs.micropython.org/en/latest/library/usocket.html#usocket.socket.settimeout

dir-ableton commented 4 years ago

Ok. I'm willing to take this on but have one question that I couldn't solve yesterday, maybe you have some insight here. I'm well versed with standard Python, pip and setuptools. But I don't know much about upip. Is there a way to do an install based on a local repository? Or how do you develop the package? I normally use ampy to send files over, but I'm not aware of it being able to copy files into a deeper file hierarchy, as needed here. Or am I missing something?

fizista commented 4 years ago

I don't use upip on devices. I use upip locally on my computer, preparing files for upload. I use "ampy", but the modified version (https://github.com/fizista/ampy/tree/rsync). When the device is working, I prefer to upload files via webrepl(https://github.com/fizista/webrepl), and it is not always stable, but it probably works better than ampy. And I usually use mpy-build, which converts text files(.py) into "binary" (.mpy).

Webrepl from the console. Not the web version!

fizista commented 4 years ago

Theoretically, the problem should be fixed. However, I have not tested whether SSL connections work.

dir-ableton commented 4 years ago

I'll have a look ASAP, other obligations might mean tomorrow, latest friday

dir-ableton commented 4 years ago

Ok, I found the time to reproduce - and I can confirm this works for me with SSL! Awesome!

fizista commented 4 years ago

I uploaded a new version, I still had to rewrite the code to make it compatible with uselect.poller.

I hope I didn't corrupt what worked for you.

If something doesn't work, reopen the issue.