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: Sending string message to Hologram over LTE-M...

    Scheduled Pinned Locked Moved FiPy
    3 Posts 2 Posters 278 Views 2 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.
    • securigyS Offline
      securigy
      last edited by securigy

      I am sending data using the following code and it executes without any errors:

      HOST = "cloudsocket.hologram.io"
      PORT = 9999
      DEVICE_KEY = "30AEAXXXXXXX" #generated on hologram's portal for each SIM card.
      TOPIC = "ENVTOPIC"
      
      idx = 0
      
      try:
          lteSocket = socket.socket()
          lteSocket.setblocking(True)
          print(lteSocket)
          dns_records = socket.getaddrinfo(HOST, PORT)
          print("got dns_records:")
          print(dns_records)
          
          dns_record = dns_records[0][-1]
          print("DNS Record: {}".format(dns_record))
          lteSocket.connect(dns_record)
          print("==== LTE Socket connected")
      
          while (idx < 1):
      
              print("@@@@@@@@@@@@@@@@@@@@ Transmission #: {}".format(idx))
              #print("Local Time: {}".format(utime.localtime())
      
              message = CreatePayload()
      
              #for record in dns_records:
              try:
                  data = '{"k": "%s", "d": "%s", "t": "%s"}' % (DEVICE_KEY, message, TOPIC)
                  lteSocket.send(bytes(data, 'ascii'))
                  time.sleep(1)
      
                  print("==== LTE Socket data sent")
                  result = lteSocket.recv(8).decode()
                  print("LTE Socket result received: "+result)
              except Exception as err1:
                  try:
                      print("LTE Socket exception: {}".format(err1))
                      print("LTE Socket closing...")
                      lteSocket.close()
                  except:
                      pass
                  print("   "+err1)
       
              idx += 1
      
              time.sleep(5)
      
          lteSocket.close()               
          print("LTE Socket closed.")
      
      except Exception:
          print("Exception displaying data...")
      

      The above code works (however I do not see any data on Hologram, not sure why...)
      The problem is that if I change While loop and start sending multiple messages in a loop I get [Error 104] ECONNRESET.
      Any ideas why Hologram server resets the socket connection?

      EDIT: Nov 9, 2019
      What if instead of sockets I want to use MQTT to send the data to MQTT Broker to some other destination than Hologram (or to Hologram). Based on what I read it should be possible since LTE-M connection should allow any type of TCPIP communication. I am reasonably experienced with MQTT but still wonder - is there any special I need to do than creting MQTT client and publishing to specific token... I'd appreciate any thoughts.

      1 Reply Last reply Reply Quote 0
      • Z Offline
        zwarcola
        last edited by

        Hello, sorry I do not believe I can answer your question. But could you show your code on connecting the FiPy to LTE with a hologram SIM?

        securigyS 1 Reply Last reply Reply Quote 0
        • securigyS Offline
          securigy @zwarcola
          last edited by

          @zwarcola I resolved my problem - it was entirely my mistake. However, sending data with LTE-M sockets to Hologram did not bring me to 100% success. The send of the data goes through and I can see it on Hologram, but then I thought that I will be receiving some kind of response from Hologram but nothing comes back and the call to socket.recv(128) times out... I tried it with different buffer sizes and even giving it different timeout values (up to 10 sec) but nothing comes back. In addition Hologram displays only a list of 15 tuples that I send first. It does not show the second list that I send which is hundreds of tuples long...strange... Besides that, they do not have any data visualization but only mechanisms of forwarding it to other sites... That brings me to another question that I asked in my previous post:

          What if instead of sockets I want to use MQTT to send the data to MQTT Broker to some other destination than Hologram (or to Hologram). Based on what I read it should be possible since LTE-M connection should allow any type of TCPIP communication. I am reasonably experienced with MQTT but still wonder - is there any special I need to do than creting MQTT client and publishing to specific token... I'd appreciate any thoughts.

          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