☁️

Weather Station (Standard)

 
 
[{"id":"e9317d97.91a5e","type":"ui_chart","z":"46068dbc.29ebf4","name":"Temperature Chart","group":"9fd0144b.d7ef28","order":4,"width":"0","height":"0","label":"","chartType":"line","legend":"false","xformat":"HH:mm","interpolate":"linear","nodata":"","dot":false,"ymin":"15","ymax":"50","removeOlder":"24","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":630,"y":200,"wires":[[],[]]},{"id":"e29d6cdb.c05cb","type":"mqtt in","z":"46068dbc.29ebf4","name":"","topic":"weatherStation/temperature","qos":"1","broker":"569fbfd1.c8073","x":127.9998550415039,"y":163.666748046875,"wires":[["e9317d97.91a5e","4b112697.102088","f51be4ee.368998"]]},{"id":"e015e24d.243d6","type":"mqtt in","z":"46068dbc.29ebf4","name":"","topic":"weatherStation/humidity","qos":"1","broker":"569fbfd1.c8073","x":119.83313751220703,"y":73.66664505004883,"wires":[["f51be4ee.368998","da1cc302.7ae53","c3645cef.4ff35"]]},{"id":"c3645cef.4ff35","type":"ui_chart","z":"46068dbc.29ebf4","name":"Humidity Chart","group":"9fd0144b.d7ef28","order":8,"width":"0","height":"0","label":"not working @humidity","chartType":"line","legend":"false","xformat":"HH:mm","interpolate":"linear","nodata":"","dot":false,"ymin":"0","ymax":"100","removeOlder":"24","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":620.8331642150879,"y":106.66663074493408,"wires":[[],[]]},{"id":"25fee574.5822fa","type":"mqtt in","z":"46068dbc.29ebf4","name":"","topic":"weatherStation/voltage","qos":"1","broker":"569fbfd1.c8073","x":102.83326721191406,"y":532.6668424606323,"wires":[["6c48e4f6.6be57c"]]},{"id":"7aafa03e.8f8c9","type":"mqtt in","z":"46068dbc.29ebf4","name":"","topic":"weatherStation/pressure","qos":"1","broker":"569fbfd1.c8073","x":118.8331069946289,"y":262.66654872894287,"wires":[["d5b4510b.50a04"]]},{"id":"d5b4510b.50a04","type":"function","z":"46068dbc.29ebf4","name":"pascal to mm/hg","func":"msg.payload *= 0.00750062;\nreturn msg;","outputs":1,"noerr":0,"x":411.9998550415039,"y":264.33325386047363,"wires":[["318a6ec.19a2e92","f51be4ee.368998","17e047db.80b028"]]},{"id":"da1cc302.7ae53","type":"ui_gauge","z":"46068dbc.29ebf4","name":"","group":"9fd0144b.d7ef28","order":7,"width":"0","height":"0","gtype":"wave","title":"Humidity","label":"%","format":"{{value|number:1}}","min":0,"max":"100","colors":["#5a5a5a","#34b92d","#0202ff"],"seg1":"","seg2":"","x":597.9998359680176,"y":56.6665563583374,"wires":[]},{"id":"4b112697.102088","type":"ui_gauge","z":"46068dbc.29ebf4","name":"","group":"9fd0144b.d7ef28","order":3,"width":"0","height":"0","gtype":"gage","title":"Temperature","label":"�C","format":"{{value|number:1}}","min":"15","max":"50","colors":["#0000ff","#e6e600","#ca3838"],"seg1":"0","seg2":"30","x":609.9998435974121,"y":154.66656303405762,"wires":[]},{"id":"318a6ec.19a2e92","type":"ui_gauge","z":"46068dbc.29ebf4","name":"","group":"9fd0144b.d7ef28","order":5,"width":"0","height":"0","gtype":"gage","title":"Pressure","label":"mm/Hg","format":"{{value|number:2}}","min":"650","max":"850","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":626.9998168945312,"y":239.6666259765625,"wires":[]},{"id":"a2e22e3a.a4c01","type":"mqtt in","z":"46068dbc.29ebf4","name":"","topic":"weatherStation/light","qos":"1","broker":"569fbfd1.c8073","x":98.83309936523438,"y":344.66659355163574,"wires":[["b6dd3b5d.252958","f51be4ee.368998","27593613.e0b28a"]]},{"id":"b6dd3b5d.252958","type":"ui_gauge","z":"46068dbc.29ebf4","name":"","group":"9fd0144b.d7ef28","order":9,"width":"0","height":"0","gtype":"gage","title":"Light (LDR Lost Somewhere)","label":"","format":"{{value|number:2}}","min":"0","max":"100","colors":["#000080","#c0c0c0","#ffff80"],"seg1":"","seg2":"","x":664.8333320617676,"y":330.66663360595703,"wires":[]},{"id":"df107d9d.ed225","type":"function","z":"46068dbc.29ebf4","name":"state to finished html icon","func":"\nvar moon = \"&#127769;\";\nvar rain = \"&#127783;\";\nvar sun = \"&#127774\";\nvar cloud = \"&#9925;\";\n\ncontext.humidity = context.humidity || 50;\ncontext.light = context.light || 0.5;\ncontext.pressure = context.pressure || 1000;\n\nif(msg.topic === 'humidity' && msg.payload != 'nan')\n context.humidity = msg.payload;\nif(msg.topic === 'light' && msg.payload != 'nan')\n context.light = msg.payload;\nif(msg.topic === 'pressure' && msg.payload != 'nan')\n context.pressure = msg.payload;\n\nif(context.humidity < 50)\n{\n if(context.light > 0.1)\n msg.payload = sun;\n else\n msg.payload = moon;\n}\nelse \nif(context.humidity < 80)\n{\n //if(context.light > 0.1)\n msg.payload = cloud;\n //else\n // msg.payload = moon;\n}\nelse\n{\n msg.payload = rain;\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":668.8330154418945,"y":461.6664762496948,"wires":[["370a4fcf.592d4"]]},{"id":"f51be4ee.368998","type":"change","z":"46068dbc.29ebf4","name":"translate topic","rules":[{"t":"change","p":"topic","pt":"msg","from":"weatherStation/humidity","fromt":"str","to":"humidity","tot":"str"},{"t":"change","p":"topic","pt":"msg","from":"weatherStation/temperature","fromt":"str","to":"temperature","tot":"str"},{"t":"change","p":"topic","pt":"msg","from":"weatherStation/light","fromt":"str","to":"light","tot":"str"},{"t":"change","p":"topic","pt":"msg","from":"weatherStation/pressure","fromt":"str","to":"pressure","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":428.83300018310547,"y":458.66647720336914,"wires":[["df107d9d.ed225"]]},{"id":"370a4fcf.592d4","type":"ui_template","z":"46068dbc.29ebf4","group":"9fd0144b.d7ef28","name":"Weather symbol","order":1,"width":"2","height":"3","format":"<div ng-bind-html=\"msg.payload\" style=\"font-size: 50pt\"></div>","storeOutMessages":true,"fwdInMessages":true,"templateScope":"local","x":926.8330268859863,"y":459.66647577285767,"wires":[["2b62284b.adb7d8"]]},{"id":"27593613.e0b28a","type":"ui_chart","z":"46068dbc.29ebf4","name":"Light Chart","group":"9fd0144b.d7ef28","order":10,"width":"0","height":"0","label":"","chartType":"line","legend":"false","xformat":"HH:mm","interpolate":"linear","nodata":"","dot":false,"ymin":"0","ymax":"100","removeOlder":"24","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":608.8330993652344,"y":388.6665143966675,"wires":[[],[]]},{"id":"6c48e4f6.6be57c","type":"function","z":"46068dbc.29ebf4","name":"scale","func":"msg.payload *= 3.304 / 2788;\nreturn msg;","outputs":1,"noerr":0,"x":380.83299255371094,"y":536.666482925415,"wires":[["c160f90c.db9318"]]},{"id":"c160f90c.db9318","type":"debug","z":"46068dbc.29ebf4","name":"","active":false,"console":"false","complete":"false","x":629.9998550415039,"y":536.6664817333221,"wires":[]},{"id":"2b62284b.adb7d8","type":"ui_text","z":"46068dbc.29ebf4","group":"9fd0144b.d7ef28","order":2,"width":0,"height":0,"name":"Status","label":"*Graphic Representarion (underdevelopment)","format":"{{msg.payload}}","layout":"row-center","x":990,"y":320,"wires":[]},{"id":"17e047db.80b028","type":"ui_chart","z":"46068dbc.29ebf4","name":"Pressure chart","group":"9fd0144b.d7ef28","order":6,"width":0,"height":0,"label":"","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"650","ymax":"850","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"86400","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":661,"y":285,"wires":[[],[]]},{"id":"9fd0144b.d7ef28","type":"ui_group","z":"","name":"Weather","tab":"77cbd525.8f4a1c","order":2,"disp":true,"width":"7","collapse":false},{"id":"569fbfd1.c8073","type":"mqtt-broker","z":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"77cbd525.8f4a1c","type":"ui_tab","z":"","name":"Climate","icon":"dashboard","order":1}]
Node-Red Clipboard import.txt
 
 
Schematic
Schematic
 
#include <ESP8266WiFi.h>
#include <Wire.h>
#include "DHT.h"
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"

#define DHTPIN D5
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

#define WLAN_SSID   "ssid"
#define WLAN_PASS   "doen't matter"

//MQTT broker settings
#define HOST        "whatever(ip)"
#define PORT        1883
//#define USERNAME    ""
//#define PASSWORD    ""
  
WiFiClient client;
Adafruit_MQTT_Client mqtt(&client, HOST, PORT);
Adafruit_MQTT_Publish temperature = Adafruit_MQTT_Publish(&mqtt, "weatherStation/temperature");
Adafruit_MQTT_Publish pressure = Adafruit_MQTT_Publish(&mqtt, "weatherStation/pressure");
Adafruit_MQTT_Publish humidity = Adafruit_MQTT_Publish(&mqtt, "weatherStation/humidity");
Adafruit_MQTT_Publish light = Adafruit_MQTT_Publish(&mqtt, "weatherStation/light");
Adafruit_MQTT_Publish voltage = Adafruit_MQTT_Publish(&mqtt, "weatherStation/voltage");
void MQTT_connect();

Adafruit_BMP280 bmp; // I2C

void setup() {
  delay(100);
  pinMode(D6, OUTPUT);
  digitalWrite(D6,HIGH);
  WiFi.mode(WIFI_STA);  

  //Serial.begin(115200);
  Serial.print("Connecting to ");
  Serial.println(WLAN_SSID);

  WiFi.begin(WLAN_SSID, WLAN_PASS);
    delay(5000);
  //Serial.println("IP address: "); Serial.println(WiFi.localIP());
  dht.begin();
  bmp.begin();
  if (!bmp.begin()) {  
    Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
    //while (1);
  }
  delay(5000);
  MQTT_connect();
  delay(100);
  temperature.publish(bmp.readTemperature());
  pressure.publish(bmp.readPressure());
  humidity.publish(dht.readHumidity());
//  voltage.publish(ESP.getVcc());
  light.publish((analogRead(A0))/10);
  digitalWrite(D6,LOW);
  Serial.println("deep sleep");
  ESP.deepSleep(3e+8);
}

void loop() 
{
}

void MQTT_connect() {
  int8_t ret;
  if (mqtt.connected()) {
    return;
  }

  Serial.print("Connecting to MQTT... ");
  
  while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected
       //Serial.println(mqtt.connectErrorString(ret));
       //Serial.println("Retrying MQTT connection in 1 second...");
       mqtt.disconnect();
       delay(1000);
           
  }
  //Serial.println("MQTT Connected!");
}