So you're a Noob? Post your questions here until you graduate! Don't be shy.
User avatar
By bcosta
#69585 Hi all,

I am working on something where I want to continually sample data from some sensors attached to the ESP8266 and periodically upload that data using a HTTP POST.

All examples I have seen (Arduino samples so far) basically stop sampling the data while they connect WiFi and upload the data, which is not suitable for my use case as I will lose important information.

Is it possible to have the data continually sampled from sensors, and upload happen "simulataneously" and do you have any links to examples doing this?

I was considering using ISR to do the sensor data sampling while the main routine basically has a loop of sleep, gather data, connect wifi, do POST.

I was wondering if this is possible with arduino, if not I am also considering using the Espressif RTOS SDK instead which is probably much more suitable anyway as my sensor sampling realistically should have time limits to be accurate.

What issues might I face?

For example I read that using the ADC during WiFi TX will give erroneous results. Would this also happen if using an external ADC like ADS1115 or with other GPIO inputs?

Thanks,
Brendon.
User avatar
By philbowles
#69658 "What issues might I face?" - First the issue of asynchronous / synchronous programming - ESP runs WiFi code in the background and if your code delays or takes to long, it will cause a Watchdog timer (WDT) reset.

Structure your code so that there are no overlapping synchronous / asynchronous functions. Using an ISR is asking for trouble in that regard. If you are only sending periodically, poll the sensor in the main loop and forget the complications of interrupts.

Also...the examples you describe seem like bad style to me...why repeatedly connect and disconnect the Wifi? (this in itself is an area where you will get timing problems if you are not careful...Do you mean "Internet" rather than "WiFi" ?) I.e. do you mean you want to periodically upload some sensor data to an external site?

If so, then connect the Wifi, leave it alone and periodically issue the HTTP POST/GET/whatever to send your data.

Unless you have a battery powered solution, why bother with disconnect / reconnect?..then you will also need sleep/wake functionality...a whole other discussion

Are you saying that you are worried about losing sensor data during the actual transmission of the HTTP POST? If so, you need the Async versions of the libraries, e.g. ESPAsyncTCP or other libraries based on them.

Then (and only then unless you want a world of pain) you can do { sample, fire+forget HTTP, yield } while(1)...conceptually of course, I can't be bothered to format proper code!

Hope this helps!
User avatar
By bcosta
#69717
philbowles wrote:ESP runs WiFi code in the background and if your code delays or takes to long, it will cause a Watchdog timer (WDT) reset.

...

Are you saying that you are worried about losing sensor data during the actual transmission of the HTTP POST? If so, you need the Async versions of the libraries, e.g. ESPAsyncTCP or other libraries based on them.


Yes that is what I was worried about. Thanks for the pointer. So it sounds like I can use ESPAsyncTCP to do async POST in the background while my main loop is continually reading the sensors producing data ready for the next POST.

Thanks.
User avatar
By philbowles
#69924
bcosta wrote:So it sounds like I can use ESPAsyncTCP to do async POST in the background while my main loop is continually reading the sensors producing data ready for the next POST.


That's the general idea, yes - as long as you structure your code correctly, it shouldn't be a problem. Best of luck!