├── README.md ├── Licence.txt └── ESP32_Thingspeak_Deep_Sleep_BME280.ino /README.md: -------------------------------------------------------------------------------- 1 | # ESP32-Deep-Sleep-Ultra-Low-Power-Trial 2 | -------------------------------------------------------------------------------- /Licence.txt: -------------------------------------------------------------------------------- 1 | This software, the ideas and concepts is Copyright (c) David Bird 2014 and beyond. 2 | 3 | All rights to this software are reserved. 4 | 5 | It is prohibited to redistribute or reproduce of any part or all of the software contents in any form other than the following: 6 | 7 | 1. You may print or download to a local hard disk extracts for your personal and non-commercial use only. 8 | 9 | 2. You may copy the content to individual third parties for their personal use, but only if you acknowledge the author David Bird as the source of the material. 10 | 11 | 3. You may not, except with my express written permission, distribute or commercially exploit the content. 12 | 13 | 4. You may not transmit it or store it in any other website or other form of electronic retrieval system for commercial purposes. 14 | 15 | 5. You MUST include all of this copyright and permission notice ('as annotated') and this shall be included in all copies or substantial portions of the software and where the software use is visible to an end-user. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS" FOR PRIVATE USE ONLY, IT IS NOT FOR COMMERCIAL USE IN WHOLE OR PART OR CONCEPT. 18 | 19 | FOR PERSONAL USE IT IS SUPPLIED WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | 21 | IN NO EVENT SHALL THE AUTHOR OR COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /ESP32_Thingspeak_Deep_Sleep_BME280.ino: -------------------------------------------------------------------------------- 1 | /* ESP32 takes a large current pulse to get started, so won't work with a USB programmer PSU, need a direct power feed at 3.3V 2 | ESP32 in Deep Sleep takes 0.0056mA or 5.6uA, giving a typical battery life with a 2600mAh battery of : 220 days at 15-min update intervals 3 | Typical battery capacities: 4 | AAA 1200 (Alkaline) or 800–1000 (NiMH) 5 | AA 2700 (alkaline) or 3000 (Lithium-Rechargeable) or 1700–2900 (NiMH) 6 | C 8000 (alkaline) or 4500–6000 (NiMH) 7 | D 12000 (alkaline) or 2200–12000 (NiMH) or 19000 (Lithium-Primary) 3.6V 8 | 9V Transistor 565 (alkaline) or 175–300 (NiMH) 9 | 6V Lantern 26000 (alkaline) 10 | CR2032 240 (Lithium-Primary) 3.6V 11 | CR2016 90 (Lithium-Primary) 3.6V 12 | 4 Farad Cap 1 (loses 1 volt in 1 hour at 1mA) 13 | 14 | */ 15 | #include 16 | #include 17 | #include 18 | WiFiClient client; // wifi client object 19 | 20 | const char *ssid = "yourSSID"; 21 | const char *password = "yourPASSWORD"; 22 | 23 | char ThingSpeakAddress[] = "api.thingspeak.com"; // Thingspeak address 24 | String api_key = "yourTHINGSPEAK_API_KEY"; // Thingspeak API WRITE Key for your channel 25 | const int UpdateInterval = 10 * 60 * 1000000; // e.g. 15 * 60 * 1000000; for a 15-Min update interval (15-mins x 60-secs * 1000000uS) 26 | #define ADC_input_pin 36 // also known as SVP ADC-0 or SVN Pin-39 27 | #define pressure_offset 3.9 // Compensates for this location being 40M asl 28 | Adafruit_BME280 bme; 29 | 30 | void setup() { 31 | Serial.begin(115200); 32 | WiFi.begin(ssid, password); 33 | Serial.println("Start WiFi"); 34 | while (WiFi.status() != WL_CONNECTED ) {Serial.print("."); delay(500); } 35 | Wire.begin(17,16); // (sda,scl) 36 | if (!bme.begin()) { 37 | Serial.println("Could not find a sensor, check wiring!"); 38 | } 39 | else 40 | { 41 | Serial.println("Found a sensor continuing"); 42 | while (isnan(bme.readPressure())) {};//Serial.println(bme.readPressure());} 43 | } 44 | 45 | float temperature = bme.readTemperature(); // 3 example variables, ideally supplied by a sensor, see my examples for the BMP180, BME280 or DS18B20 46 | float humidity = bme.readHumidity(); 47 | float pressure = bme.readPressure() / 100.0F + pressure_offset; // Result is in hPA 48 | float VBat = float(analogRead(ADC_input_pin)) / 4096.0f * 3.3; // Using ADC Channel-0 49 | UpdateThingSpeak("field1="+String(temperature)+"&field2="+String(humidity)+"&field3="+String(pressure)+"&field4="+String(VBat)); //Send the data as text 50 | esp_deep_sleep_enable_timer_wakeup(UpdateInterval); 51 | BME280_Sleep(); 52 | Serial.println("Going to sleep now..."); 53 | esp_deep_sleep_start(); 54 | } 55 | 56 | void loop() { 57 | //Do nothing as it will never get here! 58 | } 59 | 60 | void UpdateThingSpeak(String DataForUpload) { 61 | WiFiClient client; 62 | if (!client.connect(ThingSpeakAddress, 80)) { 63 | Serial.println("connection failed"); 64 | return; 65 | } 66 | else 67 | { 68 | Serial.println(DataForUpload); 69 | client.print("POST /update HTTP/1.1\n"); 70 | client.print("Host: api.thingspeak.com\n"); 71 | client.print("Connection: close\n"); 72 | client.print("X-THINGSPEAKAPIKEY: " + api_key + "\n"); 73 | client.print("Content-Type: application/x-www-form-urlencoded\n"); 74 | client.print("Content-Length: "); 75 | client.print(DataForUpload.length()); 76 | client.print("\n\n"); 77 | client.print(DataForUpload); 78 | } 79 | client.stop(); 80 | } 81 | 82 | void BME280_Sleep() { 83 | //Serial.println("BME280 to Sleep mode"); 84 | Wire.beginTransmission(0x76); // Check your I2C address, they vary, could be 0x77 85 | Wire.write((uint8_t)BME280_REGISTER_CONTROL); 86 | Wire.write((uint8_t)0b00); 87 | Wire.endTransmission(); 88 | } 89 | 90 | --------------------------------------------------------------------------------