Claude (science 3d)
Published © GPL3+

IoT Weather Station and Data Logging

Get the temperature, humidity and barometric pressure with a very simple circuit and using the free MQTT service io. adafruit. com

IntermediateFull instructions provided4 hours855
IoT Weather Station and Data Logging

Things used in this project

Hardware components

BME280
×1
WEMOS D1 Mini PRO
×1
Copper clad single sided board
×1
M3 screw and nuts
×1

Hand tools and fabrication machines

Formlabs Form 2 SLA 3D printer or Ultimaker FDM 3D Printer
Shapeoko 3 CNC

Story

Read more

Custom parts and enclosures

Enclosure (casing) and drawer

Enclosure (Casing) Support

to screw the casing on a wall

Wemos drawer part 1

Wemos drawer part 2

Schematics

Electronic schematic

Board

Code

Main code

Arduino
/* if BOARD = WEMOS D1 mini Pro
** SCL = D1
** SDA = D2 
*/

// PING
//#define trigPin D5
//#define echoPin D6

// BME280
#include "Seeed_BME280.h" // library needed Grove_BME280-master
#include <Wire.h>
BME280 bme280;

/////////////////////////////////
// Generated with a lot of love//
// with TUNIOT FOR ESP8266     //
// Website: Easycoding.tn      //
/////////////////////////////////
#include <ESP8266WiFi.h>

#include "Adafruit_MQTT.h"    // librairie Adafruit_MQTT_Library-master
#include "Adafruit_MQTT_Client.h"

#define AIO_SERVER      "io.adafruit.com"
#define AIO_SERVERPORT  1883
#define AIO_USERNAME    "ADAFRUIT_USER_NAME"
#define AIO_KEY         "xxxxxxxxxxxxxxxxxxxxxxxxxxx" // key that is generated within the website
// claude
#define WIFI_SSID      "XXXXX"
#define WIFI_PASS      "XXXXX"

#define WAIT_DELAY     35000

WiFiClient client;
Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);

boolean MQTT_connect();
boolean MQTT_connect()
{
  int8_t ret;
  if (mqtt.connected()) {
    return true;
  }  uint8_t retries = 3;
  while ((ret = mqtt.connect()) != 0) {
    mqtt.disconnect();
    delay(2000);
    retries--;
    if (retries == 0) {
      return false;
    }
  } return true;
}

Adafruit_MQTT_Publish Garage_Humidity = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/Garage_Humidity");
Adafruit_MQTT_Publish Garage_Pression = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/Garage_Pression");
Adafruit_MQTT_Publish Garage_Temperature = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/Garage_Temperature");
//Adafruit_MQTT_Publish MeteoSnowLevel = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/MeteoSnowLevel");

void setup()
{
  // Pour IIC ESP8266-01 //---------------------------------------------------
  // garder la ligne qui suit uniquement lorsque ESP8266-01 est en usage
  //Wire.begin(0, 2); // (SDA,SCL) join i2c bus (address optional for master)

  Serial.begin(9600);
  if (!bme280.init()) Serial.println("BMP280 - Device error!");

  WiFi.disconnect();
  delay(3000);
  Serial.println("START");
  WiFi.begin(WIFI_SSID, WIFI_PASS);
  while ((!(WiFi.status() == WL_CONNECTED)))
  {
    delay(300);
    Serial.print("..");
  }
  Serial.println("Connected");
  Serial.println("Your IP is");
  Serial.println((WiFi.localIP().toString()));
  Serial.println("Boot complete");
}


void loop()
{
  // Enlever si ESP8266
  //digitalWrite(LED_BUILTIN, LOW);

  float temperature = (bme280.getTemperature());
    temperature = temperature - 2.0;
  if (MQTT_connect())
  {
    if (Garage_Temperature.publish(temperature) )
    {
      Serial.print("Feed - Temperature :");
      Serial.println(temperature);
    }
    else
    {
      Serial.print("Feed error - Humidity - reconnect wifi ");
      WifiConnect();
    }
  }

  delay(WAIT_DELAY);


  float pressure = bme280.getPressure();
  if (MQTT_connect())
  {
    if (Garage_Pression.publish(pressure) )
    {
      Serial.print("Feed - Pressure: ");
      Serial.println(pressure);
    }
    else
    {
      Serial.print("Feed error - Humidity - reconnect wifi ");
      WifiConnect();
    }
  }

  delay(WAIT_DELAY);

  float Humidity = bme280.getHumidity();
  if (MQTT_connect())
  {
    if (Garage_Humidity.publish(Humidity) )
    {
      Serial.print("Feed - Humidity: ");
      Serial.println(Humidity);
    }
    else
    {
      Serial.print("Feed error - Humidity - reconnect wifi ");
      WifiConnect();
    }
  }

  
  delay(WAIT_DELAY);

}


void WifiConnect()
{
  WiFi.disconnect();
  delay(3000);
  WiFi.begin(WIFI_SSID, WIFI_PASS);
  while ((!(WiFi.status() == WL_CONNECTED)))
  {
    delay(300);
    Serial.print("..");
  }
}

Credits

Claude (science 3d)

Claude (science 3d)

9 projects • 17 followers
I have a background in electronics, since 1984. I used to work as a programmer for a couple of years. Now, I am working as a DBA.

Comments