Skip to content

Instantly share code, notes, and snippets.

@auriza
Created February 18, 2022 04:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save auriza/02d564af1073875cee1c33df8a0baa34 to your computer and use it in GitHub Desktop.
Save auriza/02d564af1073875cee1c33df8a0baa34 to your computer and use it in GitHub Desktop.
/* https://thingspeak.com/channels/1655247
TODO preserve energy:
- ccs.setDriveMode(3)
- nWAKE pin
- ESP8266 deep sleep
*/
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <Adafruit_BME680.h>
#include <SparkFunCCS811.h>
//#define DEBUG
Adafruit_BME680 bme;
CCS811 ccs(0x5A);
void setup() {
#ifdef DEBUG
Serial.begin(115200);
#endif
ccs.begin();
bme.begin();
WiFi.begin("Ilkomerz_GreenHouse", "ilkomgr33n1P8");
while (WiFi.status() != WL_CONNECTED)
delay(500);
}
void loop() {
bme.performReading();
ccs.setEnvironmentalData(bme.humidity, bme.temperature);
if (ccs.dataAvailable())
ccs.readAlgorithmResults();
#ifdef DEBUG
Serial.print(bme.temperature); Serial.print("'C, ");
Serial.print(bme.humidity); Serial.print("%, ");
Serial.print(bme.pressure/100.0); Serial.print(" hPa, ");
Serial.print(bme.gas_resistance/1000.0); Serial.println(" kohm");
Serial.print(ccs.getCO2()); Serial.print(" ppm CO2, ");
Serial.print(ccs.getTVOC()); Serial.println(" ppb TVOC");
#endif
send_data();
delay(60000);
}
void send_data() {
WiFiClient client;
HTTPClient http;
http.begin(client, "http://api.thingspeak.com/update");
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
int rc = http.POST("api_key=13D0VN2KL4SFWDH5&field1=" + String(bme.temperature) + "&field2=" + bme.humidity + "&field3=" + bme.pressure/100.0 + "&field4=" + bme.gas_resistance/1000.0 + "&field5=" + ccs.getCO2() + "&field6=" + ccs.getTVOC());
http.end();
#ifdef DEBUG
Serial.print("HTTP "); Serial.println(rc);
#endif
if (rc == 302) {
http.begin(client, "http://1.1.1.3/ac_portal/login.php");
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
http.POST("opr=pwdLogin&userName=krs002&pwd=krs2015");
http.end();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment