Advertisement
DanCor82

Untitled

Oct 23rd, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Aggiungo per sensore polvere
  2. #ifdef ESP32
  3. #error ESP32 does not work with SoftSerial, use HardwareSerial example instead
  4. #endif
  5. #include <SDS011.h>
  6.  
  7. #include <Wire.h>
  8. #include <ESP8266WiFi.h>
  9. #include <ESP8266mDNS.h>
  10. #include <WiFiUdp.h>
  11. #include <ArduinoOTA.h>
  12. #include <ESP8266HTTPClient.h>
  13. #include <SPI.h>
  14. #include <Adafruit_Sensor.h>
  15. #include <Adafruit_BME280.h>
  16.  
  17.  
  18. //#define BME_SCK 13
  19. //#define BME_MISO 12
  20. //#define BME_MOSI 11
  21. //#define BME_CS 10
  22.  
  23. #define SEALEVELPRESSURE_HPA (1013.25)
  24.  
  25. Adafruit_BME280 bme; // I2C
  26. float temperatura;
  27. float pressione;
  28. float umidita;
  29. float dp;
  30. float tempf;
  31. const char* ssid     = "ZeusWiFi_EXT";        
  32. const char* password = "pass";
  33. float p10, p25;
  34.  
  35. SDS011 my_sds;
  36.  
  37. void setup() {
  38.  // Tolgo per sensore SDS   Serial.begin(115200);
  39.     bool status;
  40.     my_sds.begin(D1, D2);
  41.     Wire.begin(D3,D4); //SDA SCL bme280
  42.     status = bme.begin(0x76);  
  43.     if (!status) {
  44.         Serial.println("Could not find a valid BME280 sensor, check wiring!");
  45.         while (1);
  46.     }
  47.     WiFi.mode(WIFI_OFF);
  48.     WiFi.mode(WIFI_STA);
  49.     WiFi.begin(ssid, password);
  50.     int i = 0;
  51.     while (WiFi.status() != WL_CONNECTED) {
  52.      delay(1000);
  53.     }
  54.     ArduinoOTA.setPassword("!password!");
  55.     ArduinoOTA.onStart([]() {
  56.     String type;
  57.     if (ArduinoOTA.getCommand() == U_FLASH) {
  58.       type = "sketch";
  59.     } else { // U_SPIFFS
  60.       type = "filesystem";
  61.     }
  62.  
  63.     // NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
  64.     Serial.println("Start updating " + type);
  65.   });
  66.   ArduinoOTA.onEnd([]() {
  67.     Serial.println("\nEnd");
  68.   });
  69.   ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
  70.     Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
  71.   });
  72.   ArduinoOTA.onError([](ota_error_t error) {
  73.     Serial.printf("Error[%u]: ", error);
  74.     if (error == OTA_AUTH_ERROR) {
  75.       Serial.println("Auth Failed");
  76.     } else if (error == OTA_BEGIN_ERROR) {
  77.       Serial.println("Begin Failed");
  78.     } else if (error == OTA_CONNECT_ERROR) {
  79.       Serial.println("Connect Failed");
  80.     } else if (error == OTA_RECEIVE_ERROR) {
  81.       Serial.println("Receive Failed");
  82.     } else if (error == OTA_END_ERROR) {
  83.       Serial.println("End Failed");
  84.     }
  85.   });
  86.   ArduinoOTA.begin();
  87.   Serial.println("Ready");
  88.   Serial.print("IP address: ");
  89.   Serial.println(WiFi.localIP());
  90.  
  91. }
  92.  
  93.  
  94. void loop() {
  95.     ArduinoOTA.handle();
  96.     HTTPClient http;
  97.     temperatura = bme.readTemperature();
  98.     pressione = (bme.readPressure() / 100);
  99.     umidita = bme.readHumidity();
  100.     dp = temperatura - 0.36 * (100 - umidita);
  101.     String str_temp, str_press, str_um, str_dp, Link, Link2, getData;
  102.     str_temp = String(temperatura);
  103.     str_press = String(pressione);
  104.     str_um = String(umidita);
  105.     str_dp = String(dp);
  106.  
  107.     //Aggiungo per sensore aria
  108.     error = my_sds.read(&p25, &p10);
  109.     if (!error) {
  110.       Serial.println("P2.5: " + String(p25));
  111.       Serial.println("P10:  " + String(p10));
  112.     }
  113.    
  114.    delay(300e6);
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement