Page 1 of 1

Async main and WebREPL

Posted: Thu Jan 07, 2021 4:14 pm
by Divergentti
I am trying to figure our why this code ... in/ 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 by ctrl+c from usb serial repl, then WebREPL start working.

The WebREPL is started in the ... in/ and is not asynchronous. Is that problem?

Re: Async main and WebREPL

Posted: Fri Jan 08, 2021 9:08 am
by Lennyz1988
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.

Re: Async main and WebREPL

Posted: Fri Jan 08, 2021 9:35 am
by Divergentti
I got this working. I had to change distance measurement loop to use await and add some delay:

Code: Select all

    async def measure_distance_cm(self):
            distance = self.sensor.distance_cm()
            if distance > 0:
                self.distancecm = distance
                await asyncio.sleep_ms(100)
                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)
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 ... in/

3D printer objects for the ESP32 etc. case here