PWS na ESP8266

Tvoříte zajímavý projekt? Pochlubte se s ním.
Pravidla fóra
Vkládejte prosím jen HOTOVÉ projekty, které chcete představit ostatním.
Odpovědět
Uživatelský avatar
mpca86
Příspěvky: 21
Registrován: 26 úno 2018, 08:11
Reputation: 0

PWS na ESP8266

Příspěvek od mpca86 » 12 dub 2018, 16:45

PWS lebo "Personal Weather Station" :-)
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 :oops:
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();
}
Výsledné hodnoty sa zobrazujú a ukladajú na stránke cez Meteotemplate.

jankop
Příspěvky: 1029
Registrován: 06 zář 2017, 20:04
Reputation: 0
Bydliště: Brno
Kontaktovat uživatele:

Re: PWS na ESP8266

Příspěvek od jankop » 12 dub 2018, 18:51

Nerozumím jen jedné věci. Proč jsi pro OTA zvolil nějaký cloud. OTA funguje perfektně z prohlížeče nebo i ze serveru. Sám nahrávám i při ladění firmware prakticky jen přes WiFi z prohlížeče. Když ten cloud vypadne nebo ho zruší, tak jsi nahranej. Nejsem paranoidní, ale správce cloudu si také může s tvými IOT dělat co chce. Pokud nemám zrovna 300 zařízení, tak nějakej super IOT management na cloudu není nutný.

Uživatelský avatar
mpca86
Příspěvky: 21
Registrován: 26 úno 2018, 08:11
Reputation: 0

Re: PWS na ESP8266

Příspěvek od mpca86 » 12 dub 2018, 20:27

Ďakujem za dotaz iotappstory.com som zvolil prave kvoli tomu ze nemusim si pamatat udaje ku vlastnemu FTP a nemusim riesti "svoje" PHP riesenie. Mam tam pekne logy kedy prebehol update atd... Aktualizacie nechcem len z prehliadaca preto som volil server. Ten web riesi pan Andreas Spiess aj s jednym chlapkom a nemam obavy o to aby zanikol a do buducnosti mozno pripravim aj verejnu verziu kedze sa da pekne priamo po inicializacii customizovat... A ak by nahodou zanikol tak si uz napsiem vlastne riesenie (skor si myslim ze umre samotna "doska" skor ako web skonci)

jankop
Příspěvky: 1029
Registrován: 06 zář 2017, 20:04
Reputation: 0
Bydliště: Brno
Kontaktovat uživatele:

Re: PWS na ESP8266

Příspěvek od jankop » 12 dub 2018, 21:09

Ještě mi řekni, jestli se někde můžu podívat na Meteotemplate na výsledek

Uživatelský avatar
mpca86
Příspěvky: 21
Registrován: 26 úno 2018, 08:11
Reputation: 0

Re: PWS na ESP8266

Příspěvek od mpca86 » 12 dub 2018, 21:17

samozrejme https://sturcel.sk/meteo/ čakám kým vyjde 18ta verzia a potom sa chcem povenovať customizacii webu

Inak ku Meteotemplate vytvoril to pán Jachym Brzezina zhodou okolností tiež z Brna ;) Ako tak pozerám veľa šikovných ľudí žije v Brne :ugeek: :shock: http://www.meteotemplate.com/template/
Slovenský preklad ku Meteotemplate som dokončil ja takže ak by chcel niekto poďakovať môže aj mne :-D

Uživatelský avatar
mpca86
Příspěvky: 21
Registrován: 26 úno 2018, 08:11
Reputation: 0

Re: PWS na ESP8266

Příspěvek od mpca86 » 29 dub 2018, 13:08

aktuálne mám tento kód:

Kód: Vybrat vše

