Copyright ©

Mongoose OS Forum

ATTENTION! This forum has moved to:

Do not post any new messages.

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
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!



  • 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 -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.
  • SergeySergey Dublin, Ireland
    @Vic, see

    I suspect your issue is the same - the 3rd param to
    please confirm
  • pratikshindepratikshinde Bangalore
    edited May 2017
    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:

    Output  with mos config-set debug.level=3 debug.mbedtls_level=3 is here

    I have modified c_mqtt example here is code

  • 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
    please apply changes from that commit to your code.

    original reporters: in 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)
    1) AWS MQTT server, everything is going OK
    2) Switching to MQTT server (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

  • rojerrojer Dublin, Ireland

    indeed. looks like ssl client cert parameters were left in place and hence handshake was attempted with
    @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.