ez mancoJake JohnsTyler Watkins
Published

Trusty Temperature Tool

The weathermen are shoddy at best, let's put the power in our hands. Accurate live data can give you the results the meteorologists don't.

BeginnerFull instructions provided5 hours366
Trusty Temperature Tool

Things used in this project

Hardware components

Photon
Particle Photon
×3
Resistor 221 ohm
Resistor 221 ohm
×1
LED (generic)
LED (generic)
×2
SparkFun Atmospheric Sensor Breakout - BME280
SparkFun Atmospheric Sensor Breakout - BME280
×2

Story

Read more

Schematics

Temperature sensing circuits

Signal Strength go no go readout

Code

BME weather photon 1

C/C++
This is the first data set, using a rudimentary code that publishes directly to the console as well as thingspeak
// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_BMP280.h>

// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_BME280.h>


/***************************************************************************
  This is a library for the BME280 humidity, temperature & pressure sensor

  Designed specifically to work with the Adafruit BME280 Breakout
  ----> http://www.adafruit.com/products/2650

  These sensors use I2C or SPI to communicate, 2 or 4 pins are required
  to interface.

  Adafruit invests time and resources providing this open source code,
  please support Adafruit andopen-source hardware by purchasing products
  from Adafruit!

  Written by Limor Fried & Kevin Townsend for Adafruit Industries.
  BSD license, all text above must be included in any redistribution

  This file was modified by Markus Haack (https://github.com/mhaack)
  in order to work with Particle Photon & Core.
 ***************************************************************************/



#define BME_SCK D4
#define BME_MISO D3
#define BME_MOSI D2
#define BME_CS D5

#define SEALEVELPRESSURE_HPA (1013.25)


Adafruit_BME280 bme; // I2C

Timer timer(10000, checkEnvironment); // call this function every 10 seconds
Timer timer2(10000, serialDebug); // call this function every 10 seconds
Timer timer3(15000, updateThingspeak);

//global Vars

int caladdress = 0;
double bme280temp = 0;
double bme280baro = 0;
double bme280humidity = 0;
double bme280altitude = 0;
float analog1 = 0;
int connect = D7;
int count = 0;
int connectlog = 0;
const String key = "your key here"; //thingspeak write key

//ApplicationWatchdog wd(5000, System.reset); //5 second application watchdog
SYSTEM_MODE(SEMI_AUTOMATIC);



ApplicationWatchdog wd(60000, System.reset);


void setup() {


  pinMode(D7, OUTPUT);
  Serial.begin(230400);
  Serial.println(F("BME280 test"));

  
  
  Particle.publish("DEBUG", "starting...");

  if (bme.begin(0x76)) {  //0x76 is the i2c address of the sensor
    Particle.publish("DEBUG", "starting the environment timer...");
    timer.start(); //initialize timer
    timer2.start();//initialize timer2
    timer3.start();//initialize timer2
  }
  else {
    Particle.publish("WARN", "Could not find a valid BMP280 sensor, check wiring!");
  }

  Particle.publish("DEBUG", "started!");
 
  Particle.connect(); 
  Particle.variable("bme280temp", bme280temp);
  Particle.variable("bme280hum", bme280humidity);
  Particle.variable("bme280bar", bme280baro);
  Particle.variable("bme280alt", bme280altitude);
  
  }
 

void loop() {
    wd.checkin(); //watchdog checkin
    
    if (System.buttonPushed() > 2000) { //trigger a wifi disconnect if you hold for over 2 seconds.
        //RGB.color(255, 255, 0); // YELLOW
        if (Particle.connected() == false) {  //if not connected, delay, 5000ms before attempting reconnect.  without delay was causing gps to fail.
            Serial.println("Connecting to wifi");
		    Particle.connect();
		    delay(1000);
        } else {
            //Particle.disconnect();
            WiFi.off();
            delay(1000);
        }   
    }
}



void serialDebug() {
    Serial.print("Temperature = ");
    Serial.print(bme.readTemperature());
    Serial.println(" *C");

    Serial.print("Pressure = ");

    Serial.print(bme.readPressure() / 100.0F);
    Serial.println(" hPa");

    Serial.print("Approx. Altitude = ");
    Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
    Serial.println(" m");

    Serial.print("Humidity = ");
    Serial.print(bme.readHumidity());
    Serial.println(" %");

    Serial.println();
}

