/* * For SensorShip with ESP8266 and BME280 sensor 1/10/2019 * For data display on mobile app using Blynk: http://www.blynk.cc */ #define BLYNK_PRINT Serial // Comment this out to disable prints and save space #include #include #include // http://www.blynk.cc #include // https://github.com/jfturcot/SimpleTimer #include // https://github.com/adafruit/Adafruit_Sensor #include // https://github.com/adafruit/Adafruit_BME280_Library #include Adafruit_BME280 bme; // The BME280 will be an I2C device, and "bme" is the object. // get Auth Token in the Blynk App in Project Settings (nut icon). char auth[] = "blynk auth code"; //Enter the Auth code which was sent by Blynk // Your WiFi credentials. Set password to "" for open networks. char ssid[] = "WiFi name"; // Enter your WIFI Name char pass[] = "password"; // Enter your WIFI Password float BMEt; float BMEh; float BMEp; float BMEa; float hgInches = 29.83; // Enter the sealevel barometric pressure here (xx.xx inches Hg) #define SEALEVELPRESSURE_HPA (hgInches/0.02952998751) // hPa=(inches Hg)/0.02952998751 SimpleTimer timer; // In the app, Widget's reading frequency should be set to PUSH. void sendSensor() { // read and display data from BME280 sensor BMEt = (((9*(bme.readTemperature())/5)+32)); // read the temperature and convert to F BMEh = (bme.readHumidity()); // read the humidity BMEp = (bme.readPressure() / 100.0F); // read the pressure BMEa = (bme.readAltitude(SEALEVELPRESSURE_HPA)); // compute the altitude if (isnan(BMEh) || isnan(BMEt)) { Serial.println("Failed to read from sensor"); } Serial.print("BME280 temp: "); Serial.print(BMEt); Serial.println(" F"); Serial.print("BME280 humidity: "); Serial.print(BMEh); Serial.println(" %"); Serial.println(); // send sensor data from the virtual pins to the Web Blynk.virtualWrite(V5, BMEh); // V5 is for Humidity Blynk.virtualWrite(V6, BMEt); // V6 is for Temperature Blynk.virtualWrite(V7, BMEp); // V7 is for Pressure Blynk.virtualWrite(V8, BMEa); // V8 is for Elevation } void setup() { Serial.begin(9600); // To see ouput on the serial monitor Blynk.begin(auth, ssid, pass); Wire.begin(); // initialize the I2C interface if (!bme.begin(0x76)) // initialize the BME280 sensor and display the status { // the I2C address of these BME280 sensors is 0x76; Serial.println("No BME280"); } delay(200); // Wait so the sensor can initialize timer.setInterval(5000L, sendSensor); // Setup a function to be called every x/1000 seconds } void loop() { Blynk.run(); // Initiates Blynk timer.run(); // Initiates SimpleTimer }