It's my first post so I'd like to say hello! ;)
I want to share with you my DIY project I've completed sometime ago. Which I'm using to see what temperature is in my house, well - In each room.
Take a look:
Pretty simple, right? That's what best about it.
The dashboard looks like this:
And now how It's made..
The hardware consists of:
- NodeMCU ( esp8266 ) ( 3$ on Aliexpress )
- BME280 ( 6$ on Aliexpres )
- Breadboard ( 0,6$ on Aliexpress )
- Some wires
At total cost of no more than 10$ you're getting very accurate sensor and a micro-controller with built-in Wi-FI, with an ability to add more sensors, for example PM10/PM2,5 sensor. ;)
It works like this.. ESP2866 is connected to my home Wi-FI network, every 10 seconds it sends a POST request to my InfluxDB database, that's installed on my server, with everything that's needed:
- Id of esp8266
- Temperature
- Humidity
- Pressure
Here's the full ready to use code, I'm using this library for BME280.. You can easily change the frequency, or the units in which the output is presented, metric or not, and every kind of pressure unit.
#include "ESP8266WiFi.h"
#include <BME280.h>
#include <Wire.h>
// WiFi parameters
const char* ssid = "";
const char* password = "";
// InfluxDB parameters
const int Port = ;
const char* host = "";
int freq = 10; // In seconds
String id = "6"; // Ids of each esp8266 unit, in case of multiple units.
// BMP280 settings
BME280 bme;
uint8_t pressureUnit(1); // unit: 0 = Pa, 1 = hPa, 2 = Hg, 3 = atm, 4 = bar, 5 = torr, 6 = N/m^2, 7 = psi
bool metric = true;
float temp(NAN), hum(NAN), pres(NAN);
String host_db = "ESP82660" + id;
void setup() {
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
}
Wire.begin(4, 5);
while (!bme.begin()) {
delay(1000);
}
}
void loop() {
WiFiClient client;
if (!client.connect(host, Port)) {
return;
}
bme.ReadData(pres, temp, hum, metric, pressureUnit);
String PostTemp = "temperature,host=" + host_db + " value=" + String(temp);
String PostHum = "humidity,host=" + host_db + " value=" + String(hum);
String PostPres = "pressure,host=" + host_db + " value=" + String(pres);
client.println("POST /write?db=name_of_database&u=username&p=password HTTP/1.1");
client.println("Host: " + String(host));
client.print("Content-Length: ");
client.println(PostHum.length() + PostHum.length() + PostPres.length() + 4);
client.println();
client.print(PostTemp + "\n" + PostHum + "\n" + PostPres);
client.println("Connection: close");
client.println();
delay((freq - 4) * 1000);
}
I hope You'll like this! Here it is again steemit like the mess up the formatting: https://gist.github.com/ireun/306571c2b44e82720080ed6fbd7ce81a
IreuN.