FiPy: Sending string message to Hologram over LTE-M...



  • 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.



  • @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.



  • 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?


Log in to reply
 

Pycom on Twitter