groger57 wrote: ↑Wed Oct 02, 2019 5:46 am
so to send an integer value greater than 255 requires....what? Do I need to resort to old-fashioned bit-twiddling? there's no built in methods to do this?
If I cannot append to an array, then how are the bytes sent over the socket? I could get a book and do some reading, but with the almost non-existent info on this subject I have found on the web, I'd be worried most books will not have much either.
If I were to pack a struct, for example - how would this be converted to bytes that I could use "conn.send()" ?
sorry, lots of things new to me here - thanks for helping me find my way.
Hi, I've been working on this topic a while now, not too much, but enough to say that it's a non-trivial task and for "the almost non-existent info on this subject I have found on the web", I can relate. So I will share my insights into this:
- If I've understood right, what you are trying to do is sampling (from ADCs) + streaming this data (through sockets, TCP I guess)
I would say that there are three different methods:
1) Sample the ADCs, pack into bytes (using struct) and immediately send this data through the socket: This is the slowest approach, because sending the data through the socket does take time, so if you do this after each ADC sampling, it will drop the data transfer rate.
2) Sample the ADCs, store the data into a "buffer" array (see
http://docs.micropython.org/en/latest/l ... array.html) with a length between 20 or 32 (it is what I've found that works the best) and when the buffer is full, send it through the socket. Then start again to fill the buffer and so on. This is the fastest approach if you want to do sampling + streaming at the same time, and the fastest I've got so far are 300 kbit/s ~ 37 KB/s ~ at 1 KHz sampling rate (but just 1 variable) for 3 variables I've got at 860 Hz sampling rate ~ 30 KB/s ~ 240 Kbits/s .
*I would recommend to see the sample code from here
https://github.com/robert-hh/ads1x15, for the sampling method, then this
https://github.com/Carglglz/upydev/blob ... d#ads_init, and this
https://github.com/Carglglz/upydev/blob ... nit_ADS.py
3) Sample the ADCs, store the data into a file (plain text or json), and when finished read/load the file in chunks ( of 2000 bytes size or so) and send the chunk through the socket. It is not sampling + streaming at the same time, but the data transfer rate is the highest. (I've got between 80-100 KB/s) but I guess it could be faster if the chunks where larger. see
https://github.com/Carglglz/upydev/blob ... on.md#sync and
https://github.com/Carglglz/upydev/blob ... nc_tool.py
** All the test where done with the esp32 and my laptop connected to the same AP (home wifi). The setup of esp32 being the AP and connect the laptop to this AP, in some initial test that I've done the speed drops by 20-25 % but further test needs to be done I guess...
***[made a typo with units, 860 Hz not KHz (already edited)]