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

    FiPy not connecting to MQTT with LTE CatM1

    Scheduled Pinned Locked Moved FiPy
    mqttlte
    4 Posts 3 Posters 1.3k Views 3 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
      Dylan
      last edited by Dylan

      Hello,

      I am having trouble getting the FiPy to send messages via LTE Cat-M1. I have update the sequans, and the latest firmware for the FiPy.

      According to lte.isattached and lte.isconnected everything is True.

      When connecting by Wifi the MQTT message send no problems.
      I have checked to make sure I have data on the SIM.

      The code I have eventually returns:

      Traceback (most recent call last):
      File "main.py", line 42, in <module>
      File "mqtt.py", line 84, in connect
      IndexError: bytes index out of range
      

      My mqtt.py code is from the pycom github unchanged.
      My main.py is:

      import machine
      import network
      import os
      import time
      import socket
      import ssl
      import pycom
      from network import LTE
      from mqtt import MQTTClient
      
      def sub_cb(topic, msg):
          print(msg)
      # setup as a station
      lte = LTE()
      print("Line 15")
      lte.send_at_cmd('AT+CFUN=0')
      lte.send_at_cmd('AT!="clearscanconfig"')
      lte.send_at_cmd('AT!="addscanfreq band=28 dl-earfcn=9410"')
      lte.send_at_cmd('AT+CGDCONT=1, "IP", "telstra.internet"')
      lte.send_at_cmd('AT+CEMODE=0')
      lte.send_at_cmd('AT+CEREG=2')
      lte.send_at_cmd('AT+CFUN=1')
      
      while not lte.isattached():
          print("Attaching...")
          time.sleep(0.1)
      print("Attached")
      
      lte.connect()
      
      while not lte.isconnected():
          print("Connecting...")
          time.sleep(0.1)
          print("Connected!")
      time.sleep(2)
      print(lte.isconnected())
      client = MQTTClient("Demo","io.adafruit.com",user="Dylan", password="xxxx", port=1883)
      print("Line 38")
      print(lte.isconnected())
      client.set_callback(sub_cb)
      print("Line 41")
      client.connect()
      print("Line 43")
      time.sleep(3)
      client.subscribe(topic="Dylan/feeds/mqtt")
      print("Line 46")
      
      while True:
          print("Sending ON")
          client.publish(topic="Dylan/feeds/mqtt", msg="ON")
          print("Line 51")
          time.sleep(1)
          print("Sending OFF")
          client.publish(topic="Dylan/feeds/mqtt", msg="OFF")
          print("Line 55")
          client.check_msg()
      
          time.sleep(1)
      

      Any help would be greatly appreciated,
      Cheers

      J T 2 Replies Last reply Reply Quote 0
      • J Offline
        jmarcelino @Dylan
        last edited by

        @dylan
        Can you try editing mqtt.py and adding

        self.sock.setBlocking(True)

        after line 55
        self.sock = socket.socket()

        D 1 Reply Last reply Reply Quote 0
        • D Offline
          Dylan @jmarcelino
          last edited by

          @jmarcelino Gave the same error :(

          1 Reply Last reply Reply Quote 0
          • T Offline
            timh @Dylan
            last edited by

            @dylan Hi Dylan. I am using MQTT constantlty over CAT-M1 on Telstra.

            I am only using.

            lte.send_at_cmd('AT+CGDCONT=1,"IP","telstra.internet"')
            lte.send_at_cmd("AT!=\"RRC::addscanfreq band=28 dl-earfcn=9410\"")
            lte.send_at_cmd('AT+CFUN=1')
            

            And have not had to resort to the additional AT commands you are using.
            I have also found the reset the modem if I have lost the connection and am reconnecting without a power cycle.

            lte.send_at_cmd('AT^RESET')
            

            Other than that its working very reliably for me.

            I am not using mqtt but using the AWS client (not to connect to AWS) as I need TLS with certificate support.
            We use Losant. They do support port 1883.

            T

            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