From f3f41c0d3bce7414ab9aa37f451089a525bc2570 Mon Sep 17 00:00:00 2001 From: uptoratlen <80213345+uptoratlen@users.noreply.github.com> Date: Wed, 4 Aug 2021 20:58:03 +0200 Subject: [PATCH 1/5] Mqtt anonymous access option added --- src/Config.h | 3 +++ src/esp8266-vindriktning-particle-sensor.ino | 20 +++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Config.h b/src/Config.h index 4904b11..1e4d347 100644 --- a/src/Config.h +++ b/src/Config.h @@ -8,12 +8,14 @@ namespace Config { char username[24] = ""; char password[24] = ""; + char mqtt_anonymous[2] = ""; void save() { DynamicJsonDocument json(512); json["mqtt_server"] = mqtt_server; json["username"] = username; json["password"] = password; + json["mqtt_anonymous"] = mqtt_anonymous; File configFile = SPIFFS.open("/config.json", "w"); if (!configFile) { @@ -41,6 +43,7 @@ namespace Config { strcpy(mqtt_server, json["mqtt_server"]); strcpy(username, json["username"]); strcpy(password, json["password"]); + strcpy(mqtt_anonymous, json["mqtt_anonymous"]); } } } diff --git a/src/esp8266-vindriktning-particle-sensor.ino b/src/esp8266-vindriktning-particle-sensor.ino index 0265ac2..8173699 100644 --- a/src/esp8266-vindriktning-particle-sensor.ino +++ b/src/esp8266-vindriktning-particle-sensor.ino @@ -18,9 +18,12 @@ WiFiManager wifiManager; WiFiClient wifiClient; PubSubClient mqttClient; +WiFiManagerParameter p_lineBreak_text_title("

MQTT Server Config:

"); WiFiManagerParameter custom_mqtt_server("server", "mqtt server", Config::mqtt_server, sizeof(Config::mqtt_server)); WiFiManagerParameter custom_mqtt_user("user", "MQTT username", Config::username, sizeof(Config::username)); WiFiManagerParameter custom_mqtt_pass("pass", "MQTT password", Config::password, sizeof(Config::password)); +WiFiManagerParameter p_lineBreak_text_mqtt_anonymous("

MQTT Anonymous? (bypass user/pass):

"); +WiFiManagerParameter custom_mqtt_anonymous("mqtt_anónymous", "MQTT anonymous", "T", 2, "type=\"checkbox\""); uint32_t lastMqttConnectionAttempt = 0; const uint16_t mqttConnectionInterval = 60000; // 1 minute = 60 seconds = 60000 milliseconds @@ -141,9 +144,12 @@ void setupWifi() { wifiManager.setDebugOutput(false); wifiManager.setSaveConfigCallback(saveConfigCallback); + wifiManager.addParameter(&p_lineBreak_text_title); wifiManager.addParameter(&custom_mqtt_server); wifiManager.addParameter(&custom_mqtt_user); wifiManager.addParameter(&custom_mqtt_pass); + wifiManager.addParameter(&p_lineBreak_text_mqtt_anonymous); + wifiManager.addParameter(&custom_mqtt_anonymous); WiFi.hostname(identifier); wifiManager.autoConnect(identifier); @@ -152,6 +158,7 @@ void setupWifi() { strcpy(Config::mqtt_server, custom_mqtt_server.getValue()); strcpy(Config::username, custom_mqtt_user.getValue()); strcpy(Config::password, custom_mqtt_pass.getValue()); + strcpy(Config::mqtt_anonymous, custom_mqtt_anonymous.getValue()); if (shouldSaveConfig) { Config::save(); @@ -171,13 +178,24 @@ void resetWifiSettingsAndReboot() { void mqttReconnect() { for (uint8_t attempt = 0; attempt < 3; ++attempt) { - if (mqttClient.connect(identifier, Config::username, Config::password, MQTT_TOPIC_AVAILABILITY, 1, true, AVAILABILITY_OFFLINE)) { + if (strcmp(Config::mqtt_anonymous, "T") == 0) { + if (mqttClient.connect(identifier, MQTT_TOPIC_AVAILABILITY, 1, true, AVAILABILITY_OFFLINE)) { mqttClient.publish(MQTT_TOPIC_AVAILABILITY, AVAILABILITY_ONLINE, true); publishAutoConfig(); // Make sure to subscribe after polling the status so that we never execute commands with the default data mqttClient.subscribe(MQTT_TOPIC_COMMAND); break; + } + } else{ + if (mqttClient.connect(identifier, Config::username, Config::password, MQTT_TOPIC_AVAILABILITY, 1, true, AVAILABILITY_OFFLINE)) { + mqttClient.publish(MQTT_TOPIC_AVAILABILITY, AVAILABILITY_ONLINE, true); + publishAutoConfig(); + + // Make sure to subscribe after polling the status so that we never execute commands with the default data + mqttClient.subscribe(MQTT_TOPIC_COMMAND); + break; + } } delay(5000); } From b292ffecc47c448e178bc83e64c697bcd473b0f8 Mon Sep 17 00:00:00 2001 From: uptoratlen <80213345+uptoratlen@users.noreply.github.com> Date: Fri, 20 Aug 2021 11:40:57 +0200 Subject: [PATCH 2/5] Added info on PM 2.5 from Ikea manual --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 46f6746..b97abff 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,11 @@ Therefore, to add Wi-Fi connectivity, we just need to also listen to the TX of t The Ikea uC will do all that polling stuff for us. As reported in #16, the transitions from Green to Yellow and Yellow to Red in the Ikea firmware are at around 30 and 100μg/m³. +Info from (https://www.ikea.com/us/en/manuals/vindriktning-air-quality-sensor__AA-2289325-1_pub.pdf): +Green: 0-35 / Good + Low +Amber: 36-85 / OK + Medium +Red: 86- / Not good + High +Pulsing: Startup Mode ## ToDo From 698f7a98d9e4ab1a6be1bd6b578c56a944205c82 Mon Sep 17 00:00:00 2001 From: uptoratlen <80213345+uptoratlen@users.noreply.github.com> Date: Fri, 20 Aug 2021 11:55:51 +0200 Subject: [PATCH 3/5] Update README.md Table looks nicer --- README.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b97abff..3c89c75 100644 --- a/README.md +++ b/README.md @@ -95,11 +95,14 @@ Therefore, to add Wi-Fi connectivity, we just need to also listen to the TX of t The Ikea uC will do all that polling stuff for us. As reported in #16, the transitions from Green to Yellow and Yellow to Red in the Ikea firmware are at around 30 and 100μg/m³. +| Color | Value | Comment | +| ------------- |:-------------:| -----:| +| Green | 0-35 | Good + Low | +| Amber | 36-85 | Ok + Medium | +| Red | 86- | Not good + High | +| Pulsing | --- | Startup mode | + Info from (https://www.ikea.com/us/en/manuals/vindriktning-air-quality-sensor__AA-2289325-1_pub.pdf): -Green: 0-35 / Good + Low -Amber: 36-85 / OK + Medium -Red: 86- / Not good + High -Pulsing: Startup Mode ## ToDo From 0208082bd8bbd15ebe351be4919405dfab2e03d0 Mon Sep 17 00:00:00 2001 From: uptoratlen <80213345+uptoratlen@users.noreply.github.com> Date: Fri, 20 Aug 2021 12:39:30 +0200 Subject: [PATCH 4/5] Update README.md Added startup info --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3c89c75..801e56a 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,7 @@ As reported in #16, the transitions from Green to Yellow and Yellow to Red in th | Green | 0-35 | Good + Low | | Amber | 36-85 | Ok + Medium | | Red | 86- | Not good + High | -| Pulsing | --- | Startup mode | +| Pulsing | --- | Startup mode for 10 seconds| Info from (https://www.ikea.com/us/en/manuals/vindriktning-air-quality-sensor__AA-2289325-1_pub.pdf): From 508fa5ad533183d5b4e8883e9d711085817f6c9b Mon Sep 17 00:00:00 2001 From: uptoratlen <80213345+uptoratlen@users.noreply.github.com> Date: Fri, 20 Aug 2021 12:42:17 +0200 Subject: [PATCH 5/5] Update README.md table alignment changed --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 801e56a..0da2d7c 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,7 @@ The Ikea uC will do all that polling stuff for us. As reported in #16, the transitions from Green to Yellow and Yellow to Red in the Ikea firmware are at around 30 and 100μg/m³. | Color | Value | Comment | -| ------------- |:-------------:| -----:| +|:------------- |:-------------:|:-----| | Green | 0-35 | Good + Low | | Amber | 36-85 | Ok + Medium | | Red | 86- | Not good + High |