Compare commits
10 commits
Author | SHA1 | Date | |
---|---|---|---|
Admar Schoonen | b9f90c2db2 | ||
Admar Schoonen | f8d25822ce | ||
Admar Schoonen | 2966bb7d84 | ||
Admar Schoonen | 87c76e945f | ||
Admar Schoonen | 1ed29953fe | ||
Admar Schoonen | 6c360d9473 | ||
Admar Schoonen | e413703196 | ||
Admar Schoonen | 6926d35baf | ||
Admar Schoonen | ba7906ad9f | ||
Admar Schoonen | 25dd53116c |
235
Claire.ino
235
Claire.ino
|
@ -2,7 +2,15 @@
|
||||||
#define HW_PROTO_PAPER 1
|
#define HW_PROTO_PAPER 1
|
||||||
#define HW_PROTO_V1 2
|
#define HW_PROTO_V1 2
|
||||||
|
|
||||||
#include <WiFiManager.h> // https://github.com/admarschoonen/WiFiManager
|
#ifndef LED_BUILTIN
|
||||||
|
#define LED_BUILTIN 2
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef BUTTON_BUILTIN
|
||||||
|
#define BUTTON_BUILTIN 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <WiFiManager-esp32.h> // https://github.com/admarschoonen/WiFiManager
|
||||||
#include <dESPatch.h>
|
#include <dESPatch.h>
|
||||||
|
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
|
@ -12,6 +20,13 @@
|
||||||
#include <Adafruit_NeoPixel.h>
|
#include <Adafruit_NeoPixel.h>
|
||||||
#include "bsec.h"
|
#include "bsec.h"
|
||||||
|
|
||||||
|
#include "soc/soc.h"
|
||||||
|
#include "soc/rtc_cntl_reg.h"
|
||||||
|
|
||||||
|
#ifndef LED_BUILTIN
|
||||||
|
#define LED_BUILTIN 2
|
||||||
|
#endif
|
||||||
|
|
||||||
#define NUM_LEDS_PROTO_PAPER 93
|
#define NUM_LEDS_PROTO_PAPER 93
|
||||||
#define DATA_PIN_PROTO_PAPER 5
|
#define DATA_PIN_PROTO_PAPER 5
|
||||||
#define CONNECT_SW_PIN_PROTO_PAPER BUTTON_BUILTIN
|
#define CONNECT_SW_PIN_PROTO_PAPER BUTTON_BUILTIN
|
||||||
|
@ -30,6 +45,7 @@ static int AQI_LED = 0;
|
||||||
static int POLLEN_LED = 0;
|
static int POLLEN_LED = 0;
|
||||||
static int IAQI_LED = 0;
|
static int IAQI_LED = 0;
|
||||||
static int CONNECT_SW_PIN = 0;
|
static int CONNECT_SW_PIN = 0;
|
||||||
|
static int LIGHT_PIN = 0;
|
||||||
|
|
||||||
#define SHOW_AQI_LED
|
#define SHOW_AQI_LED
|
||||||
#define SHOW_POLLEN_LED
|
#define SHOW_POLLEN_LED
|
||||||
|
@ -40,14 +56,25 @@ static int CONNECT_SW_PIN = 0;
|
||||||
Adafruit_NeoPixel leds_rgb_proto_paper(NUM_LEDS_PROTO_PAPER, DATA_PIN_PROTO_PAPER, NEO_GRB + NEO_KHZ800);
|
Adafruit_NeoPixel leds_rgb_proto_paper(NUM_LEDS_PROTO_PAPER, DATA_PIN_PROTO_PAPER, NEO_GRB + NEO_KHZ800);
|
||||||
Adafruit_NeoPixel leds_rgbw_proto_v1(NUM_LEDS_PROTO_V1, DATA_PIN_PROTO_V1, NEO_RGBW + NEO_KHZ800);
|
Adafruit_NeoPixel leds_rgbw_proto_v1(NUM_LEDS_PROTO_V1, DATA_PIN_PROTO_V1, NEO_RGBW + NEO_KHZ800);
|
||||||
|
|
||||||
|
const uint8_t bsec_config_iaq[] = {
|
||||||
|
#include "config/generic_33v_3s_4d/bsec_iaq.txt"
|
||||||
|
};
|
||||||
|
|
||||||
|
static int ledMapPrecipitation[12] = {0};
|
||||||
|
static int ledMapPAQI[12] = {0};
|
||||||
|
static int ledMapUVI = 0;
|
||||||
|
static int ledMapPollen = 0;
|
||||||
|
static int ledMapIAQI = 0;
|
||||||
|
static int ledMapAQI = 0;
|
||||||
|
|
||||||
#define SEALEVELPRESSURE_HPA (1013.25)
|
#define SEALEVELPRESSURE_HPA (1013.25)
|
||||||
#define BME_CS 5
|
#define BME_CS 5
|
||||||
String output;
|
String output;
|
||||||
Bsec iaqSensor;
|
Bsec iaqSensor;
|
||||||
|
|
||||||
static HTTPClient http;
|
static HTTPClient http;
|
||||||
static const String baseUrlAQI = "http://target.luon.net:2356//forecast?&metrics=PAQI&metrics=AQI&metrics=pollen&metrics=UVI";
|
static const String baseUrlAQI = "https://sinoptik.luon.net/forecast?metrics=PAQI&metrics=AQI&metrics=pollen&metrics=UVI";
|
||||||
static const String baseUrlPrecipitation = "http://target.luon.net:2356//forecast?metrics=precipitation";
|
static const String baseUrlPrecipitation = "https://sinoptik.luon.net/forecast?metrics=precipitation";
|
||||||
|
|
||||||
static int hw_variant = 0;
|
static int hw_variant = 0;
|
||||||
|
|
||||||
|
@ -55,26 +82,39 @@ WiFiManager wifiManager;
|
||||||
DESPatch dESPatch;
|
DESPatch dESPatch;
|
||||||
const char* root_ca = \
|
const char* root_ca = \
|
||||||
"-----BEGIN CERTIFICATE-----\n" \
|
"-----BEGIN CERTIFICATE-----\n" \
|
||||||
"MIIDSjCCAjKgAwIBAgIQRK+wgNajJ7qJMDmGLvhAazANBgkqhkiG9w0BAQUFADA/\n" \
|
"MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw\n" \
|
||||||
"MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT\n" \
|
"TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh\n" \
|
||||||
"DkRTVCBSb290IENBIFgzMB4XDTAwMDkzMDIxMTIxOVoXDTIxMDkzMDE0MDExNVow\n" \
|
"cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4\n" \
|
||||||
"PzEkMCIGA1UEChMbRGlnaXRhbCBTaWduYXR1cmUgVHJ1c3QgQ28uMRcwFQYDVQQD\n" \
|
"WhcNMzUwNjA0MTEwNDM4WjBPMQsw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QDLHYGmkgJykIrGF1XIpu+ILlaS/V9lZL\n" \
|
||||||
|
"ubhzEFnTIZd+50xx+7LSYK05qAvqFyFWhfFQDlnrzuBZ6brJFe+GnY+EgPbk6ZGQ\n" \
|
||||||
|
"3BebYhtF8GaV0nxvwuo77x/Py9auJ/GpsMiu/X1+mvoiBOv/2X/qkSsisRcOj/KK\n" \
|
||||||
|
"NFtY2PwByVS5uCbMiogziUwthDyC3+6WVwW6LLv3xLfHTjuCvjHIInNzktHCgKQ5\n" \
|
||||||
|
"ORAzI4JMPJ+GslWYHb4phowim57iaztXOoJwTdwJx4nLCgdNbOhdjsnvzqvHu7Ur\n" \
|
||||||
|
"TkXWStAmzOVyyghqpZXjFaH3pO3JLF+l+/+sKAIuvtd7u+Nxe5AW0wdeRlN8NwdC\n" \
|
||||||
|
"jNPElpzVmbUq4JUagEiuTDkHzsxHpFKVK7q4+63SM1N95R1NbdWhscdCb+ZAJzVc\n" \
|
||||||
|
"oyi3B43njTOQ5yOf+1CceWxG1bQVs5ZufpsMljq4Ui0/1lvh+wjChP4kqKOJ2qxq\n" \
|
||||||
|
"4RgqsahDYVvTH9w7jXbyLeiNdd8XM2w9U/t7y0Ff/9yi0GE44Za4rF2LN9d11TPA\n" \
|
||||||
|
"mRGunUHBcnWEvgJBQl9nJEiU0Zsnvgc/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57d\n" \
|
||||||
|
"emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=\n" \
|
||||||
"-----END CERTIFICATE-----\n";
|
"-----END CERTIFICATE-----\n";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const float location[] = {51.445466493287434, 5.515445691496135}; // Telefoonstraat, Eindhoven
|
const float location[] = {51.445466493287434, 5.515445691496135}; // Telefoonstraat, Eindhoven
|
||||||
const String address = "Telefoonstraat 18, Eindhoven";
|
const String address = "Telefoonstraat 18, Eindhoven";
|
||||||
|
|
||||||
|
@ -183,6 +223,8 @@ void parseJson(String * payload)
|
||||||
|
|
||||||
static void setup_pins_proto_paper(void)
|
static void setup_pins_proto_paper(void)
|
||||||
{
|
{
|
||||||
|
int n = 0;
|
||||||
|
|
||||||
BUIENRADAR_START_LED = 32;
|
BUIENRADAR_START_LED = 32;
|
||||||
BUIENRADAR_SKIP_LED = 1;
|
BUIENRADAR_SKIP_LED = 1;
|
||||||
BUIENRADAR_NUM_LEDS = 12;
|
BUIENRADAR_NUM_LEDS = 12;
|
||||||
|
@ -198,10 +240,29 @@ static void setup_pins_proto_paper(void)
|
||||||
IAQI_LED = 88; // LED below center
|
IAQI_LED = 88; // LED below center
|
||||||
|
|
||||||
CONNECT_SW_PIN = CONNECT_SW_PIN_PROTO_PAPER;
|
CONNECT_SW_PIN = CONNECT_SW_PIN_PROTO_PAPER;
|
||||||
|
|
||||||
|
n = 0;
|
||||||
|
while (n < BUIENRADAR_NUM_LEDS) {
|
||||||
|
ledMapPrecipitation[n] = BUIENRADAR_START_LED + n * (BUIENRADAR_SKIP_LED + 1);
|
||||||
|
n = n + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
n = 0;
|
||||||
|
while (n < PAQI_NUM_LEDS) {
|
||||||
|
ledMapPAQI[n] = PAQI_START_LED + n * (PAQI_SKIP_LED + 1);
|
||||||
|
n = n + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ledMapAQI = AQI_LED;
|
||||||
|
ledMapUVI = UVI_LED;
|
||||||
|
ledMapPollen = POLLEN_LED;
|
||||||
|
ledMapIAQI = IAQI_LED;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setup_pins_proto_v1(void)
|
static void setup_pins_proto_v1(void)
|
||||||
{
|
{
|
||||||
|
int n = 0;
|
||||||
|
|
||||||
BUIENRADAR_START_LED = 0;
|
BUIENRADAR_START_LED = 0;
|
||||||
BUIENRADAR_SKIP_LED = 0;
|
BUIENRADAR_SKIP_LED = 0;
|
||||||
BUIENRADAR_NUM_LEDS = 12;
|
BUIENRADAR_NUM_LEDS = 12;
|
||||||
|
@ -216,6 +277,29 @@ static void setup_pins_proto_v1(void)
|
||||||
IAQI_LED = 25; // LED below center
|
IAQI_LED = 25; // LED below center
|
||||||
|
|
||||||
CONNECT_SW_PIN = CONNECT_SW_PIN_PROTO_V1;
|
CONNECT_SW_PIN = CONNECT_SW_PIN_PROTO_V1;
|
||||||
|
|
||||||
|
ledMapPrecipitation[0] = 11;
|
||||||
|
n = 1;
|
||||||
|
while (n < BUIENRADAR_NUM_LEDS) {
|
||||||
|
ledMapPrecipitation[n] = BUIENRADAR_START_LED + (n - 1) * (BUIENRADAR_SKIP_LED + 1);
|
||||||
|
n = n + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ledMapPAQI[0] = 23;
|
||||||
|
n = 1;
|
||||||
|
while (n < PAQI_NUM_LEDS) {
|
||||||
|
ledMapPAQI[n] = PAQI_START_LED + (n - 1) * (PAQI_SKIP_LED + 1);
|
||||||
|
n = n + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ledMapAQI = AQI_LED;
|
||||||
|
ledMapUVI = UVI_LED;
|
||||||
|
ledMapPollen = POLLEN_LED;
|
||||||
|
ledMapIAQI = IAQI_LED;
|
||||||
|
|
||||||
|
LIGHT_PIN = 34;
|
||||||
|
analogSetPinAttenuation(LIGHT_PIN, ADC_0db);
|
||||||
|
analogReadResolution(12);
|
||||||
}
|
}
|
||||||
|
|
||||||
void leds_clear(void) {
|
void leds_clear(void) {
|
||||||
|
@ -230,29 +314,29 @@ void leds_clear(void) {
|
||||||
|
|
||||||
int checkIaqSensorStatus(void)
|
int checkIaqSensorStatus(void)
|
||||||
{
|
{
|
||||||
if (iaqSensor.status != BSEC_OK) {
|
if (iaqSensor.bsecStatus != BSEC_OK) {
|
||||||
if (iaqSensor.status < BSEC_OK) {
|
if (iaqSensor.bsecStatus < BSEC_OK) {
|
||||||
output = "BSEC error code : " + String(iaqSensor.status);
|
output = "BSEC error code : " + String(iaqSensor.bsecStatus);
|
||||||
Serial.println(output);
|
Serial.println(output);
|
||||||
//for (;;);
|
//for (;;);
|
||||||
} else {
|
} else {
|
||||||
output = "BSEC warning code : " + String(iaqSensor.status);
|
output = "BSEC warning code : " + String(iaqSensor.bsecStatus);
|
||||||
Serial.println(output);
|
Serial.println(output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iaqSensor.bme680Status != BME680_OK) {
|
if (iaqSensor.bme68xStatus != BME68X_OK) {
|
||||||
if (iaqSensor.bme680Status < BME680_OK) {
|
if (iaqSensor.bme68xStatus < BME68X_OK) {
|
||||||
output = "BME680 error code : " + String(iaqSensor.bme680Status);
|
output = "BME680 error code : " + String(iaqSensor.bme68xStatus);
|
||||||
Serial.println(output);
|
Serial.println(output);
|
||||||
//for (;;);
|
//for (;;);
|
||||||
} else {
|
} else {
|
||||||
output = "BME680 warning code : " + String(iaqSensor.bme680Status);
|
output = "BME680 warning code : " + String(iaqSensor.bme68xStatus);
|
||||||
Serial.println(output);
|
Serial.println(output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return iaqSensor.bme680Status;
|
return iaqSensor.bme68xStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
void readSensors(void) {
|
void readSensors(void) {
|
||||||
|
@ -266,18 +350,25 @@ void readSensors(void) {
|
||||||
unsigned long time_trigger = millis();
|
unsigned long time_trigger = millis();
|
||||||
if (iaqSensor.run()) { // If new data is available
|
if (iaqSensor.run()) { // If new data is available
|
||||||
output = String(time_trigger);
|
output = String(time_trigger);
|
||||||
output += " ms, Traw: " + String(iaqSensor.rawTemperature);
|
output += " Sensor data: Traw: " + String(iaqSensor.rawTemperature);
|
||||||
output += " *C , P: " + String(iaqSensor.pressure);
|
output += " *C , P: " + String(iaqSensor.pressure);
|
||||||
output += " hPa, RHraw: " + String(iaqSensor.rawHumidity);
|
output += " hPa, RHraw: " + String(iaqSensor.rawHumidity);
|
||||||
output += " %, Rgas: " + String(iaqSensor.gasResistance);
|
output += " %, Rgas: " + String(iaqSensor.gasResistance);
|
||||||
output += " Ohm, IAQ: " + String(iaqSensor.iaq);
|
output += " Ohm, IAQ: " + String(iaqSensor.iaq);
|
||||||
output += ", accuracy: " + String(iaqSensor.iaqAccuracy);
|
output += ", accuracy: " + String(iaqSensor.iaqAccuracy);
|
||||||
output += ", Tcorr: " + String(iaqSensor.temperature);
|
output += ", Tcorr: " + String(iaqSensor.temperature);
|
||||||
output += " *C, RHcorr" + String(iaqSensor.humidity);
|
output += " *C, RHcorr: " + String(iaqSensor.humidity);
|
||||||
output += " %, IAQ static" + String(iaqSensor.staticIaq);
|
output += " %, IAQstatic: " + String(iaqSensor.staticIaq);
|
||||||
output += ", eCO2: " + String(iaqSensor.co2Equivalent);
|
output += ", eCO2: " + String(iaqSensor.co2Equivalent);
|
||||||
output += " ppm, eVOC: " + String(iaqSensor.breathVocEquivalent);
|
output += " ppm, eVOC: " + String(iaqSensor.breathVocEquivalent);
|
||||||
output += " ppm";
|
output += " ppm";
|
||||||
|
|
||||||
|
int light = 0;
|
||||||
|
for (int n = 0; n < 256; n++) {
|
||||||
|
light += analogRead(LIGHT_PIN);
|
||||||
|
}
|
||||||
|
light = (light + 128) >> 8;
|
||||||
|
output += ", light: " + String(light);
|
||||||
Serial.println(output);
|
Serial.println(output);
|
||||||
} else {
|
} else {
|
||||||
checkIaqSensorStatus();
|
checkIaqSensorStatus();
|
||||||
|
@ -304,25 +395,33 @@ void setup() {
|
||||||
unsigned long interval = 60; // By default check for updates every 60 seconds
|
unsigned long interval = 60; // By default check for updates every 60 seconds
|
||||||
int x;
|
int x;
|
||||||
|
|
||||||
|
WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); // Disable brownout; needed for some dev kits
|
||||||
|
|
||||||
// sanity check delay - allows reprogramming if accidently blowing power w/leds
|
// sanity check delay - allows reprogramming if accidently blowing power w/leds
|
||||||
delay(2000);
|
delay(2000);
|
||||||
|
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
Serial.println("buienradarklok starting");
|
Serial.println("buienradarklok starting");
|
||||||
|
|
||||||
|
http.setReuse(false);
|
||||||
|
|
||||||
SPI.begin();
|
SPI.begin();
|
||||||
iaqSensor.begin(BME_CS, SPI);
|
iaqSensor.begin(BME_CS, SPI);
|
||||||
String output = "\nBSEC library version " + String(iaqSensor.version.major) + "." + String(iaqSensor.version.minor) + "." + String(iaqSensor.version.major_bugfix) + "." + String(iaqSensor.version.minor_bugfix);
|
String output = "\nBSEC library version " + String(iaqSensor.version.major) + "." + String(iaqSensor.version.minor) + "." + String(iaqSensor.version.major_bugfix) + "." + String(iaqSensor.version.minor_bugfix);
|
||||||
Serial.println(output);
|
Serial.println(output);
|
||||||
x = checkIaqSensorStatus();
|
x = checkIaqSensorStatus();
|
||||||
|
|
||||||
if (x != BME680_OK) {
|
if (x != BME68X_OK) {
|
||||||
Serial.println(F("Could not find a valid BME680 sensor; assuming hw variant \"paper prototype\"!"));
|
Serial.println(F("Could not find a valid BME680 sensor; assuming hw variant \"paper prototype\"!"));
|
||||||
hw_variant = HW_PROTO_PAPER;
|
hw_variant = HW_PROTO_PAPER;
|
||||||
setup_pins_proto_paper();
|
setup_pins_proto_paper();
|
||||||
leds_rgb_proto_paper.begin(); // INITIALIZE NeoPixel strip object
|
leds_rgb_proto_paper.begin(); // INITIALIZE NeoPixel strip object
|
||||||
} else {
|
} else {
|
||||||
Serial.println(F("BME680 found; assuming hw variant \"proto v1\""));
|
Serial.println(F("BME680 found; assuming hw variant \"proto v1\""));
|
||||||
|
|
||||||
|
iaqSensor.setConfig(bsec_config_iaq);
|
||||||
|
iaqSensor.setTemperatureOffset(13.5f);
|
||||||
|
checkIaqSensorStatus();
|
||||||
|
|
||||||
hw_variant = HW_PROTO_V1;
|
hw_variant = HW_PROTO_V1;
|
||||||
setup_pins_proto_v1();
|
setup_pins_proto_v1();
|
||||||
|
@ -354,7 +453,7 @@ void setup() {
|
||||||
#ifndef DISABLE_WIFI
|
#ifndef DISABLE_WIFI
|
||||||
//wifiManager.resetSettings();
|
//wifiManager.resetSettings();
|
||||||
wifiManager.configure("Claire-", true, LED_BUILTIN, true, CONNECT_SW_PIN, false);
|
wifiManager.configure("Claire-", true, LED_BUILTIN, true, CONNECT_SW_PIN, false);
|
||||||
|
|
||||||
//fetches ssid and pass and tries to connect
|
//fetches ssid and pass and tries to connect
|
||||||
//if it does not connect it starts an access point
|
//if it does not connect it starts an access point
|
||||||
//and goes into a blocking loop awaiting configuration
|
//and goes into a blocking loop awaiting configuration
|
||||||
|
@ -435,17 +534,19 @@ void getPrecipitation(const float * location) {
|
||||||
|
|
||||||
url = baseUrlPrecipitation + "&lat=" + latS + "&lon=" + lonS;
|
url = baseUrlPrecipitation + "&lat=" + latS + "&lon=" + lonS;
|
||||||
|
|
||||||
|
Serial.print(millis());
|
||||||
|
Serial.print(" Retrieving precipitation from ");
|
||||||
Serial.println(url);
|
Serial.println(url);
|
||||||
|
|
||||||
http.begin(url);
|
http.begin(url, root_ca);
|
||||||
httpCode = http.GET();
|
httpCode = http.GET();
|
||||||
|
|
||||||
if (httpCode > 0) {
|
if (httpCode > 0) {
|
||||||
payload = http.getString();
|
payload = http.getString();
|
||||||
parseJson(&payload);
|
parseJson(&payload);
|
||||||
} else {
|
} else {
|
||||||
Serial.print(__func__);
|
Serial.print(millis());
|
||||||
Serial.print("(): got http code ");
|
Serial.print(" Got http code ");
|
||||||
Serial.println(httpCode);
|
Serial.println(httpCode);
|
||||||
}
|
}
|
||||||
http.end();
|
http.end();
|
||||||
|
@ -461,17 +562,19 @@ void getPrecipitation(const String address) {
|
||||||
|
|
||||||
url = baseUrlPrecipitation + "&address=" + a;
|
url = baseUrlPrecipitation + "&address=" + a;
|
||||||
|
|
||||||
|
Serial.print(millis());
|
||||||
|
Serial.print(" Retrieving precipitation from ");
|
||||||
Serial.println(url);
|
Serial.println(url);
|
||||||
|
|
||||||
http.begin(url);
|
http.begin(url, root_ca);
|
||||||
httpCode = http.GET();
|
httpCode = http.GET();
|
||||||
|
|
||||||
if (httpCode > 0) {
|
if (httpCode > 0) {
|
||||||
payload = http.getString();
|
payload = http.getString();
|
||||||
parseJson(&payload);
|
parseJson(&payload);
|
||||||
} else {
|
} else {
|
||||||
Serial.print(__func__);
|
Serial.print(millis());
|
||||||
Serial.print("(): got http code ");
|
Serial.print(" Got http code ");
|
||||||
Serial.println(httpCode);
|
Serial.println(httpCode);
|
||||||
}
|
}
|
||||||
http.end();
|
http.end();
|
||||||
|
@ -493,17 +596,19 @@ void getAQI(const float * location) {
|
||||||
|
|
||||||
url = baseUrlAQI + "&lat=" + latS + "&lon=" + lonS;
|
url = baseUrlAQI + "&lat=" + latS + "&lon=" + lonS;
|
||||||
|
|
||||||
|
Serial.print(millis());
|
||||||
|
Serial.print(" Retrieving AQI from ");
|
||||||
Serial.println(url);
|
Serial.println(url);
|
||||||
|
|
||||||
http.begin(url);
|
http.begin(url, root_ca);
|
||||||
httpCode = http.GET();
|
httpCode = http.GET();
|
||||||
|
|
||||||
if (httpCode > 0) {
|
if (httpCode > 0) {
|
||||||
payload = http.getString();
|
payload = http.getString();
|
||||||
parseJson(&payload);
|
parseJson(&payload);
|
||||||
} else {
|
} else {
|
||||||
Serial.print(__func__);
|
Serial.print(millis());
|
||||||
Serial.print("(): got http code ");
|
Serial.print(" Got http code ");
|
||||||
Serial.println(httpCode);
|
Serial.println(httpCode);
|
||||||
}
|
}
|
||||||
http.end();
|
http.end();
|
||||||
|
@ -519,17 +624,19 @@ void getAQI(const String address) {
|
||||||
|
|
||||||
url = baseUrlAQI + "&address=" + a;
|
url = baseUrlAQI + "&address=" + a;
|
||||||
|
|
||||||
|
Serial.print(millis());
|
||||||
|
Serial.print(" Retrieving AQI from ");
|
||||||
Serial.println(url);
|
Serial.println(url);
|
||||||
|
|
||||||
http.begin(url);
|
http.begin(url, root_ca);
|
||||||
httpCode = http.GET();
|
httpCode = http.GET();
|
||||||
|
|
||||||
if (httpCode > 0) {
|
if (httpCode > 0) {
|
||||||
payload = http.getString();
|
payload = http.getString();
|
||||||
parseJson(&payload);
|
parseJson(&payload);
|
||||||
} else {
|
} else {
|
||||||
Serial.print(__func__);
|
Serial.print(millis());
|
||||||
Serial.print("(): got http code ");
|
Serial.print(" Got http code ");
|
||||||
Serial.println(httpCode);
|
Serial.println(httpCode);
|
||||||
}
|
}
|
||||||
http.end();
|
http.end();
|
||||||
|
@ -584,18 +691,26 @@ static int colormap(float x) {
|
||||||
float colormapIaqi(void)
|
float colormapIaqi(void)
|
||||||
{
|
{
|
||||||
float x = 0.0f;
|
float x = 0.0f;
|
||||||
float iaqi = iaqSensor.iaq;
|
float iaqi = iaqSensor.staticIaq;
|
||||||
|
|
||||||
if (iaqi <= 50.0f) {
|
if (iaqi <= 50.0f) {
|
||||||
x = 1.0f; // Excellent
|
x = 1.0f; // Excellent
|
||||||
} else if (iaqi <= 100.0f) {
|
} else if (iaqi <= 100.0f) {
|
||||||
x = 2.0f; // Good
|
x = 2.0f; // Good
|
||||||
|
} else if (iaqi <= 125.0f) {
|
||||||
|
x = 4.0f;
|
||||||
} else if (iaqi <= 150.0f) {
|
} else if (iaqi <= 150.0f) {
|
||||||
x = 4.0f; // Lightly polluted
|
x = 4.0f; // Lightly polluted
|
||||||
|
} else if (iaqi <= 175.0f) {
|
||||||
|
x = 5.0f;
|
||||||
} else if (iaqi <= 200.0f) {
|
} else if (iaqi <= 200.0f) {
|
||||||
x = 7.0f; // Moderately polluted
|
x = 6.0f; // Moderately polluted
|
||||||
|
} else if (iaqi <= 225.0f) {
|
||||||
|
x = 7.0f;
|
||||||
} else if (iaqi <= 250.0f) {
|
} else if (iaqi <= 250.0f) {
|
||||||
x = 9.0f; // Heavily polluted
|
x = 8.0f; // Heavily polluted
|
||||||
|
} else if (iaqi <= 300.0f) {
|
||||||
|
x = 9.0f;
|
||||||
} else if (iaqi <= 350.0f) {
|
} else if (iaqi <= 350.0f) {
|
||||||
x = 10.0f; // Severely polluted
|
x = 10.0f; // Severely polluted
|
||||||
} else {
|
} else {
|
||||||
|
@ -705,7 +820,7 @@ static void updateLeds(void) {
|
||||||
b = (color & 0x0000FF);
|
b = (color & 0x0000FF);
|
||||||
w = (color & 0xFF000000) >> 24;
|
w = (color & 0xFF000000) >> 24;
|
||||||
|
|
||||||
ledsSetPixelColor(ledIdx, r, g, b);
|
ledsSetPixelColor(ledMapPAQI[ledCount], r, g, b);
|
||||||
ledIdx = ledIdx + PAQI_SKIP_LED + 1;
|
ledIdx = ledIdx + PAQI_SKIP_LED + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -727,7 +842,7 @@ static void updateLeds(void) {
|
||||||
b = (color & 0x0000FF);
|
b = (color & 0x0000FF);
|
||||||
w = (color & 0xFF000000) >> 24;
|
w = (color & 0xFF000000) >> 24;
|
||||||
|
|
||||||
ledsSetPixelColor(ledIdx, r, g, b);
|
ledsSetPixelColor(ledMapPAQI[ledCount], r, g, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef SHOW_AQI_LED
|
#ifdef SHOW_AQI_LED
|
||||||
|
@ -813,6 +928,7 @@ static void updateLeds(void) {
|
||||||
g = (color & 0x00FF00) >> 8;
|
g = (color & 0x00FF00) >> 8;
|
||||||
b = (color & 0x0000FF);
|
b = (color & 0x0000FF);
|
||||||
|
|
||||||
|
ledsSetPixelColor(ledMapPrecipitation[ledCount], r, g, b);
|
||||||
ledIdx = ledIdx + BUIENRADAR_SKIP_LED + 1;
|
ledIdx = ledIdx + BUIENRADAR_SKIP_LED + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -832,7 +948,7 @@ static void updateLeds(void) {
|
||||||
r = (color & 0xFF0000) >> 16;
|
r = (color & 0xFF0000) >> 16;
|
||||||
g = (color & 0x00FF00) >> 8;
|
g = (color & 0x00FF00) >> 8;
|
||||||
b = (color & 0x0000FF);
|
b = (color & 0x0000FF);
|
||||||
ledsSetPixelColor(ledIdx, r, g, b);
|
ledsSetPixelColor(ledMapPrecipitation[ledCount], r, g, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
ledsSetPixelColor(IAQI_LED, r, g, b);
|
ledsSetPixelColor(IAQI_LED, r, g, b);
|
||||||
|
@ -896,6 +1012,19 @@ void loop(void) {
|
||||||
firstTime = false;
|
firstTime = false;
|
||||||
|
|
||||||
#ifndef DISABLE_WIFI
|
#ifndef DISABLE_WIFI
|
||||||
|
if (WiFi.status() != WL_CONNECTED) {
|
||||||
|
Serial.print(millis());
|
||||||
|
Serial.print(" wifi status error: ");
|
||||||
|
Serial.print(WiFi.status());
|
||||||
|
Serial.print("; expected: ");
|
||||||
|
Serial.println(WL_CONNECTED);
|
||||||
|
bool result = WiFi.reconnect();
|
||||||
|
Serial.print(millis());
|
||||||
|
Serial.print(" reconnecting result: ");
|
||||||
|
Serial.print(result);
|
||||||
|
Serial.print("; expected: ");
|
||||||
|
Serial.println(ESP_OK);
|
||||||
|
}
|
||||||
getPrecipitation(address);
|
getPrecipitation(address);
|
||||||
|
|
||||||
if (counter == 0) {
|
if (counter == 0) {
|
||||||
|
|
Loading…
Reference in a new issue