void checkEnvironment() {

  Particle.publish("RSSI", String(WiFi.RSSI()));

  bme280temp = cToF(bme.readTemperature());
  bme280baro = pToHg(bme.readPressure());
  bme280altitude = bme.readAltitude(SEALEVELPRESSURE_HPA);
  bme280humidity = bme.readHumidity();

  Particle.subscribe("goodsignal", connection, "your other device id here");

    

}

float cToF(float c) {
  return c * 9/5 + 32;
}

float pToHg(float p) {
  return p/3389.39;
}
void connection(const char *event, const char *data){
    connectlog = atof(data);
    if (connectlog == 1){
        digitalWrite(connect, HIGH);
        delay(1000);
        digitalWrite(connect, LOW);
        delay(1000);
        digitalWrite(connect, HIGH);
        delay(1000);
        digitalWrite(connect, LOW);
        delay(1000);
        digitalWrite(connect, HIGH);
        delay(1000);
        digitalWrite(connect, LOW);
        delay(1000);
    }
    else{
        digitalWrite(connect, LOW);
    }
    
   delay(5000);
}
/*******************************************************************************
 * Function Name  : updateThingspeak
 * Description    : sends variables to ts
 * Input          : doorstatus global variables
 * Output         : sends data to ts
 * Return         : void
                    
 *******************************************************************************/
bool updateThingspeak() 
{
    //delay (2000);
    count++;
    Serial.print("Updating Thingspeak:");
    Serial.print(count);
    
    int rssival = WiFi.RSSI();
    //sprintf(publishString,"%d",rssival);
    //bool success = Particle.publish("RSSI",publishString);
    
    //sprintf(publishString, "%1.4f", checkbattery());

      bool success = Particle.publish("thingSpeakWrite_All", +
     "{ \"1\": \"" + String(rssival) + "\"," +
       "\"2\": \"" + String(bme280temp) + "\"," +
       "\"3\": \"" + String(bme280humidity) + "\"," +
       "\"4\": \"" + String(bme280baro) + "\"," +
       "\"5\": \"" + String(bme280altitude) + "\"," +
       "\"k\": \"" + key + "\" }", 60, PRIVATE);
    return success; //if sent, then turn of the send flag, otherwise let it try again.
    
}
  

photon 2 Temp with Wifi signal strength average

C/C++
#include <Adafruit_BME280.h>


#define BME_SCK D4
#define BME_MISO D3
#define BME_MOSI D2
#define BME_CS D5

#define SEALEVELPRESSURE_HPA (1013.25)



Adafruit_BME280 bme; 

Timer timer(10000, checkEnvironment); // call this function every 10 seconds
Timer timer2(10000, serialDebug); // call this function every 10 seconds
Timer timer3(15000, updateThingspeak);

//global Variables

int caladdress = 0;
double bme280temp = 0;
double bme280baro = 0;
double bme280humidity = 0;
double bme280altitude = 0;
double analog1 = 0;
double Signal = 0;
double sig1 = 0;
int count = 0;
int connect = D7;
int connectlog = 0;

const String key = "your key here"; //thingspeak write key

//ApplicationWatchdog wd(5000, System.reset); //5 second application watchdog
SYSTEM_MODE(SEMI_AUTOMATIC);



ApplicationWatchdog wd(60000, System.reset);


void setup() {

  pinMode(D7, OUTPUT);
  Serial.begin(230400);
  Serial.println(F("BME280 test"));
 
  Particle.publish("DEBUG", "starting...");

  if (bme.begin(0x76)) {  //0x76 is the i2c address of the sensor
    Particle.publish("DEBUG", "starting the environment timer...");
    timer.start(); //initialize timer
    timer2.start();//initialize timer2
    timer3.start();//initialize timer2
  }
  else {
    Particle.publish("WARN", "Could not find a valid BMP280 sensor, check wiring!");
  }

  Particle.publish("DEBUG", "started!");
 
  Particle.connect(); 
  Particle.variable("bme280temp", bme280temp);
  Particle.variable("bme280hum", bme280humidity);
  Particle.variable("bme280bar", bme280baro);
  Particle.variable("bme280alt", bme280altitude);
  Particle.variable("analog1", analog1);
  
  }
 

