mirror of
https://github.com/airgradienthq/arduino.git
synced 2025-07-29 16:37:17 +02:00
Updated example sketches
This commit is contained in:
@ -1,3 +1,23 @@
|
||||
/*
|
||||
Important: This code is only for the AirGradient DIY OUTDOOR.
|
||||
|
||||
Build Instructions: https://www.airgradient.com/open-airgradient/instructions/diy-outdoor/
|
||||
|
||||
Kits (including a pre-soldered version) are available: https://www.airgradient.com/open-airgradient/kits/
|
||||
|
||||
Configuration:
|
||||
Install required libraries
|
||||
Patch PMS library to accept temperature and humidity from PMS5003T
|
||||
|
||||
If you have any questions please visit our forum at https://forum.airgradient.com/
|
||||
|
||||
If you are a school or university contact us for a free trial on the AirGradient platform.
|
||||
https://www.airgradient.com/
|
||||
|
||||
License: CC BY-NC 4.0 Attribution-NonCommercial 4.0 International
|
||||
|
||||
*/
|
||||
|
||||
#include "PMS.h"
|
||||
#include "SoftwareSerial.h"
|
||||
#include <Wire.h>
|
||||
@ -7,25 +27,18 @@
|
||||
#include <ESP8266HTTPClient.h>
|
||||
#include <WiFiClient.h>
|
||||
|
||||
#include "ClosedCube_SHT31D.h"
|
||||
|
||||
SoftwareSerial softSerial(D6, D5); //(RX, TX)
|
||||
SoftwareSerial soft2(D3, D7); //(RX, TX)
|
||||
|
||||
ClosedCube_SHT31D sht3xd;
|
||||
|
||||
PMS pms(softSerial);
|
||||
PMS pms2(soft2);
|
||||
PMS::DATA data;
|
||||
|
||||
int pm1 = 0;
|
||||
int pm2 = 0;
|
||||
float temp = 0;
|
||||
int hum = 0;
|
||||
|
||||
float temp_pm1 = 0;
|
||||
float hum_pm1 = 0;
|
||||
|
||||
int pm2 = 0;
|
||||
float temp_pm2 = 0;
|
||||
float hum_pm2 = 0;
|
||||
|
||||
@ -33,14 +46,13 @@ String APIROOT = "http://hw.airgradient.com/";
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
Serial.println("hhi");
|
||||
Serial.begin(115200);
|
||||
Serial.println("Welcome to AirGradient");
|
||||
softSerial.begin(9600);
|
||||
soft2.begin(9600);
|
||||
Wire.begin();
|
||||
sht3xd.begin(0x44);
|
||||
pinMode(D7, OUTPUT);
|
||||
|
||||
|
||||
connectToWifi();
|
||||
}
|
||||
|
||||
@ -53,7 +65,7 @@ void loop()
|
||||
else {
|
||||
digitalWrite(D7, LOW);
|
||||
}
|
||||
|
||||
|
||||
if (pms.read(data)){
|
||||
pm1 = data.PM_AE_UG_2_5;
|
||||
temp_pm1 = data.AMB_TMP;
|
||||
@ -66,6 +78,7 @@ void loop()
|
||||
Serial.println(hum_pm1);
|
||||
Serial.println();
|
||||
delay(1000);
|
||||
sendToServerPM1();
|
||||
}
|
||||
if (pms2.read(data)){
|
||||
pm2 = data.PM_AE_UG_2_5;
|
||||
@ -79,21 +92,13 @@ void loop()
|
||||
Serial.println(hum_pm2);
|
||||
Serial.println();
|
||||
delay(1000);
|
||||
|
||||
temp = sht3xd.readTempAndHumidity(SHT3XD_REPEATABILITY_LOW, SHT3XD_MODE_CLOCK_STRETCH, 50).t;
|
||||
hum = sht3xd.readTempAndHumidity(SHT3XD_REPEATABILITY_LOW, SHT3XD_MODE_CLOCK_STRETCH, 50).rh;
|
||||
|
||||
Serial.println(temp);
|
||||
Serial.println(hum);
|
||||
|
||||
sendToServer();
|
||||
delay(1000);
|
||||
sendToServerPM1();
|
||||
delay(1000);
|
||||
sendToServerPM2();
|
||||
|
||||
}
|
||||
|
||||
if (hum_pm1 > 0 && hum_pm2 > 0) sendToServer();
|
||||
|
||||
delay(30000);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -101,8 +106,8 @@ void loop()
|
||||
void sendToServer() {
|
||||
String payload = "{\"wifi\":" + String(WiFi.RSSI())
|
||||
+ ", \"pm02\":" + String((pm1+pm2)/2)
|
||||
+ ", \"atmp\":" + String(temp)
|
||||
+ ", \"rhum\":" + String(hum)
|
||||
+ ", \"atmp\":" + String((temp_pm1 + temp_pm2) / 20)
|
||||
+ ", \"rhum\":" + String((hum_pm1 + hum_pm2) / 20)
|
||||
+ "}";
|
||||
|
||||
if(WiFi.status()== WL_CONNECTED){
|
||||
@ -192,10 +197,10 @@ void sendToServerPM2() {
|
||||
WiFiManager wifiManager;
|
||||
//WiFi.disconnect(); //to delete previous saved hotspot
|
||||
String HOTSPOT = "AIRGRADIENT-" + String(ESP.getChipId(), HEX);
|
||||
wifiManager.setTimeout(60);
|
||||
wifiManager.setTimeout(120);
|
||||
if (!wifiManager.autoConnect((const char * ) HOTSPOT.c_str())) {
|
||||
Serial.println("failed to connect and hit timeout");
|
||||
delay(6000);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user