Copyright © https://mongoose-os.com

Mongoose OS Forum

frame

AWS IoT MQTT periodic disconnect/connect

VicVic Moscow, Russia
First of all, many thanks to developers of mos!

Back to my question. I have ESP8266 with mos onboard. It's connected to AWS IoT. So far so good but periodically (ca once per 3-5 minutes) I got the following output:

mgos_mqtt_ev         MQTT Disconnect
mqtt_global_reconnec MQTT connecting after 2157 ms
mqtt_global_connect  MQTT connecting to xxxxxxxxxxxxxx.iot.xxx.amazonaws.com:8883
SW ECDSA verify curve 3 hash_len 32 sig_len 71
SW ECDSA verify curve 3 hash_len 32 sig_len 70
ATCA is not available (-20096), using sw ECDH
mgos_mqtt_ev         MQTT Connect (1)
mgos_mqtt_ev         MQTT CONNACK 0
mgos_mqtt_ev         Subscribing to 'mytopic'
mgos_mqtt_ev         Subscribing to 'esp8266_xxxxxx/rpc'
mgos_mqtt_ev         Subscribing to 'esp8266_xxxxxx/rpc/#'

Unfortunatelly, during this "dead time" ESP8266 does not accept messages for the topic "mytopic". Any guess on it? Thanks in advance!

Vic

Comments

  • rojerrojer Dublin, Ireland
    hm. well, what i can say is that MQTT is pretty well covered by our automated tests, AWS IoT as well as public brokers.
    please verify that the message is indeed published. you can use mosquitto client to connect to AWS IoT with the same credentials as the device - assuming you have cert and key files in the current directory (mos aws-iot-setup writes them there), you can run the following command on a linux machine:
    ```
    $ mosquitto_sub -d -h xxxxxxxxxxxxxx.iot.xxx.amazonaws.com -p 8883 --cafile /etc/ssl/certs/ca-certificates.crt --cert aws-iot-XXX.crt.pem --key aws-iot-XXX.key.pem -t mytopic
    Client mosqsub/19738-nba sending CONNECT
    Client mosqsub/19738-nba received CONNACK
    Client mosqsub/19738-nba sending SUBSCRIBE (Mid: 1, Topic: mytopic, QoS: 0)
    Client mosqsub/19738-nba received SUBACK
    Subscribed (mid: 1): 0
    ```

    after that, you should see messages published to your topic.
    if you can see the message, but device still does not seem to receive it, please poist device log with higher debug levels, run:
    ```
    mos config-set debug.level=3 debug.mbedtls_level=3
    ```
    and post `mos console` output here. there will be quite a bit of it.
  • pratikshindepratikshinde Bangalore
    edited May 2017
    Hi, 
    I am also facing similar issue with disconnection after 5 secs, It was working with 2 subscriptions, after adding 3rd sub topic there were frequent connections-disconnections, is there any limit on number of topics ? or some other problem?

    Simple Debug output is here: https://pastebin.com/dNG0Yf8i

    Output  with mos config-set debug.level=3 debug.mbedtls_level=3 is here https://pastebin.com/2BaTeyxM

    I have modified c_mqtt example here is code https://pastebin.com/3kd9QTsV


  • rojerrojer Dublin, Ireland
    @pratikshinde thanks for a detailed report! your issue is different - it was caused by duplicate message IDs being used for subscription requests and was fixed in https://github.com/cesanta/mongoose-os/commit/cca7ea859e605310325c75008224195f4c96c62b
    please apply changes from that commit to your code.

    original reporters: in https://github.com/cesanta/mongoose-os/commit/a3dbcee97323a289106321ef4d79b9cd1a171417 there was a major change in how networking is handled in ESP32 mOS, and it may have solved the problem. can you please confirm the issue still exists? (i hope not)
  • @rojer It is working fine, getting different sub ids in logs.
    Thanks a lot

  • VicVic Moscow, Russia

    Today I could not reproduce the problem the topic is dedicated to.
    I definitely got one under the conditions: AWS MQTT server, mos-default, 2 arguments in pub function.

    But I faced the following effect with the code (init.js) https://pastebin.com/aumd5nqE
    1) AWS MQTT server, everything is going OK
    2) Switching to MQTT server test.mosquitto.org (I did it from Web GUI)
    3) Back to prototyping => problem. It seems to me that ESP8266 during connection to mosquitto MQTT server is still trying to use the credentials designated for AWS MQTT server. Detailed log is here https://pastebin.com/maN9zxpH

  • rojerrojer Dublin, Ireland

    indeed. looks like ssl client cert parameters were left in place and hence handshake was attempted with test.mosquitto.org
    @Sergey - we should fully configure MQTT params, not just server, including SSL params, and set them explicitly to empty.

  • Just a quick question (hopefully not to steer the topic off-topic).... The OP shows:

    mgos_mqtt_ev         Subscribing to 'esp8266_xxxxxx/rpc'
    mgos_mqtt_ev         Subscribing to 'esp8266_xxxxxx/rpc/#'
    

    Is it possible to prevent mgos from subscribing to /rpc/# automatically? We are setting our project config like so:
    - ["rpc.mqtt.sub_topic", "s", "env/device/commands", {title: "......."}]

    But what ends up happening is we are subscribed to two topics, commands and commands/#. And because of the wildcard, we are getting kicked off our customer's AWS cloud. Is there a switch I can disable for this?

  • I think I have found it....
    ["rpc.mqtt.sub_wc", "b", true, {title: "Also subscribe to wildcard topic"}]

    Thanked by 1Sergey
Sign In or Register to comment.