".SendMessage" stops connecting after a few hours


#1

I have a Nova connected to my Raspberry Pi Zero. My python program is very simple.

def send_data(r1,r2,r3,r4,r5,r6,r7,r8):

try:
	credentials = {'devicekey': 'MyDeciceKey'}

	hologram = HologramCloud(credentials, network='cellular')

	payload = {"DateSent" : datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S.%f')[:-3] + "Z","Reading1": r1,"Reading2": r2,"Reading3": r3,"Reading4": r4,"Reading5": r5,"Reading6": r6,"Reading7": r7,"Reading8": r8}

	formattedPayload = json.dumps(payload)
	
	recv = hologram.sendMessage(formattedPayload, topics=["Nova_Reading"], timeout=10)
	
	hologram_message = {
		0: "ERR_OK",
		1: "ERR_CONNCLOSED",
		2: "ERR_MSGINVALID",
		3: "ERR_AUTHINVALID",
		4: "ERR_PAYLOADINVALID",
		5: "ERR_PROTINVALID",
		6: "ERR_INTERNAL",
		-1: "ERR_UNKNOWN"
	}
	
	a = hologram_message.get(recv)
	print(a);
	
	if recv == 0:
		return 0
	else:
		return 1

except requests.exceptions.RequestException:
	return 1

When I run the script fast, about once a minute, it times out after 3 hours and will not send any more data until the Pi is restarted. When I run the script slow, say, every 10 minutes, it will drop after a few days and, once again, not connect until I make the Pi restart.

I’ve seen a few similar stories about devices not staying connected, but what can I do to get around this?


#2

Are you seeing any exceptions around the time it fails? It’s possible that there was a failure to send for some reason and maybe the serial port wasn’t released properly so all future sends fail. We’re hopefully releasing a new version soon with better error handling that might help here but you may want to add some logging so you can see better what is going on.


#3

I was playing with logging in my program. ran it for a few hours and got found that the program was locking up after an error to connect. Any recommendations for getting around this type of error?

Previous Call:

393 - program_logger - INFO - rcv was successful: 0 2018-07-23 21:39:00,
130 - Hologram.Network.Network - INFO - Detected modem Nova_U201
2018-07-23 21:39:00,
419 - Hologram.Network.Modem.IModem - INFO - found working port at /dev/ttyACM0
2018-07-23 21:39:00,
432 - Hologram.Network.Modem.IModem - INFO - chatscript file: /usr/local/lib/python2.7/dist->packages/Hologram/Network/Modem/chatscripts/default-script
2018-07-23 21:39:00,
623 - Hologram.Network.Modem.IModem - INFO - Instantiated a Nova_U201 interface with device name of >/dev/ttyACM0
2018-07-23 21:39:00,
846 - Hologram.Cloud - INFO - Connecting to: cloudsocket.hologram.io
2018-07-23 21:39:00,
850 - Hologram.Cloud - INFO - Port: 9999
2018-07-23 21:39:02,
323 - Hologram.Network.Modem.IModem - INFO - Connect socket is successful
2018-07-23 21:39:04,
328 - Hologram.Cloud - INFO - Sending message with body of length 305
2018-07-23 21:39:05,
892 - Hologram.Cloud - INFO - Sent.
2018-07-23 21:39:06,
145 - Hologram.Network.Modem.IModem - INFO - Failed to close socket
2018-07-23 21:39:06,
148 - Hologram.Cloud - INFO - Socket closed.
2018-07-23 21:39:06,
152 - program_logger - INFO - ERR_OK
2018-07-23 21:39:06,

Final Call, With Error

162 - program_logger - INFO - rcv was successful: 0 2018-07-23 21:39:38,
041 - Hologram.Network.Network - INFO - Detected modem Nova_U201
2018-07-23 21:39:38,
318 - Hologram.Network.Modem.IModem - INFO - found working port at /dev/ttyACM0
2018-07-23 21:39:38,
330 - Hologram.Network.Modem.IModem - INFO - chatscript file: /usr/local/lib/python2.7/dist->packages/Hologram/Network/Modem/chatscripts/default-script
2018-07-23 21:39:38,
538 - Hologram.Network.Modem.IModem - INFO - Instantiated a Nova_U201 interface with device name of >/dev/ttyACM0
2018-07-23 21:39:38,
844 - Hologram.Cloud - INFO - Connecting to: cloudsocket.hologram.io
2018-07-23 21:39:38,
847 - Hologram.Cloud - INFO - Port: 9999
2018-07-23 21:39:43,
964 - Hologram.Network.Modem.IModem - ERROR - Failed to connect socket
2018-07-23 21:39:45,
970 - Hologram.Cloud - INFO - Sending message with body of length 307
2018-07-23 21:39:47,
995 - Hologram.Network.Modem.IModem - ERROR - Failed to write to socket

I have the call in a try/catch… Since that didn’t solve it I don’t know what else to try.


#4

Are you using the latest version of the SDK we released last week? 0.8.0
That one has some improvements to how we handle connection errors and might help here.


#5

Hmm, it must not have upgraded with my regular system updates. I’ll manually upgrade and try again

I’ll post back with my results


#6

Yeah it’s part of the pip updates but not part of apt so it might not happen automatically depending on your config