Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Properly detecting and reconnecting to Pybytes

    Scheduled Pinned Locked Moved Pybytes IoT platform
    1 Posts 1 Posters 30 Views 1 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D Offline
      Daniel Near
      last edited by

      I have code that's working "fine" on one FiPy device over a Wifi connection - it's been online pretty consistently for months (Although it says "Offline" in pybytes, the signals post fine every time. I mirrored the exact same code to a second device (It has a unique pybytes configuration on the same account) and that device is inconsistently unable to post pybytes signals despite it reporting pybytes.isconnected as True.

      Is there some tried and true method to query the connection status of the pybytes mqtt server and reconnect when it's offline?

      When I set

      import pycom; pycom.nvs_set('pybytes_debug', 99)
      

      The one difference between working and not is that

      [         53.341] [1073565772] This is pack_pybytes_message_variable(5, 1, b'70.63')
      [         53.353] [1073565772] __pack_message: b'0e050137302e3633'
      [         53.361] [1073565772] MQTT Protocol
      

      is followed shortly after by

      [        57.731] [1073656844] Packet sent. (Length: 48)
      

      when it's actually sending. When it's not properly connecting, the "Packet sent" message doesn't show, but no additional errors are displayed.

      The startup looks like this (With credentials replaced with ***)

      [          1.651] [1073517588] {'wifi': {'ssid': '*****', 'password': '*****'}, 'pybytes_autostart': True, 'username': '*****', 'cfg_msg':'Pybytes configuration read from /flash/pybytes_config.json', 'server': 'mqtt.pybytes.pycom.io', 'lte': {'apn': None, 'cid': None, 'reset': False, 'carrier': None, 'band': None, 'type': None}, 'ssl': False, 'device_id': '*****', 'network_preferences': ['wifi'], 'dump_ca': False, 'wlan_antenna': 0, 'ota_server': {'port': 443, 'domain': 'software.pycom.io'}}
      [          1.699] [1073517588]  ssl_params={'ca_certs': '/flash/cert/pycom-ca.pem'}
      [          5.344] [1073517588] LIS2HH12 not imported
      [          6.736] [1073517588]  ssl_params={'ca_certs': '/flash/cert/pycom-ca.pe                                                       m'}
      WMAC: 840D8E******
      Firmware: 1.20.2.r6
      Pybytes: 1.7.1
      [          6.752] [1073517588] {'wifi': {'ssid': '*****', 'password': '*****'}, 'pybytes_autostart': True, 'username': '*****', 'cfg_msg': 'Pybytes configuration read from /flash/pybytes_config.json', 'server': 'mqtt.pybytes.pycom.io', 'lte': {'apn': None, 'cid': None, 'reset': False, 'carrier': None,'band': None, 'type': None}, 'ssl': False, 'device_id': '*****', 'network_preferences': ['wifi'], 'dump_ca': False, 'wlan_antenna': 0, 'ota_server': {'port': 443, 'domain': 'software.pycom.io'}}
      [          6.858] [1073517588] Attempting to connect with network wifi
      Initialized watchdog for WiFi and LTE connection with timeout 1260000 ms
      [          6.998] [1073517588] WLAN connected? False
      [          7.006] [1073517588] Wifi connection attempt: 1
      [          7.015] [1073517588] WLAN connected? False
      [          9.135] [1073517588] (ssid='*****', bssid=b"\xc0V'\xd7\xd1y", sec=3, channel=1, rssi=-57)
      [          9.141] [1073517588] (ssid='*****-guest', bssid=b'\xf6\x92\xbf\x95\x88]', sec=0, channel=6, rssi=-59)
      [          9.147] [1073517588] (ssid='*****', bssid=b'\xf4\x92\xbf\xa5\x88]', sec=3, channel=6, rssi=-59)
      [          9.156] [1073517588] (ssid='*****-guest', bssid=b'n\xd7\x9a\xc7^\x8a', sec=0, channel=6, rssi=-64)
      [          9.166] [1073517588] (ssid='*****', bssid=b'h\xd7\x9a\xc7^\x8a', sec=3, channel=6, rssi=-65)
      [          9.175] [1073517588] (ssid='*****', bssid=b'$ZLk\x9e\x00', sec=3, channel=11, rssi=-68)
      [          9.183] [1073517588] (ssid='*****-guest', bssid=b'&ZL\x1b\x9e\x00', sec=0, channel=11, rssi=-68)
      [          9.192] [1073517588] (ssid='*****', bssid=b'h\xd7\x9a\xc1\xb4\x8a', sec=3, channel=6, rssi=-85)
      [          9.201] [1073517588] (ssid='*****-guest', bssid=b'n\xd7\x9a\xc1\xb4\x8a', sec=0, channel=6, rssi=-86)
      [         10.217] [1073517588] Connecting with ***** and *****
      WiFi connection established
      [         12.126] [1073517588] MQTT Protocol
      [         12.132] [1073517588] starting new MsgHandler
      [         12.276] [1073517588] Packet sent. (Length: 110)
      [         12.431] [1073517588] This is PybytesProtocol.start_MQTT
      [         13.431] [1073646604] Packet sent. (Length: 44)
      Connected to MQTT mqtt.pybytes.pycom.io
      Pybytes connected successfully (using the built-in pybytes library)
      [         13.665] [1073517588] This is pack_info_message()
      [         13.681] [1073517588] pybytes
      [         13.690] [1073517588] __pack_message: b'010504a00586000000'
      [         13.699] [1073517588] MQTT Protocol
      [         13.708] [1073517588] Packet sent. (Length: 50)
      Pybytes configuration read from /flash/pybytes_config.json
      Pybytes is connected, sending signals to Pybytes
      [         16.397] [1073517588]  ssl_params={'ca_certs': '/flash/cert/pycom-ca.pem'}```
      1 Reply Last reply Reply Quote 0

      Hello! It looks like you're interested in this conversation, but you don't have an account yet.

      Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

      With your input, this post could be even better 💗

      Register Login
      • 1 / 1
      • First post
        Last post

      Pycom on Twitter

      Pycom