I am working on a project where I have got an ESP32 device (Wifi & Bluetooth), which reads data from some sensors, such as temperature and soil moisture (outdoor environment). The data is then sent to a Raspberry PI which is 15 meters far, the PI then sends the data over the Internet. Now, The Raspberry will be plugged into an external stable power source, while the ESP32 will be running by a 3.3 Volt battery, so I need to design well the way the 2 devices communicate to save energy. At first glance I was thinking about simple RESTful API, basically, a flask app running on the PI with the ESP32 to wake up from deep sleep mode every 3 hours to send POST Request to the server. After a bit of research, I then found that my ESP32 supports also BLE (Bluetooth Low Energy), so I was playing a bit with that, and I have been able to exchange some data between the PI and the ESP32. The way I do is:
- The ESP32 advertises itself, writing the value of the sensors in a characteristic
- The PI scans continuously for the ESP32 and when found reads the data
- The ESP32 to deep sleep after every cycle.
Even If I managed to make that work, I think the Flask approach is much cleaner because there is no loop as there is now in the PI. The point is that the ESP32 is almost always deep sleeping so I need to loop (in the PI) to find it and if found read the data. I am reading around that in BLE design the sensor is the server, but I think it might be better if the PI would be the Server advertising itself and the ESP32 to discover it and write the value of the sensor in one characteristic. I still need to fully understand the best pattern here.
Any suggestion from someone which some more experience in the above?