Hello:
I want to transfer data from a micropython app running on the ESP32. Very simple, running a single ADC channel and sending:
for k in range(0,1000):
#read and add delimiter
txData1 = str(input1.read()) + ‘\n’
conn.send(txData1)
Using this loop, what is the fastest I can expect to receive data in a PC application connected to the ESP32 WiFi? Assume that it sends 2 bytes per read for ADC values from 0 to 4095.
The PC is running much faster so speed isn’t an issue on that side. Also – I’m assuming the ESP32 defaults to the fastest speed of processor execution. (maybe not?)
Thanks,
Gary
Forgot to mention – My board is using a very recent micropython firmware.
I did a bit of testing to figure out if the issue was with A/D conversion or the link.
Using the A/D to convert a sine wave input, I was able to send 10.072K bytes in 5.7 seconds. If we don’t include any bit stuffing or link overhead, that works out to around 15k bits/sec.
Using an integer and sending the same way, it took a bit less time, 4.3 sec, or 19.5k bits/sec. So the conversion doesn’t add much overhead.
So…those numbers do not look at all right. I’ve seen link speeds of 10Mbits for the ESP32. Whoa, something is really broke. Is the processor running slow? The “client” is a Lenovo laptop with a Realtek wireless adapter, about 15ft away.
Any ideas on this?
Hi
If you are using the same home Wifi Router. when here is a lot of traffic,
some of your data being sent can get lost ie. using SKY Netflex Steam slows down most routers
Its best to use a separate wifi router for esp32
Use handshaking in the for loop …
i.e
after
conn.send(txData1) //sending to client
the server then sends back acknowledgement ack
or
just a delay function of 100ms to 500ms
usually A/D have a sample rate, this determines max speed
https://www.youtube.com/watch?v=RlKMJknsNpo
https://www.youtube.com/watch?v=CbacRysML5c
https://www.youtube.com/watch?v=Z-sDHDI6FFY
might help
Hi, thanks for the input.
The ADC loop on it’s own, without doing anything but read the 3 ADC inputs, takes 217ms for 1000 iterations. This seems about right.
So I see the real issue now. It’s the python code that’s slowing it down immensely. The conversion to a string is choking the loop. Sending formatted string bytes is killing the loop execution!
conn.sendall( bytes((txData1 + txData2 + txData3), “utf-8”))
where txDatax is just a formatted string from the ADC
Wow…any idea how to speed this up? How does a wireless link possible achieve data rates anywhere near the megabit range if they send data formatted this way? I checked the board, it’s running at full speed of 240MHz.
I haven’t tried this yet, but you can probably improve speed by moving the slow code to its own C module: https://micropython-dev-docs.readthedocs.io/en/latest/adding-module.html
Hard to say if this is any better than just writing the whole thing in C, though – I guess it depends on the project and whether you’ll use it again or not. Personally, I’ve stuck with C for Arduino stuff, and I move as much logic to the PC as possible, because I much prefer working with Python.