Ako inšpiráciou mi bolo veľa príspevkov z tohoto fóra a taktiež veľa zahraničných. Možno (určite) si v tomto kóde všimne tú svoju časť jankop
Celok ako taký je funkčný i keď nie veľmi pekný ale ako tak fungujúci. Samozrejme ak má niekto nápady na vylepšenie kludne môže napísať, budem len rád.
Kód: Vybrat vše
// NodeMCU ESP8266 ESP-12E V3 LoLin WiFi Weather Station / 2018-04-11
// For ESP8266 and BMP280, BH1750, DHT22, DS18B20 and SI1145 sensor
// Copyright 2018 Martin Šturcel, https://sturcel.sk/martin
// MIT license, http://opensource.org/licenses/MIT
// Tested with ARDUINO IDE 1.8.5, NodeMCU ESP8266 V3 LoLin
//
// Properties:
// - WiFi Protected Setup with PBC ready
// - Support OTA from iotappstory.com
// (with at least 1MB of memory for OTA)
// - Improved barometric formula
//
//
// Connection :
// ESP8266-12 ------------------------------------------
// USB -> Power USB
// 3V3 -> Vcc BMP280, SI1145, BH1750
// GND -> GND BMP280, SI1145, BH1750
// GPIO2 -> DS18B20 (physically connected to D4)
// GPIO4 -> SCL BMP280, SI1145, BH1750 (physically connected to D2)
// GPIO5 -> SCL BMP280, SI1145, BH1750 (physically connected to D1)
// GPI14 -> SCL HT22 (physically connected to D5)
// --------------------------------------------------------
//
//
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <time.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>
#include <BH1750.h>
#include <Wire.h>
#include <DHT.h>
#include <Adafruit_SI1145.h>
#include <IOTAppStory.h>
#define APPNAME "mpca86_PWS_production"
#define VERSION "V1.0.3"
#define COMPDATE __DATE__ __TIME__
#define DHTPIN 14
#define DHTTYPE DHT22
#define ONE_WIRE_BUS 2
#define SDAI2CPIN 4
#define SCLI2CPIN 5
#define BMP280ADDR 0x76 // Set BMP280 I2C address
#define SI1145ADDR 0x60 // Set BMP280 I2C address
IOTAppStory IAS(APPNAME,VERSION,COMPDATE,0);
DHT dht(DHTPIN, DHTTYPE);
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
Adafruit_BMP280 bmp280;
Adafruit_SI1145 uv = Adafruit_SI1145();
BH1750 lightMeter;
const char* ssid = "***";
const char* password = "***";
const char* host = "sturcel.sk";
unsigned long callHomeTimeout = 120; // put time in seconds
unsigned long sendDataTimeout = 60;
unsigned long callHomeEntry = millis();
unsigned long sendDataEntry = millis();
#define PASSCODE "***"
void setup() {
delay(100);
IAS.serialdebug(false,9600);
IAS.preSetConfig(ssid,password,"NODEMCU_PWS_BOARD",true);
IAS.begin(true);
IAS.callHome(true);
Wire.begin(SDAI2CPIN, SCLI2CPIN);
bmp280.begin(BMP280ADDR);
uv.begin();
lightMeter.begin(BH1750::ONE_TIME_HIGH_RES_MODE);
dht.begin();
sensors.begin();
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
}
digitalWrite(2, HIGH);
}
void loop(void){
IAS.buttonLoop();
if (millis() - callHomeEntry > (callHomeTimeout*1000)) {
IAS.callHome();
callHomeEntry = millis();
}
if (millis() - sendDataEntry > (sendDataTimeout*1000)) {
//ESP.restart();
sendData();
sendDataEntry = millis();
}
if (uv.readIR() == 0) {
ESP.restart();
}
delay(1000);
}
void sendData(void) {
WiFiClientSecure client;
if (!client.connect(host, 443)) {
Serial.println("Connection failed");
return;
}
float tempDS18B20 = sensors.getTempCByIndex(0);
float pres = bmp280.readPressure();
float tempBMP = bmp280.readTemperature();
float UVindex = uv.readUV();
String url = "/meteo/posielamudaje.php?code=";
url += PASSCODE;
url += "&h=";
url += dht.readHumidity();
url += "&t=";
url += dht.readTemperature();
url += "&p=";
url += ((pres / pow(1.0 - 0.0065 * 673 / (dht.readTemperature() + 273.15), 5.255))/100);
url += "&t1=";
url += tempBMP;
url += "&t2=";
url += tempDS18B20;
url += "&uv=";
url += UVindex/100;
url += "&ir=";
url += uv.readIR();
url += "&vis=";
url += uv.readVisible();
url += "&s=";
url += (uv.readUV()*0.25);
url += "&lux=";
url += lightMeter.readLightLevel();
//Serial.print("Requesting URL: "); //uncomment for debug
//Serial.println(host + url); //uncomment for debug
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"User-Agent: ESP8266/1.0\r\n" +
"Connection: close\r\n\r\n");
delay(100);
while(client.connected()){
String line = client.readString();
//String line = client.readStringUntil('\n');
//Serial.println(line); //uncomment for debug
}
client.stop();
}