/* Full details of the Mazzone Edoardo project can be found at “https://github.com/edomazzone” (instructions are publicly available). Permission is granted, free of charge, to any person obtaining a copy of this software and associated documentation files. The above copyright notice and this permission notice must be included in all copies or substantial portions of the Software. */ //include all library #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /***********************************************************/ //MHZ-19 #define RX_PIN 26 // Rx pin that MHZ19 Tx pin is connected to #define TX_PIN 27 // Tx pin that MHZ19 Rx pin is connected to #define BAUDRATE 9600 // Serial baudrate for the MH-Z19 from the device (do not change)#include MHZ19 myMHZ19; // Constructor for library HardwareSerial mySerial(1); // ESP32 has two USARTs available, so the SoftwareSerial library is not needed unsigned long getDataTimer; unsigned long preheat_time = 15000; // Test time int CO2; /********************************************************/ //OTA const char* ssid = “xxxxxxxxxxxxxxxxx”; const char* password = “yyyyyyyyyyyyyy”; AsyncWebServer server(80); /****************************************************************/ //SDS011 float p10, p25; int err; SDS011 my_sds; #ifdef ESP32 HardwareSerial port(2); #endif /****************************************************************/ //DHT11 DHTPIN 5 #define DHTTYPE DHT11 DHT dht(DHTPIN, DHTTYPE); /****************************************************************/ //InfluxDB WiFiMulti wifiMulti; #define DEVICE “ESP32” #define WIFI_SSID “xxxxxxxxxxxxxxxxxx” #define WIFI_PASSWORD “yyyyyyyyyyyyyyyyyyyy” #define INFLUXDB_URL “https://us-east-1-1.aws.cloud2.influxdata.com” #define INFLUXDB_TOKEN “zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz” #define INFLUXDB_ORG “zzzzzzzzzz” #define INFLUXDB_BUCKET “Sensor” // Set the timezone string according to https://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html // Central Europe: “CET-1CEST,M3.5.0,M10.5.0/3” #define TZ_INFO “UTC2” InfluxDBClientclient(INFLUXDB_URL, INFLUXDB_ORG, INFLUXDB_BUCKET, INFLUXDB_TOKEN, InfluxDbCloud2CACert); Point sensors_readings(“measurements”); /****************************************/ //Global var byte i; unsigned long s = 30; double Temp; #define uS_TO_S_FACTOR 1000000 // Conversion factor from microseconds to seconds #define TIME_TO_SLEEP 300 // Time in seconds for ESP32 to sleep 5min*60s int interval = 5000; // Start time for PM sensors void setup() { Serial.begin(9600); // Start the serial monitor esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR); // Set sleep time WiFi.mode(WIFI_STA); // Turn on WiFi wifiMulti.addAP(WIFI_SSID, WIFI_PASSWORD); Serial.print(“Connected to WiFi”); while ((wifiMulti.run() != WL_CONNECTED) && (i < 5)) { i++; Serial.print("."); delay(500); } Serial.println(""); Serial.print("" に接続しました "); Serial.println(WIFI_SSID); Serial.print("IP アドレス: "); Serial.println(WiFi.localIP()); // 同じ SSID で接続することを忘れないでください server.on("/", HTTP_GET, [](AsyncWebServerRequest * request) { request->send(200, “text/plain”, “AirQualitySensor”); }); AsyncElegantOTA.begin(&server); // Start ElegantOTA server.begin(); Serial.println(“HTTP server started”); // Add a tag sensors_readings.addTag(“sensor”, “Green”); // If you are using multiple sensors (I chose the case color) // Or set an insecure connection to skip server certificate validation //client.setInsecure(); timeSync(TZ_INFO, “pool.ntp.org”, “time.nis.gov”); // Check server connection if (client.validateConnection()) { Serial.print(“Connected to InfluxDB: “); Serial.println(client.getServerUrl()); } else { Serial.print(“InfluxDB connection failed: “); Serial.println(client.getLastErrorMessage()); } mySerial.begin(BAUDRATE,SERIAL_8N1, RX_PIN, TX_PIN); // Start MH-Z19 serial from device myMHZ19.begin(mySerial); // You must pass a *Serial(Stream) reference to the library begin(). myMHZ19.setRange(2000); myMHZ19.autoCalibration(); // Turn on autocalibration (OFF autoCalibration(false)) my_sds.begin(&port); dht.begin(); if (!SPIFFS.begin(true)) { Serial.println(“Error mounting SPIFFS”); return; } } void loop() { // Print data not sent File file2 = SPIFFS.open(“/PM sensors.txt”); if (!file2) { Serial.println(“Could not open file for reading”); return; } Serial.println(“File contents:”); while (file2.available()) { Serial.write(file2.read()); } file2.close(); // Get new data sds_011.wakeup(); delay(interval); err = my_sds.read(&p25,&p10); // Request PM value if (!err) { Serial.print(“P2.5: ” + String(p25)); Serial.println(” P10: ” + String(p10)); } else{ Serial.println(“PM Reading Error!!”); } sds_011.sleep(); CO2 = myMHZ19.getCO2(); // Request CO2 (as ppm) Temp = myMHZ19.getTemperature(); // Request Temperature (as Celsius) Serial.print(“CO2 (ppm): “); Serial.print(CO2); Serial.print(” Temperature (C): “); Serial.println(Temp); double h = dht.readHumidity(); double t = dht.readTemperature(); if (isnan(h) || isnan
Source link
- Home
- AI
- VR & AR
- Automotive Technology & Autonomous Vehicles
- Big Data & Data Analysis
- Blockchain & Cryptocurrencies
- Energy & Green Technology
- Games & Gaming Technology
- Mobile Communications & Telecommunications
- Technological Developments in the Healthcare Industry
- Technology Market Trends & Analysis
- Technology Policy & Regulation
- Biotechnology
- Cybersecurity
- Cloud Computing & Infrastructure
- Space Technology
- Gaming
- Robotics