so my battery powered BME280 temp/humidity/pressure + BH1750 light sensor combo ESP8266 node is doing well with deep sleep, running off 2 x 18650 and LM2596 regulator.
it does thingspeak updates as well
my apparently very simple deep sleep code is:
ESP.deepSleep(300000000);
delay(10);
my entire code for anyone interested or anyone who wants to provide advice/criticism on improving it is:
/*
BME280 Test.ino
This code shows how to record data from the BME280 environmental sensor.
This file is an example file, part of the Arduino BME280 library.
Copyright (C) 2016 Tyler Glenn
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Written: Dec 30 2015.
Last Updated: Jan 1 2016.
*/
//#define BLYNK_PRINT Serial //this is the debugging for Blynk
//#define BLYNK_DEBUG // Optional, this enables 'full' debugging detailed prints
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <BME280.h>
#include <BH1750FVI.h>
#include <Wire.h>
WiFiClient client;
BH1750FVI LightSensor;
BME280 bme; // Default : forced mode, standby time = 1000 ms
SimpleTimer timer;
ADC_MODE(ADC_VCC);
bool debug = 1; //turns serial prints on (1) or off (0)
int vcc = ESP.getVcc(); //readvdd33();
double cellarDewPoint;
float medianHum;
float medianTemp;
float node3DewPoint;
const char* ssid = "xxx";
const char* password = "xxx";
const char* serverThingspeak = "api.thingspeak.com"; //this is the Thingspeak address
String apiKeyThingspeak = "xxx"; // Channel 78844
char authBlynk[] = "xxx"; //insert token generated by Blynk
bool metric = true;
void printBME280Data()
{
float temp, hum, pres;
long rssi = WiFi.RSSI();
uint8_t pressureUnit(1); // unit: B000 = Pa, B001 = hPa, B010 = Hg, B011 = atm, B100 = bar, B101 = torr, B110 = N/m^2, B111 = psi
bme.ReadData(pres, temp, hum, metric, pressureUnit); // Parameters: (float& pressure, float& temp, float& humidity, bool celsius = false, uint8_t pressureUnit = 0x0)
node3DewPoint = dewPointAccurate(temp, hum);
uint16_t lux = LightSensor.GetLightIntensity();// Get Lux value
if (debug == 1) {
Serial.print("Temp: ");
Serial.print(temp);
Serial.println("'C");
Serial.print("Humidity: ");
Serial.print(hum);
Serial.println("% RH");
Serial.print("Pressure: ");
Serial.print(pres);
Serial.println(" hPa");
Serial.print("Dew Point: ");
Serial.print(node3DewPoint);
Serial.println(" 'C");
Serial.print("Light: ");
Serial.print(lux);
Serial.println(" lux");
Serial.println("-------------------------------------------");
}
Blynk.virtualWrite(V11, temp); // this sends the reading to the Blynk virtual pin
Blynk.virtualWrite(V9, hum); // this sends the reading to the Blynk virtual pin
Blynk.virtualWrite(V2, pres); // this sends the reading to the Blynk virtual pin
Blynk.virtualWrite(V8, node3DewPoint); // this sends the reading to the Blynk virtual pin
Blynk.virtualWrite(V19, vcc); // this sends the reading to the Blynk virtual pin
Blynk.virtualWrite(V18, rssi); // this sends the reading to the Blynk virtual pin
Blynk.virtualWrite(V4, lux); // this sends the reading to the Blynk virtual pin
if (client.connect(serverThingspeak, 80))
{
String postStr = apiKeyThingspeak;
postStr += "&field1=";
postStr += String(temp);
postStr += "&field2=";
postStr += String(hum);
postStr += "&field3=";
postStr += String(pres);
postStr += "\r\n\r\n";
postStr += "&field4=";
postStr += String(rssi);
postStr += "\r\n\r\n";
postStr += "&field5=";
postStr += String(vcc);
postStr += "\r\n\r\n";
postStr += "&field6=";
postStr += String(lux);
postStr += "\r\n\r\n";
postStr += "&field7=";
postStr += String(node3DewPoint);
postStr += "\r\n\r\n";
client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: " + apiKeyThingspeak + "\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);
}
if (debug == 1)
{
Serial.println(F("just thingspoke"));
}
Blynk.tweet((String("NODE_03: temperature: ")) + temp + (" 'C, humidity: ") + hum + ("'C, dew point: ") + node3DewPoint + ("'C, volts: ") + vcc + ("mV, WiFi: ") + rssi + ("dBm, light: ") + lux +("lx."));
if (debug == 1)
{
Serial.println(F("just tweeted"));
}
//delay(1000);
ESP.deepSleep(300000000);
delay(10);
}
void setup()
{
{
Serial.begin(115200);
Serial.print(F("File name: "));
if (debug == 1) {
Serial.println(F(""));
Serial.println(F("NODE03 - TPL Bug prototype BATTERY POWER - with Thingspeak & Blynk & Running Median & Twitter & Deep Sleep"));
Serial.print(F("File name: "));
Serial.println(__FILE__);
Serial.println(F(""));
Serial.print(F("ESP voltage: "));
Serial.print(vcc);
Serial.println(F("mV"));
Serial.println(F(""));
}
WiFi.begin(ssid, password);
Serial.println(F("Where's some WiFi??"));
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(F("."));
}
Serial.println(F(""));
Serial.println(F("Found some WiFi!"));
long rssi = WiFi.RSSI();
Serial.print(F("WiFi signal strength (RSSI): "));
Serial.print(rssi);
Serial.println(F(" dBm"));
Serial.println("");
Serial.println(F("------------"));
Blynk.begin(authBlynk, ssid, password);
Serial.println(F("Where's Blynk??"));
while (!Blynk.connect()) {
delay(500);
Serial.print(F("."));
}
Serial.println(F("Blynk started! "));
Serial.println(F("------------"));
//
// bool isFirstConnect = true; // Keep this flag not to re-sync on every reconnection
//
// BLYNK_CONNECTED(); // This function will run every time Blynk connection is established
// {
// if (isFirstConnect) {
// Blynk.syncAll(); // where is the sync.All function supposed to go?
// isFirstConnect = false;
// }
// }
timer.setInterval(500L, printBME280Data);
LightSensor.begin();
Wire.begin();
LightSensor.SetAddress(Device_Address_L);//'L' = Address 0x5C ???
LightSensor.SetMode(Continuous_H_resolution_Mode);
while (!Serial)
{
} // Wait
while (!bme.begin())
{
Serial.println("Could not find BME280 sensor!");
delay(1000);
}
}
}
void loop()
{
Blynk.run(); // Initiates Blynk
timer.run(); // Initiates SimpleTimer
}
/*-----( Declare User-written Functions )-----*/
// dewPoint function NOAA
// reference (1) : http://wahiduddin.net/calc/density_algorithms.htm
// reference (2) : http://www.colorado.edu/geography/weather_station/Geog_site/about.htm
//
double dewPointAccurate (double celsius, double humidity)
{
// (1) Saturation Vapor Pressure = ESGG(T)
double RATIO = 373.15 / (273.15 + celsius);
double RHS = -7.90298 * (RATIO - 1);
RHS += 5.02808 * log10(RATIO);
RHS += -1.3816e-7 * (pow(10, (11.344 * (1 - 1 / RATIO ))) - 1) ;
RHS += 8.1328e-3 * (pow(10, (-3.49149 * (RATIO - 1))) - 1) ;
RHS += log10(1013.124); // NB = 1013 = absolute air pressure from BME280 sensor!!!!???????????????
// factor -3 is to adjust units - Vapor Pressure SVP * humidity
double VP = pow(10, RHS - 3) * humidity;
// (2) DEWPOINT = F(Vapor Pressure)
double T = log(VP / 0.61078); // temp var
return (241.88 * T) / (17.558 - T);
}
/* ==== END Functions ==== */