diff --git a/examples/C02_PM_SHT_OLED/C02_PM_SHT_OLED.ino b/examples/C02_PM_SHT_OLED/C02_PM_SHT_OLED.ino index 8a8e74f..79ec283 100644 --- a/examples/C02_PM_SHT_OLED/C02_PM_SHT_OLED.ino +++ b/examples/C02_PM_SHT_OLED/C02_PM_SHT_OLED.ino @@ -10,7 +10,7 @@ void setup(){ Serial.begin(9600); display.init(); display.flipScreenVertically(); - showTextRectangle("Init", String(ESP.getChipId(),HEX)); + showTextRectangle("Init", String(ESP.getChipId(),HEX),true); ag.PMS_Init(); ag.CO2_Init(); @@ -23,19 +23,23 @@ void loop(){ int PM2 = ag.getPM2_Raw(); int CO2 = ag.getCO2_Raw(); TMP_RH result = ag.periodicFetchData(); - showTextRectangle(String(result.t),String(result.rh)+"%"); + showTextRectangle(String(result.t),String(result.rh)+"%",false); delay(2000); - showTextRectangle("PM2",String(PM2)); + showTextRectangle("PM2",String(PM2),false); delay(2000); - showTextRectangle("CO2",String(CO2)); + showTextRectangle("CO2",String(CO2),false); delay(2000); } // DISPLAY -void showTextRectangle(String ln1, String ln2) { +void showTextRectangle(String ln1, String ln2, boolean small) { display.clear(); display.setTextAlignment(TEXT_ALIGN_LEFT); - display.setFont(ArialMT_Plain_24); + if (small) { + display.setFont(ArialMT_Plain_16); + } else { + display.setFont(ArialMT_Plain_24); + } display.drawString(32, 12, ln1); display.drawString(32, 36, ln2); display.display(); diff --git a/examples/C02_PM_SHT_OLED_WIFI/C02_PM_SHT_OLED_WIFI.ino b/examples/C02_PM_SHT_OLED_WIFI/C02_PM_SHT_OLED_WIFI.ino index 20d9dd5..4b33bbf 100644 --- a/examples/C02_PM_SHT_OLED_WIFI/C02_PM_SHT_OLED_WIFI.ino +++ b/examples/C02_PM_SHT_OLED_WIFI/C02_PM_SHT_OLED_WIFI.ino @@ -17,7 +17,7 @@ void setup(){ display.init(); display.flipScreenVertically(); - showTextRectangle("Init", String(ESP.getChipId(),HEX)); + showTextRectangle("Init", String(ESP.getChipId(),HEX),true); ag.PMS_Init(); ag.CO2_Init(); @@ -32,11 +32,11 @@ void loop(){ int CO2 = ag.getCO2_Raw(); TMP_RH result = ag.periodicFetchData(); - showTextRectangle(String(result.t),String(result.rh)+"%"); + showTextRectangle(String(result.t),String(result.rh)+"%",false); delay(2000); - showTextRectangle("PM2",String(PM2)); + showTextRectangle("PM2",String(PM2),false); delay(2000); - showTextRectangle("CO2",String(CO2)); + showTextRectangle("CO2",String(CO2),false); delay(2000); // send payload @@ -57,10 +57,14 @@ void loop(){ } // DISPLAY -void showTextRectangle(String ln1, String ln2) { +void showTextRectangle(String ln1, String ln2, boolean small) { display.clear(); display.setTextAlignment(TEXT_ALIGN_LEFT); - display.setFont(ArialMT_Plain_24); + if (small) { + display.setFont(ArialMT_Plain_16); + } else { + display.setFont(ArialMT_Plain_24); + } display.drawString(32, 12, ln1); display.drawString(32, 36, ln2); display.display(); diff --git a/examples/PM_OLED_WIFI/PM_OLED_WIFI.ino b/examples/PM_OLED_WIFI/PM_OLED_WIFI.ino new file mode 100644 index 0000000..671d88f --- /dev/null +++ b/examples/PM_OLED_WIFI/PM_OLED_WIFI.ino @@ -0,0 +1,78 @@ +#include +#include +#include +#include + +#include +#include "SSD1306Wire.h" + +AirGradient ag = AirGradient(); + +SSD1306Wire display(0x3c, SDA, SCL); + +String APIROOT = "http://hw.airgradient.com/"; + +void setup(){ + Serial.begin(9600); + + display.init(); + display.flipScreenVertically(); + showTextRectangle("Init", String(ESP.getChipId(),HEX),true); + + ag.PMS_Init(); + + connectToWifi(); + delay(2000); +} + +void loop(){ + int PM = ag.getPM2_Raw(); + showTextRectangle("PM2",String(PM),false); + + // send payload + String payload = "{\"pm02\":" + String(PM) + ",\"wifi\":" + String(WiFi.RSSI()) + "}"; + Serial.println(payload); + String POSTURL = APIROOT + "sensors/airgradient:" + String(ESP.getChipId(),HEX) + "/measures"; + Serial.println(POSTURL); + HTTPClient http; + http.begin(POSTURL); + http.addHeader("content-type", "application/json"); + int httpCode = http.POST(payload); + String response = http.getString(); + Serial.println(httpCode); + Serial.println(response); + http.end(); + + delay(30000); +} + +// DISPLAY +void showTextRectangle(String ln1, String ln2, boolean small) { + display.clear(); + display.setTextAlignment(TEXT_ALIGN_LEFT); + if (small) { + display.setFont(ArialMT_Plain_16); + } else { + display.setFont(ArialMT_Plain_24); + } + display.drawString(32, 12, ln1); + display.drawString(32, 36, ln2); + display.display(); +} + + + +// Wifi Manager +void connectToWifi(){ + WiFiManager wifiManager; + //WiFi.disconnect(); //to delete previous saved hotspot + String HOTSPOT = "AIRGRADIENT-"+String(ESP.getChipId(),HEX); + wifiManager.setTimeout(120); + if(!wifiManager.autoConnect((const char*)HOTSPOT.c_str())) { + //Serial.println("failed to connect and hit timeout"); + delay(3000); + ESP.restart(); + delay(5000); + } + +}