diff --git a/README.md b/README.md index 46f6746..0da2d7c 100644 --- a/README.md +++ b/README.md @@ -95,6 +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 for 10 seconds| + +Info from (https://www.ikea.com/us/en/manuals/vindriktning-air-quality-sensor__AA-2289325-1_pub.pdf): ## ToDo 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); }