// NodeMCU ESP8266 ESP-12E V3 LoLin WiFi Weather Station / 2018-04-25
// 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  -> SDA BMP280, SI1145, BH1750 (physically connected to D2)
// GPIO5  -> SCL BMP280, SI1145, BH1750 (physically connected to D1)
// GPI14  -> SCL HT22 (physically connected to D5)
// --------------------------------------------------------
//
// How to:
// For local altitude correction, set LOCALALTUD in meters
//
//
//
#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.6"
#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 MAX_SRV_CLIENTS 5
#define PASSCODE "***"
uint8_t i = 0;
IOTAppStory IAS(APPNAME, VERSION, COMPDATE, 0);
WiFiServer TelnetServer(23);
WiFiClient Telnet;
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, 120 only for development. Please change it to at least 2 hours (7200) in production
unsigned long sendDataTimeout = 60; // put time in seconds
unsigned long callHomeEntry = millis();
unsigned long sendDataEntry = millis();
unsigned long sendDataDuration;
unsigned long callHomeDuration;
long Day = 0;
int Hour = 0;
int Minute = 0;
int Second = 0;
int HighMillis = 0;
int Rollover = 0;
void setup() {
  delay(100);
  IAS.serialdebug(false, 9600);                             //IOTAppStory 1st parameter: true or false for serial debugging. Default: false | 2nd parameter: serial speed. Default: 115200
  IAS.preSetConfig(ssid, password, "NODEMCU_PWS_BOARD", true); //IOTAppStory preset Wifi, boardName & automaticUpdate
  IAS.begin(true);                                          //IOTAppStory 1st parameter: true or false to view BOOT STATISTICS | 2nd parameter: true or false to erase eeprom on first boot of the app
  IAS.callHome(true);                                       //IOTAppStory
  Wire.begin(SDAI2CPIN, SCLI2CPIN);                 //Initializing I2C
  bmp280.begin(BMP280ADDR);                         //Initializing BME280
  uv.begin();                                       //Initializing SI1145
  lightMeter.begin(BH1750::ONE_TIME_HIGH_RES_MODE); //Initializing BH1750
  dht.begin();                                      //Initializing DHT22
  sensors.begin();                                  //Initializing DS18B20
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
  }
  digitalWrite(2, HIGH);
  TelnetServer.begin();
  TelnetServer.setNoDelay(true);
}
void loop(void) {
  uptime();                                                       //Runs the uptime script located below the main loop and reenters the main loop
  handleTelnet();
  IAS.buttonLoop();                                               // this routine handles the reaction of the Flash button. If short press: update of sketch, long press: Configuration
  if (millis() - callHomeEntry > (callHomeTimeout * 1000)) {
    unsigned long startcallHome = millis();
    print_Uptime();
    Telnet.println("IAS callHome");
    IAS.callHome();
    callHomeDuration = millis() - startcallHome;
    callHomeEntry = millis();
  }
  if (millis() - sendDataEntry > (sendDataTimeout * 1000) - sendDataDuration + callHomeDuration) {
    print_Uptime();
    Telnet.println("Send Data");
    sendData();
    sendDataEntry = millis();
  }
  if (uv.readIR() == 0) {
    print_Uptime();
    Telnet.println("ESP Restart");
    ESP.restart();
  }
  Telnet.print(".");
  delay(1000);
}
void sendData(void) {
  unsigned long startsendData = millis();
  WiFiClientSecure client;
  if (!client.connect(host, 443)) {
    Telnet.println("Connection failed");
    return;
  }
  sensors.requestTemperatures();
  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();
  Telnet.print("Requesting URL: "); //uncomment for debug
  Telnet.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');
    Telnet.println(line); //uncomment for debug
  }
  client.stop();
  sendDataDuration = millis() - startsendData;
}
void uptime() {
  //** Making Note of an expected rollover *****//
  if (millis() >= 3000000000) {
    HighMillis = 1;

  }
  //** Making note of actual rollover **//
  if (millis() <= 100000 && HighMillis == 1) {
    Rollover++;
    HighMillis = 0;
  }

  long secsUp = millis() / 1000;
  Second = secsUp % 60;
  Minute = (secsUp / 60) % 60;
  Hour = (secsUp / (60 * 60)) % 24;
  Day = (Rollover * 50) + (secsUp / (60 * 60 * 24)); //First portion takes care of a rollover [around 50 days]
};
void print_Uptime() {
  Telnet.println();
  Telnet.print(F("Uptime: ")); // The "F" Portion saves your SRam Space
  Telnet.print(Day);
  Telnet.print(F("D"));
  Telnet.print(Hour);
  Telnet.print(F(":"));
  Telnet.print(Minute);
  Telnet.print(F(":"));
  Telnet.println(Second);
};
 void handleTelnet() {
  if (TelnetServer.hasClient()) {
      if (!Telnet || !Telnet.connected()) {
        if (Telnet) { 
        Telnet.stop();
        }
        Telnet = TelnetServer.available();
      }
     }
    };
No viď príloha neviem ani za pána prísť na to prečo mi nechce odosielať údaje. Vedel by mi niekto s tým pomôcť? :oops: :roll: :?: ĎAKUEJM
Přílohy
Screenshot_JuiceSSH_20180427-080328.png

Odpovědět

Kdo je online

Uživatelé prohlížející si toto fórum: Žádní registrovaní uživatelé a 13 hostů