void loop() {

    wd.checkin(); //watchdog checkin
    
    if (System.buttonPushed() > 2000) { //trigger a wifi disconnect if you hold for over 2 seconds.
        //RGB.color(255, 255, 0); // YELLOW
        if (Particle.connected() == false) {  //if not connected, delay, 5000ms before attempting reconnect.  without delay was causing gps to fail.
            Serial.println("Connecting to wifi");
		    Particle.connect();
		    delay(1000);
        } else {
            //Particle.disconnect();
            WiFi.off();
            delay(1000);
        }   
    }
}



void serialDebug() {
    Serial.print("Temperature = ");
    Serial.print(bme.readTemperature());
    Serial.println(" *C");

    Serial.print("Pressure = ");

    Serial.print(bme.readPressure() / 100.0F);
    Serial.println(" hPa");

    Serial.print("Approx. Altitude = ");
    Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
    Serial.println(" m");

    Serial.print("Humidity = ");
    Serial.print(bme.readHumidity());
    Serial.println(" %");

    Serial.println();
}

void checkEnvironment() {

  Particle.publish("RSSI", String(WiFi.RSSI()));
 
  bme280temp = cToF(bme.readTemperature());
  bme280baro = pToHg(bme.readPressure());
  bme280altitude = bme.readAltitude(SEALEVELPRESSURE_HPA);
  bme280humidity = bme.readHumidity();


   Particle.subscribe("RSSI", SignalStrength, "your device id");
   Particle.subscribe("goodsignal", connection, "your device id");
}

float cToF(float c) {
  return c * 9/5 + 32;
}

float pToHg(float p) {
  return p/3389.39;
}

void SignalStrength(const char *event, const char *data){
    Signal = atof(data);
    sig1 = atof(String(WiFi.RSSI()));
    analog1 = (Signal/2)+(sig1/2);
}

void connection(const char *event, const char *data){
    connectlog = atof(data);
   if (connectlog == 1){
        digitalWrite(connect, HIGH);
        delay(1000);
        digitalWrite(connect, LOW);
        delay(1000);
        digitalWrite(connect, HIGH);
        delay(1000);
        digitalWrite(connect, LOW);
        delay(1000);
        digitalWrite(connect, HIGH);
        delay(1000);
        digitalWrite(connect, LOW);
        delay(1000);
    }
    else{
        digitalWrite(connect, LOW);
    }
    
   delay(5000);
   
}
    



/*******************************************************************************
 * Function Name  : updateThingspeak
 * Description    : sends variables to ts
 * Input          : doorstatus global variables
 * Output         : sends data to ts
 * Return         : void
                    
 *******************************************************************************/
bool updateThingspeak() 
{
    
    count++;
    Serial.print("Updating Thingspeak:");
    Serial.print(count);
    
    int rssival = WiFi.RSSI();
    
    
    Particle.publish("signalave", String(analog1));
      bool success = Particle.publish("thingSpeakWrite_All", +
     "{ \"1\": \"" + String(rssival) + "\"," +
       "\"2\": \"" + String(bme280temp) + "\"," +
       "\"3\": \"" + String(bme280humidity) + "\"," +
       "\"4\": \"" + String(bme280baro) + "\"," +
       "\"5\": \"" + String(bme280altitude) + "\"," +
       "\"6\": \"" + String(analog1) + "\"," +
       "\"k\": \"" + key + "\" }", 60, PRIVATE);
    return success; //if sent, then turn of the send flag, otherwise let it try again.
    
}
  

Signal Strength go no go readout

C/C++
int led1 = D0;
int led2 = D1;
double Signal = 0;
double sig1 = 0;
double comparator = 0;


void setup() {
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
Particle.subscribe("signalave", SignalStrength, "your device id here");
}


void SignalStrength(const char *event, const char *data){
    Signal = atof(data);
    sig1 = Signal;
}


void loop() {
    Particle.publish("Signal", String(sig1));
    delay(10000);
    if (sig1 >-80){
        digitalWrite(led1, HIGH);
        digitalWrite(led2, LOW);
        Particle.publish("goodsignal", "1" );
    }
    else{
        digitalWrite(led2, HIGH);
        digitalWrite(led1, LOW);
        Particle.publish("goodsignal", "0");
    }
}

Credits

ez manco

ez manco

1 project • 0 followers
Jake Johns

Jake Johns

0 projects • 0 followers
Tyler Watkins

Tyler Watkins

0 projects • 0 followers

Comments

Add projectSign up / Login