summaryrefslogtreecommitdiff
path: root/init.lua
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2022-04-29 19:39:46 +0200
committerDaniel Friesel <derf@finalrewind.org>2022-04-29 19:39:46 +0200
commitbb8baa21195aa673ba4c8debd6fd9233f5241ee3 (patch)
treecd60c616e21e2ecb823f66fc121a8abfc42184df /init.lua
parent821de6608bba6be8b4bc3c94fb306faaa6fe2908 (diff)
restart unless connected successfully
Diffstat (limited to 'init.lua')
-rw-r--r--init.lua6
1 files changed, 4 insertions, 2 deletions
diff --git a/init.lua b/init.lua
index af67928..a6335fc 100644
--- a/init.lua
+++ b/init.lua
@@ -35,7 +35,6 @@ end
function connect_mqtt()
print("IP address: " .. wifi.sta.getip())
print("Connecting to MQTT " .. mqtt_host)
- delayed_restart:stop()
mqttclient:on("connect", hass_register)
mqttclient:on("offline", log_restart)
mqttclient:lwt(mqtt_prefix .. "/state", "offline", 0, 1)
@@ -78,6 +77,8 @@ function hass_register()
local hass_pm2_5 = string.format('{%s,"name":"PM2.5","object_id":"%s_pm2_5","unique_id":"%s_pm2_5","device_class":"pm25","unit_of_measurement":"µg/m³","value_template":"{{value_json.pm2_5_ugm3}}"}', hass_entity_base, device_id, device_id)
local hass_rssi = string.format('{%s,"name":"RSSI","object_id":"%s_rssi","unique_id":"%s_rssi","device_class":"signal_strength","unit_of_measurement":"dBm","value_template":"{{value_json.rssi_dbm}}","entity_category":"diagnostic"}', hass_entity_base, device_id, device_id)
+ delayed_restart:stop()
+
mqttclient:publish("homeassistant/sensor/" .. device_id .. "/pm2_5/config", hass_pm2_5, 0, 1, function(client)
mqttclient:publish("homeassistant/sensor/" .. device_id .. "/rssi/config", hass_rssi, 0, 1, function(client)
collectgarbage()
@@ -86,6 +87,7 @@ function hass_register()
end)
end
-delayed_restart:register(20 * 1000, tmr.ALARM_SINGLE, node.restart)
+delayed_restart:register(30 * 1000, tmr.ALARM_SINGLE, node.restart)
+delayed_restart:start()
connect_wifi()