I am trying to figure our why this code https://github.com/divergentti/kanalana ... in/main.py prohibits webepl to run. Code seems to work fine, distance is read, stepper motor is rotated, but if I try to connect to the ESP32 with WebREPL client, connection is never established. If I break main.py by ctrl+c from usb serial repl, then WebREPL start working.
The WebREPL is started in the boot.py https://github.com/divergentti/kanalana ... in/boot.py and is not asynchronous. Is that problem?
Async main and WebREPL
-
- Posts: 67
- Joined: Fri Sep 04, 2020 9:27 am
- Location: Hanko, Finland
- Contact:
-
- Posts: 6
- Joined: Thu Aug 02, 2018 6:22 am
Re: Async main and WebREPL
I am having the same problem. I cannot use WebREPL if I run other code in the While True: loop.
On Github there are multiple people reporting a similair issue with WebREPL.
https://github.com/micropython/micropython/issues/6748
https://github.com/micropython/micropython/issues/2100
https://github.com/micropython/micropython/issues/6604
On Github there are multiple people reporting a similair issue with WebREPL.
https://github.com/micropython/micropython/issues/6748
https://github.com/micropython/micropython/issues/2100
https://github.com/micropython/micropython/issues/6604
-
- Posts: 67
- Joined: Fri Sep 04, 2020 9:27 am
- Location: Hanko, Finland
- Contact:
Re: Async main and WebREPL
I got this working. I had to change distance measurement loop to use await and add some delay:
Now WebREPL seems to work fine. Limiter switch reading, motor rotation and continuous measurement seems to work fine. I will continue mqtt-part etc. Initial code here https://github.com/divergentti/kanalana ... in/main.py
3D printer objects for the ESP32 etc. case here https://www.thingiverse.com/thing:4714795
Code: Select all
async def measure_distance_cm(self):
try:
distance = self.sensor.distance_cm()
if distance > 0:
self.distancecm = distance
await asyncio.sleep_ms(100)
else:
self.distancecm = None
except OSError as ex:
print('ERROR getting distance:', ex)
async def measure_distance_cm_loop(self):
while True:
await self.measure_distance_cm()
await asyncio.sleep_ms(100)
3D printer objects for the ESP32 etc. case here https://www.thingiverse.com/thing:4714795