Things used in this project

Hardware components:
DFRobot Gravity: I2C BME280 Environmental Sensor (Temperature, Humidity, Barometer)
×1
DFRobot 3.7V Polymer Lithium Ion Battery - 1000mAh
×1
DFRobot Solar Lipo Charger (3.7V)
×1
ESP8266
×1
6V 1W Solar Panel
×1
Perfboard
×1
Female Header
×1
Enclosure
×1
Software apps and online services:
Cayenne logo hi
myDevices Cayenne
Ide web
Arduino IDE
Hand tools and fabrication machines:
09507 01
Soldering iron (generic)

Schematics

System Schematic
Ws iot esp8266 sch v1 0 xodtfqxy51
Components mounting plate
Ws iot esp8266 board v1 0 b7vo2swn9f

Code

Code_V1.0.ino.inoArduino
//#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>

// Library
#include "ESP8266WiFi.h"

#define uS_TO_m_FACTOR 60000000   // Conversion factor for micro seconds to minutes
// Time to sleep (in minutes):
const int sleepTimeM = 15;


// WiFi network info.
char ssid[] = "YOUR_SSID";
char wifiPassword[] = "YOUR_WIFI_PASSWORD";

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "YOUR_USERNAME";
char password[] = "YOUR_PASSWORD";
char clientID[] = "YOUR_CLIENT_ID";



//Library for BME280 Sensor
#include <DFRobot_BME280.h>

#define SEA_LEVEL_PRESSURE  1013.25f

DFRobot_BME280 bme; //I2C

float temp, pressure, hum, alt; //Variables for the BME280 Sensor

ADC_MODE(ADC_VCC);

void setup() {


  Serial.begin(115200);

  //Connect with Wifi
  Cayenne.begin(username, password, clientID, ssid, wifiPassword);



  //Start I2C
  // I2c default address is 0x77, if the need to change please modify bme.begin(Addr)
  if (!bme.begin()) {
    Serial.println("No sensor device found, check line or address!");
    while (1);
  }

  delay(100);

  Get_Values(); //Get values from the BME280



  //Check Internal Voltage
  float vdd = ESP.getVcc() / 1000.0;
  Serial.println (vdd);


  Cayenne.loop();

  //Send data to Cayenne
  Cayenne.virtualWrite(0, temp); //Send temperature
  Cayenne.virtualWrite(1, pressure); // Send pressure
  Cayenne.virtualWrite(2, hum); // Send humidaty
  Cayenne.virtualWrite(3, vdd); //Send internal voltage

  //Go to sleep
  ESP.deepSleep(sleepTimeM * uS_TO_m_FACTOR, WAKE_RF_DEFAULT); // Sleep for 15 Minutes


}



void Get_Values()
{

  temp = bme.temperatureValue();
  delay(100);

  pressure = bme.pressureValue() / 100.0F;
  hum = bme.humidityValue();
  alt = bme.altitudeValue(SEA_LEVEL_PRESSURE);

  delay(100);

  Serial.println("Collect data");

  Serial.print("Temperature :");
  Serial.print(temp);
  Serial.println(" C");

  Serial.print("Pressure:");
  Serial.print(pressure);
  Serial.println(" hPa");

  Serial.print("Humidity :");
  Serial.print(hum);
  Serial.println(" %");

  Serial.print("Approx. Altitude:");
  Serial.print(alt);
  Serial.println(" m");

  Serial.println("------END------");

  //Place BME280 into sleep mode
  BME280_Sleep();

}


void BME280_Sleep()
{

  //Serial.println("BME280 to Sleep mode");

  Wire.beginTransmission(0x77);
  Wire.write((uint8_t)BME280_REGISTER_CONTROL);
  Wire.write((uint8_t)0b00);
  Wire.endTransmission();
}

//Default function for processing actuator commands from the Cayenne Dashboard.
//You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
CAYENNE_IN_DEFAULT()
{
  CAYENNE_LOG("CAYENNE_IN_DEFAULT(%u) - %s, %s", request.channel, getValue.getId(), getValue.asString());
  //Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError("Error message");
}


void loop() {


}

Credits

Me
Hugo Gomes
1 project • 50 followers
http://www.hugogomes.net
Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaBlog