Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Aggiungo per sensore polvere
- #ifdef ESP32
- #error ESP32 does not work with SoftSerial, use HardwareSerial example instead
- #endif
- #include <SDS011.h>
- #include <Wire.h>
- #include <ESP8266WiFi.h>
- #include <ESP8266mDNS.h>
- #include <WiFiUdp.h>
- #include <ArduinoOTA.h>
- #include <ESP8266HTTPClient.h>
- #include <SPI.h>
- #include <Adafruit_Sensor.h>
- #include <Adafruit_BME280.h>
- //#define BME_SCK 13
- //#define BME_MISO 12
- //#define BME_MOSI 11
- //#define BME_CS 10
- #define SEALEVELPRESSURE_HPA (1013.25)
- Adafruit_BME280 bme; // I2C
- float temperatura;
- float pressione;
- float umidita;
- float dp;
- float tempf;
- const char* ssid = "ZeusWiFi_EXT";
- const char* password = "pass";
- float p10, p25;
- SDS011 my_sds;
- void setup() {
- // Tolgo per sensore SDS Serial.begin(115200);
- bool status;
- my_sds.begin(D1, D2);
- Wire.begin(D3,D4); //SDA SCL bme280
- status = bme.begin(0x76);
- if (!status) {
- Serial.println("Could not find a valid BME280 sensor, check wiring!");
- while (1);
- }
- WiFi.mode(WIFI_OFF);
- WiFi.mode(WIFI_STA);
- WiFi.begin(ssid, password);
- int i = 0;
- while (WiFi.status() != WL_CONNECTED) {
- delay(1000);
- }
- ArduinoOTA.setPassword("!password!");
- ArduinoOTA.onStart([]() {
- String type;
- if (ArduinoOTA.getCommand() == U_FLASH) {
- type = "sketch";
- } else { // U_SPIFFS
- type = "filesystem";
- }
- // NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
- Serial.println("Start updating " + type);
- });
- ArduinoOTA.onEnd([]() {
- Serial.println("\nEnd");
- });
- ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
- Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
- });
- ArduinoOTA.onError([](ota_error_t error) {
- Serial.printf("Error[%u]: ", error);
- if (error == OTA_AUTH_ERROR) {
- Serial.println("Auth Failed");
- } else if (error == OTA_BEGIN_ERROR) {
- Serial.println("Begin Failed");
- } else if (error == OTA_CONNECT_ERROR) {
- Serial.println("Connect Failed");
- } else if (error == OTA_RECEIVE_ERROR) {
- Serial.println("Receive Failed");
- } else if (error == OTA_END_ERROR) {
- Serial.println("End Failed");
- }
- });
- ArduinoOTA.begin();
- Serial.println("Ready");
- Serial.print("IP address: ");
- Serial.println(WiFi.localIP());
- }
- void loop() {
- ArduinoOTA.handle();
- HTTPClient http;
- temperatura = bme.readTemperature();
- pressione = (bme.readPressure() / 100);
- umidita = bme.readHumidity();
- dp = temperatura - 0.36 * (100 - umidita);
- String str_temp, str_press, str_um, str_dp, Link, Link2, getData;
- str_temp = String(temperatura);
- str_press = String(pressione);
- str_um = String(umidita);
- str_dp = String(dp);
- //Aggiungo per sensore aria
- error = my_sds.read(&p25, &p10);
- if (!error) {
- Serial.println("P2.5: " + String(p25));
- Serial.println("P10: " + String(p10));
- }
- delay(300e6);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement