mirror of
https://github.com/airgradienthq/arduino.git
synced 2025-06-27 00:31:32 +02:00
Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
1a5ac64aa1 | |||
f170404c03 | |||
16a29b4646 | |||
bb3c57297e | |||
89e1d35a49 | |||
4f8bd0dbee | |||
ccfe271f0d |
BIN
AirGradient.zip
BIN
AirGradient.zip
Binary file not shown.
@ -1,18 +1,21 @@
|
|||||||
#include <AirGradient.h>
|
#include <AirGradient.h>
|
||||||
#include <Adafruit_GFX.h>
|
#include <Wire.h>
|
||||||
#include <Adafruit_SSD1306.h>
|
#include "SSD1306Wire.h"
|
||||||
|
|
||||||
AirGradient ag = AirGradient();
|
AirGradient ag = AirGradient();
|
||||||
#define OLED_RESET 0
|
|
||||||
Adafruit_SSD1306 display(OLED_RESET);
|
SSD1306Wire display(0x3c, SDA, SCL);
|
||||||
|
|
||||||
void setup(){
|
void setup(){
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
|
display.init();
|
||||||
|
display.flipScreenVertically();
|
||||||
|
showTextRectangle("Init", String(ESP.getChipId(),HEX),true);
|
||||||
|
|
||||||
ag.PMS_Init();
|
ag.PMS_Init();
|
||||||
ag.CO2_Init();
|
ag.CO2_Init();
|
||||||
ag.TMP_RH_Init(0x44); //check for SHT sensor with address 0x44
|
ag.TMP_RH_Init(0x44);
|
||||||
showTextRectangle("Init", String(ESP.getChipId(),HEX),"AirGradient");
|
|
||||||
delay(2000);
|
delay(2000);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -20,22 +23,24 @@ void loop(){
|
|||||||
int PM2 = ag.getPM2_Raw();
|
int PM2 = ag.getPM2_Raw();
|
||||||
int CO2 = ag.getCO2_Raw();
|
int CO2 = ag.getCO2_Raw();
|
||||||
TMP_RH result = ag.periodicFetchData();
|
TMP_RH result = ag.periodicFetchData();
|
||||||
showTextRectangle(String(result.t)+"c "+String(result.rh)+"%", "PM2: "+ String(ag.getPM2()), "CO2: "+String(ag.getCO2())+"");
|
showTextRectangle(String(result.t),String(result.rh)+"%",false);
|
||||||
delay(5000);
|
delay(2000);
|
||||||
|
showTextRectangle("PM2",String(PM2),false);
|
||||||
|
delay(2000);
|
||||||
|
showTextRectangle("CO2",String(CO2),false);
|
||||||
|
delay(2000);
|
||||||
}
|
}
|
||||||
|
|
||||||
// DISPLAY
|
// DISPLAY
|
||||||
void showTextRectangle(String ln1, String ln2, String ln3) {
|
void showTextRectangle(String ln1, String ln2, boolean small) {
|
||||||
display.clearDisplay();
|
display.clear();
|
||||||
display.setTextColor(WHITE);
|
display.setTextAlignment(TEXT_ALIGN_LEFT);
|
||||||
display.setTextSize(1);
|
if (small) {
|
||||||
display.setCursor(32,8);
|
display.setFont(ArialMT_Plain_16);
|
||||||
display.println(ln1);
|
} else {
|
||||||
display.setTextSize(1);
|
display.setFont(ArialMT_Plain_24);
|
||||||
display.setCursor(32,16);
|
}
|
||||||
display.println(ln2);
|
display.drawString(32, 12, ln1);
|
||||||
display.setTextSize(1);
|
display.drawString(32, 36, ln2);
|
||||||
display.setCursor(32,24);
|
|
||||||
display.println(ln3);
|
|
||||||
display.display();
|
display.display();
|
||||||
}
|
}
|
||||||
|
@ -1,23 +1,28 @@
|
|||||||
#include <AirGradient.h>
|
#include <AirGradient.h>
|
||||||
#include <Adafruit_GFX.h>
|
|
||||||
#include <Adafruit_SSD1306.h>
|
|
||||||
#include <WiFiManager.h>
|
#include <WiFiManager.h>
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <ESP8266HTTPClient.h>
|
#include <ESP8266HTTPClient.h>
|
||||||
|
|
||||||
|
#include <Wire.h>
|
||||||
|
#include "SSD1306Wire.h"
|
||||||
|
|
||||||
AirGradient ag = AirGradient();
|
AirGradient ag = AirGradient();
|
||||||
#define OLED_RESET 0
|
|
||||||
Adafruit_SSD1306 display(OLED_RESET);
|
SSD1306Wire display(0x3c, SDA, SCL);
|
||||||
|
|
||||||
String APIROOT = "http://hw.airgradient.com/";
|
String APIROOT = "http://hw.airgradient.com/";
|
||||||
|
|
||||||
void setup(){
|
void setup(){
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
|
|
||||||
|
display.init();
|
||||||
|
display.flipScreenVertically();
|
||||||
|
showTextRectangle("Init", String(ESP.getChipId(),HEX),true);
|
||||||
|
|
||||||
ag.PMS_Init();
|
ag.PMS_Init();
|
||||||
ag.CO2_Init();
|
ag.CO2_Init();
|
||||||
ag.TMP_RH_Init(0x44); //check for SHT sensor with address 0x44
|
ag.TMP_RH_Init(0x44);
|
||||||
showTextRectangle("Init", String(ESP.getChipId(),HEX),"AirGradient");
|
|
||||||
connectToWifi();
|
connectToWifi();
|
||||||
delay(2000);
|
delay(2000);
|
||||||
}
|
}
|
||||||
@ -26,7 +31,13 @@ void loop(){
|
|||||||
int PM2 = ag.getPM2_Raw();
|
int PM2 = ag.getPM2_Raw();
|
||||||
int CO2 = ag.getCO2_Raw();
|
int CO2 = ag.getCO2_Raw();
|
||||||
TMP_RH result = ag.periodicFetchData();
|
TMP_RH result = ag.periodicFetchData();
|
||||||
showTextRectangle(String(result.t)+"c "+String(result.rh)+"%", "PM2: "+ String(PM2), "CO2: "+String(CO2)+"");
|
|
||||||
|
showTextRectangle(String(result.t),String(result.rh)+"%",false);
|
||||||
|
delay(2000);
|
||||||
|
showTextRectangle("PM2",String(PM2),false);
|
||||||
|
delay(2000);
|
||||||
|
showTextRectangle("CO2",String(CO2),false);
|
||||||
|
delay(2000);
|
||||||
|
|
||||||
// send payload
|
// send payload
|
||||||
String payload = "{\"pm02\":" + String(ag.getPM2()) + ",\"wifi\":" + String(WiFi.RSSI()) + ",\"rco2\":" + String(ag.getCO2()) + ",\"atmp\":" + String(result.t) + ",\"rhum\":" + String(result.rh) + "}";
|
String payload = "{\"pm02\":" + String(ag.getPM2()) + ",\"wifi\":" + String(WiFi.RSSI()) + ",\"rco2\":" + String(ag.getCO2()) + ",\"atmp\":" + String(result.t) + ",\"rhum\":" + String(result.rh) + "}";
|
||||||
@ -42,29 +53,27 @@ void loop(){
|
|||||||
Serial.println(response);
|
Serial.println(response);
|
||||||
http.end();
|
http.end();
|
||||||
|
|
||||||
delay(15000);
|
delay(2000);
|
||||||
}
|
}
|
||||||
|
|
||||||
// DISPLAY
|
// DISPLAY
|
||||||
void showTextRectangle(String ln1, String ln2, String ln3) {
|
void showTextRectangle(String ln1, String ln2, boolean small) {
|
||||||
display.clearDisplay();
|
display.clear();
|
||||||
display.setTextColor(WHITE);
|
display.setTextAlignment(TEXT_ALIGN_LEFT);
|
||||||
display.setTextSize(1);
|
if (small) {
|
||||||
display.setCursor(32,8);
|
display.setFont(ArialMT_Plain_16);
|
||||||
display.println(ln1);
|
} else {
|
||||||
display.setTextSize(1);
|
display.setFont(ArialMT_Plain_24);
|
||||||
display.setCursor(32,16);
|
}
|
||||||
display.println(ln2);
|
display.drawString(32, 12, ln1);
|
||||||
display.setTextSize(1);
|
display.drawString(32, 36, ln2);
|
||||||
display.setCursor(32,24);
|
|
||||||
display.println(ln3);
|
|
||||||
display.display();
|
display.display();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wifi Manager
|
// Wifi Manager
|
||||||
void connectToWifi(){
|
void connectToWifi(){
|
||||||
WiFiManager wifiManager;
|
WiFiManager wifiManager;
|
||||||
//chWiFi.disconnect(); //to delete previous saved hotspot
|
//WiFi.disconnect(); //to delete previous saved hotspot
|
||||||
String HOTSPOT = "AIRGRADIENT-"+String(ESP.getChipId(),HEX);
|
String HOTSPOT = "AIRGRADIENT-"+String(ESP.getChipId(),HEX);
|
||||||
wifiManager.setTimeout(120);
|
wifiManager.setTimeout(120);
|
||||||
if(!wifiManager.autoConnect((const char*)HOTSPOT.c_str())) {
|
if(!wifiManager.autoConnect((const char*)HOTSPOT.c_str())) {
|
||||||
|
78
examples/PM_OLED_WIFI/PM_OLED_WIFI.ino
Normal file
78
examples/PM_OLED_WIFI/PM_OLED_WIFI.ino
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
#include <AirGradient.h>
|
||||||
|
#include <WiFiManager.h>
|
||||||
|
#include <ESP8266WiFi.h>
|
||||||
|
#include <ESP8266HTTPClient.h>
|
||||||
|
|
||||||
|
#include <Wire.h>
|
||||||
|
#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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
name=AirGradient Air Quality Sensor
|
name=AirGradient Air Quality Sensor
|
||||||
version=1.0.0
|
version=1.3.3
|
||||||
author=AirGradient <support@airgradient.com>
|
author=AirGradient <support@airgradient.com>
|
||||||
maintainer=AirGradient <support@airgradient.com>
|
maintainer=AirGradient <support@airgradient.com>
|
||||||
sentence=ESP8266 library for an air quality sensor featuring PM2.5, CO2, Temperature and Humidity with OLED display.
|
sentence=ESP8266 library for an air quality sensor featuring PM2.5, CO2, Temperature and Humidity with OLED display.
|
||||||
|
Reference in New Issue
Block a user