Copyright © https://mongoose-os.com

Mongoose OS Forum

frame

MQTT LWT not working - esp8266 and esp32

rodrmigurodrmigu Fairfax, Virginia

Hello Everyone,

I notice while trying to configure will_topic and will_message looks like it is not working as expected. Esp8266 has a weird behavior, after the 2nd reset button press, after wifi connects, I get the will_message.
Esp32 nothing happens.

Any help will be appreciated.
Thanks in advance
Rodrigo

mos.yml

config_schema:
    # libs necessary for the current app
  - ["wifi.ap.enable", true]  
  - ["wifi.sta.ssid", "my_wifi"]  
  - ["wifi.sta.pass", "secret"]  
  - ["wifi.sta.enable", true]  
  - ["mqtt.enable", true]  
  - ["mqtt.server", "192.168.1.70:1883"]
  - ["mqtt.will_topic", "/device/status"]
  - ["mqtt.will_message", "offline"]
  - ["debug.level", 3]  

init.js

load('api_sys.js');
load('api_timer.js');
load('api_config.js');

Timer.set(10000, 0, function() {
    print('mqtt.will_topic:', Cfg.get('mqtt.will_topic'), ', mqtt.will_message:', Cfg.get('mqtt.will_message'));
}, null);

mos console output

[Dec 20 14:19:05.476] connected with Wireless-N, channel 2
[Dec 20 14:19:05.476] dhcp client start...
[Dec 20 14:19:05.476] mgos_event_trigger   ev WFI2 triggered 0 handlers
[Dec 20 14:19:05.476] mgos_net_on_change_c WiFi STA: connected
[Dec 20 14:19:05.476] mgos_event_trigger   ev NET2 triggered 2 handlers
[Dec 20 14:19:08.462] ip:192.168.1.101,mask:255.255.255.0,gw:192.168.1.1
[Dec 20 14:19:08.462] mgos_event_trigger   ev WFI3 triggered 0 handlers
[Dec 20 14:19:08.462] mgos_net_on_change_c WiFi STA: ready, IP 192.168.1.101, GW 192.168.1.1, DNS 192.168.1.1
[Dec 20 14:19:08.462] mgos_mqtt_global_con MQTT connecting to 192.168.1.70:1883
[Dec 20 14:19:08.462] mg_connect_opt       0x3fff17c4 192.168.1.70:1883 -,-,-
[Dec 20 14:19:08.462] mg_do_connect        0x3fff17c4 tcp://192.168.1.70:1883
[Dec 20 14:19:08.462] mgos_event_trigger   ev NET3 triggered 2 handlers
[Dec 20 14:19:09.449] mg_if_connect_cb     0x3fff17c4 tcp://192.168.1.70:1883 -> 0
[Dec 20 14:19:09.449] mgos_mqtt_ev         MQTT TCP connect ok (0)
[Dec 20 14:19:09.449] mgos_mqtt_ev         MQTT event: 202
[Dec 20 14:19:09.449] mgos_mqtt_ev         MQTT CONNACK 0
[Dec 20 14:19:09.449] mgos_event_trigger   ev MOS4 triggered 0 handlers
[Dec 20 14:19:11.811] mqtt.will_topic: /device/status mqtt.will_message: offline
[Dec 20 14:20:09.852] mqtt_handler         Send PINGREQ
[Dec 20 14:20:20.150] mgos_mqtt_ev         MQTT event: 213
[Dec 20 14:21:09.887] mqtt_handler         Send PINGREQ
[Dec 20 14:21:18.106] mgos_mqtt_ev         MQTT event: 213
[Dec 20 14:22:09.922] mqtt_handler         Send PINGREQ
[Dec 20 14:22:09.922] mgos_mqtt_ev         MQTT event: 213
[Dec 20 14:23:09.957] mqtt_handler         Send PINGREQ
[Dec 20 14:23:09.957] mgos_mqtt_ev         MQTT event: 213
[Dec 20 14:24:09.977] mqtt_handler         Send PINGREQ
[Dec 20 14:24:09.977] mgos_mqtt_ev         MQTT event: 213

Comments

Sign In or Register to comment.