This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
proiecte:environment-monitoring [2018/06/07 15:53] cristian.cocioaba [Resources] |
proiecte:environment-monitoring [2018/06/07 16:37] (current) cristian.cocioaba headers |
||
---|---|---|---|
Line 60: | Line 60: | ||
===== Gathering data ===== | ===== Gathering data ===== | ||
- | === Temperature and humidity === | + | ==== Temperature and humidity |
<code cpp> | <code cpp> | ||
Line 79: | Line 79: | ||
</ | </ | ||
- | === Battery === | + | ==== Battery |
<code cpp> | <code cpp> | ||
typedef float sensor_battery_t; | typedef float sensor_battery_t; | ||
Line 85: | Line 85: | ||
===== Usage === | ===== Usage === | ||
- | === Software serial example on Sparrow === | + | ==== Software serial example on Sparrow |
<code cpp> | <code cpp> | ||
#include < | #include < | ||
Line 120: | Line 120: | ||
</ | </ | ||
+ | |||
+ | |||
+ | ---- | ||
====== ESP8266 solar energy harvesting ====== | ====== ESP8266 solar energy harvesting ====== | ||
Line 126: | Line 129: | ||
===== Nodes power consumption ===== | ===== Nodes power consumption ===== | ||
+ | |||
+ | In a Wireless Sensor Network, nodes are typically equipped with power-constrained batteries, which are often difficult and expensive to be replaced once the nodes are deployed. Therefore, it is a critical consideration on reducing the power consumption in the network design. Energy in WSN nodes is consumed by the CPU, by sensors or actuators, and by radio, with the last consuming the most | ||
+ | |||
+ | Although both protocols operate at 2.4 GHz frequency, 802.15.4 is low-speed and low-rate and ATmega128RFA1 has Ultra Low Power consumption as we can see below. | ||
+ | |||
+ | === ATmega128RFA1 power consumption === | ||
+ | |||
{{: | {{: | ||
+ | |||
+ | === ESP8266 power consumption when radio is on === | ||
+ | |||
+ | In contrast, ESP8266 has more processing power and together with the power required by the bandwidth and data rate of Wi-Fi, it utilizes almost 10 times more energy, as we can see below. | ||
{{: | {{: | ||
+ | |||
+ | The ESP8266 microcontroller provides 3 configurable sleep modes, which can be configured as required by each application: | ||
+ | • Modem-sleep | ||
+ | • Light-sleep | ||
+ | • Deep-sleep | ||
{{: | {{: | ||
===== ESP8266 measured power consumption ===== | ===== ESP8266 measured power consumption ===== | ||
+ | |||
+ | The first step for making a sustainable solution for a WSN was to measure the power consumption of the ESP8266 chip and see if the measurements align with the technical specifications. | ||
+ | |||
+ | For initial measurements, | ||
+ | |||
+ | As we can see in the figure below, the Wi-Fi radio switches on as soon as the ESP wakes up. The boot loader runs for about 0.35 seconds, after which it is deactivated when the “setup” function is run in the program and we force it to be off, thus entering modem-sleep. The next 3 to 10 seconds (in some of our cases) are spent connecting to the Wi-Fi access point and getting an IP. This may vary, depending on the router and DHCP traffic, taking about 3 seconds sometimes. | ||
+ | |||
+ | Next comes about 1.2 seconds of idle time, which, after some research, it is associated with the fact that Espressif SDK persists the connection information to flash memory. | ||
+ | |||
+ | The final power peak is the HTTP request, which varies between 90mA to 200mA. | ||
{{: | {{: | ||
+ | |||
+ | The average current consumption for the ESP when running this test program in different states can be seen in the table below: | ||
{{: | {{: | ||
+ | |||
+ | There were also peeks of power randomly occurring during data transmission, | ||
===== Estimating battery life for an ESP node ===== | ===== Estimating battery life for an ESP node ===== | ||
+ | |||
+ | If the ESP runs in the default mode, it draws a current of approximately 75mA. And when running continuously, | ||
+ | We will further use the same battery capacity as a reference for comparing the power consumption of different modes, i.e. popular LiPo battery of 3800mAh. The above current consumption will drain the reference battery in around **50.6 hours**, i.e. **2 days and 2 hours**, considering an ideal battery. | ||
+ | |||
+ | In our test, the total power consumption for this test, considering the maximum wait time for the Wi-Fi connection of 10 seconds is: | ||
+ | |||
+ | <note tip> | ||
+ | |||
+ | This is a total of 20.4 active seconds per cycle. In a real-life scenario, we will want to extend the deep-sleep period to minimum 5 minute for measuring an environment parameter, like temperature. This will add another 0.25mA * 300s = 75mAs = 0.02mAh to the total calculated above and will extend the cycle total period to 320 seconds, to a total of around **11 cycles per hour**. | ||
+ | |||
+ | And so, the total amount of capacity needed is around **0.305mAh per cycle** and a **total of 3.355mAh**. This consumption will last with the reference 3800 mAh battery for about **47 days**. | ||
+ | |||
+ | This a good improvement over the previous consumption when running continuously, | ||
===== Optimizing power consumption ===== | ===== Optimizing power consumption ===== | ||
+ | |||
+ | The first thing a node should do is to read sensors data and then decide either to send the data or go back to sleep. In this case, we do not want the Wi-Fi radio to be on, without the need to use it. | ||
+ | |||
+ | The code to disable the Wi-Fi is the following: | ||
+ | <code cpp> | ||
+ | WiFi.mode( WIFI_OFF ); | ||
+ | WiFi.forceSleepBegin(); | ||
+ | delay( 1 ); | ||
+ | </ | ||
+ | |||
+ | Then, just before the call to establish the Wi-Fi connection, we turn the radio back on: | ||
+ | <code cpp> | ||
+ | WiFi.forceSleepWake(); | ||
+ | delay( 1 ); | ||
+ | |||
+ | // Bring up the Wi-Fi connection | ||
+ | WiFi.mode( WIFI_STA ); | ||
+ | WiFi.begin( WLAN_SSID, WLAN_PASSWD ); | ||
+ | </ | ||
+ | |||
+ | At boot time, before we can disable the Wi-Fi radio, the ESP chip still turns it on, resulting in a sharp power peak. This default behavior can be changed by setting the WAKE_RF_DISABLED flag in // | ||
+ | |||
+ | <code cpp> | ||
+ | WiFi.disconnect( true ); | ||
+ | delay( 1 ); | ||
+ | ESP.deepSleep( SLEEPTIME, WAKE_RF_DISABLED ); | ||
+ | </ | ||
+ | |||
+ | This saves another 0.007mAh for each cycle, to a **total of 0.077mAh**. | ||
+ | |||
+ | Furthermore, | ||
+ | |||
+ | Also, by setting a -static IP, the DHCP time will be reduced, but this will depend on each network. It most cases, the time was reduced to an average of 6 seconds. This will reduce another 4 seconds from the initial estimation. Which means another **0.083mAh**. | ||
+ | |||
+ | As we can see in the figure below, the first peak was eliminated, and the connection time was reduced. | ||
+ | |||
{{: | {{: | ||
+ | The total power consumption for a cycle is now down to: | ||
+ | |||
+ | <note tip>10s * 17mA + 6s * 75mA + 0.05s * 250mA + 300s * 0.25mA ~= **0.197 mAh per cycle** ⇒ **2.167 mAh**</ | ||
+ | |||
+ | With this, the ESP chip will last with the reference 3800 mAh battery for about **73 days**. | ||
+ | |||
+ | < | ||
+ | We must notice, that although the power peaks are not present in the figure above, during our tests, we observed multiple times that they happen to appear randomly, as seen in Figure 6. and that is the reason that we included them in the above calculation. | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | Also, the 10 seconds of modem-sleep we set in this test which operates at around 17 mA, can be reduced greatly in real-life scenario, when acquiring data from sensor, either digital ones through I2C interface or analog ones. The wait time for calibration depends on each sensor, but, for example, the DHT22 temperature sensor needs an average of 2 seconds to calibrate and be available for data read. This adds, of course, another consumer on the battery, but it is a low-power sensor, operating at 1mA or maximum 1.5 mA. | ||
+ | </ | ||
===== Keeping data after Deep-Sleep ===== | ===== Keeping data after Deep-Sleep ===== | ||
+ | When the ESP chip shuts down the CPU and after it wakes up, it runs the program from the userinit. This means that all the values stored in memory in a processing cycle are not available anymore, which is not very good for sensor value comparation and for message queues. | ||
+ | For resolving this problem, we used the chip flash memory for storing important information before going to sleep. It can store files as text or binary data using the Arduino FS library implementation of ESP SDK. | ||
+ | |||
+ | <code cpp> | ||
+ | void seput() { | ||
+ | Serial.begin(115200); | ||
+ | while (!Serial) continue; | ||
+ | if (!SPIFFS.begin()) | ||
+ | { | ||
+ | Serial.println(" | ||
+ | return; | ||
+ | } | ||
+ | //... | ||
+ | } | ||
+ | |||
+ | bool loadDataRaw(const char* filename, Data& data){ | ||
+ | File dataFile = SPIFFS.open(filename, | ||
+ | if (!dataFile){ | ||
+ | Serial.println(" | ||
+ | return false; | ||
+ | } | ||
+ | |||
+ | size_t size = dataFile.size(); | ||
+ | if (size != sizeof(Data)) { | ||
+ | Serial.print(" | ||
+ | |||
+ | SPIFFS.remove(filename); | ||
+ | Serial.println(" | ||
+ | return false; | ||
+ | } | ||
+ | |||
+ | char* buffer = new char[size]; | ||
+ | dataFile.readBytes(buffer, | ||
+ | |||
+ | memcpy(& | ||
+ | |||
+ | dataFile.close(); | ||
+ | |||
+ | return true; | ||
+ | } | ||
+ | |||
+ | bool saveDataRaw(const char* filename, Data& data) { | ||
+ | File dataFile = SPIFFS.open(filename, | ||
+ | if (!dataFile) { | ||
+ | Serial.println(" | ||
+ | return false; | ||
+ | } | ||
+ | |||
+ | size_t size = sizeof(Data); | ||
+ | uint8_t* buffer = new uint8_t[size]; | ||
+ | memcpy(buffer, | ||
+ | |||
+ | const uint8_t* bufferToWrite = buffer; | ||
+ | size_t sizeWritten = dataFile.write(bufferToWrite, | ||
+ | |||
+ | if(sizeWritten != size) { | ||
+ | Serial.println(" | ||
+ | if(SPIFFS.exists(filename)) { | ||
+ | SPIFFS.remove(filename); | ||
+ | } | ||
+ | return false; | ||
+ | } | ||
+ | |||
+ | // Close the file (File' | ||
+ | dataFile.close(); | ||
+ | |||
+ | return true; | ||
+ | } | ||
+ | |||
+ | |||
+ | </ | ||
===== Solar energy harvesting ===== | ===== Solar energy harvesting ===== | ||
- | {{: | + | We used a solar panel with the dimensions of 160x116x2.5(±0.2) mm. This, in theory, should provide a 2.5W power at 5V voltage when the Solar radiation is the most powerful. |
+ | When testing it, we observed that the solar panel was not giving a steady current and voltage, but instead both varied based on how much Solar radiation strikes the panel and the orientation of the panel. This means that it cannot safely charge the LiPo battery. To overcome this problem, we used the TP4056 | ||
+ | |||
+ | We then measured the battery charger output with both the battery and ESP chip connected and got a maximum of 420 mA at 4.12 V, meaning 1.73 W, and an average of around 300 mA at 4.12 V, meaning 1.236 W between 1pm and 6 pm (see below). | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | This will total to **950mAh**, representing **3.9Wh for 14 hours per day**. This represents an approximation of the power gained and stored in the battery, and at the same time running the ESP. | ||
+ | |||
+ | Considering the previous results of ESP power consumption of 2.167mAh at 3.3 V, representing around 0.0072Wh. This means that it will consume around 0.1Wh in the 14 hours of sunlight and 0.072Wh in the remaining 10 hours of night. | ||
+ | |||
+ | Regarding this, the solar panel can store in the battery approximately 3.8Wh in the time of the sunlight. The remaining 3.8Wh should allow the ESP chip to run for about **22 days without recharging**. | ||
===== Results ===== | ===== Results ===== | ||
- | {{: | + | For testing the theoretical results, we measured the voltage of the VCC voltage from the ESP. It was connected to a 3800mAh LiPo battery, which was charged from the solar panel. |
+ | |||
+ | We present in the figure below tree days of measurement, | ||
+ | |||
+ | {{ : | ||
+ | The voltage increases at the first day sunrise, followed by a discharge at night. After that, we encountered a cloudy weather, followed by another sunny day, which kept the battery fully charged. Our test suggests that the theoretical results are correct and that the ESP can run on battery and harvest solar energy. | ||
===== Resources ===== | ===== Resources ===== | ||
- [[https:// | - [[https:// |