Can send data from device to cloud, but cannot send data from cloud to device


#1

I’m using a Pycom GPy, and the SIM typically connects to AT&T in my location. I can send data from the GPy to the cloud, but I can’t send data from the cloud to the device.

This is the Python code that opens a socket, waits for a connection, and prints what it sent.

s = socket.socket()
s.settimeout(120)
s.bind(('',4010))
s.listen(5)
print ("Waiting for accept")
(conn, addr) = s.accept()
print("Connected", addr)
with conn:
    data = conn.read()
    print(data)

I have the LTE connection working in other code.

Whenever I try to send a message from the Dashboard (via TCP on port 4010), a message saying “Socket error: timed out” comes back. Earlier this morning, it was taking around 15-20 seconds for the error to appear in the log, but now it’s almost instantaneous.

Full code:

	import socket
	import ssl
	import time
	import errno
	import pycom
	import micropython
	from network import LTE
	import sys
	import json
	import binascii
	from machine import RTC

	pycom.heartbeat(False)
	lte = LTE()
	lte.attach()
	while not lte.isattached():
			pycom.rgbled(0xFF0000)
			time.sleep(0.25)
			pycom.rgbled(0)
			time.sleep(0.25)
	lte.connect()       # start a data session and obtain an IP address
	print("Waiting for connection")
	while not lte.isconnected():
			pycom.rgbled(0x00FF00)
			time.sleep(0.25)
			pycom.rgbled(0)
			time.sleep(0.25)
	print('Connected')       # attach the cellular modem to a base station

	try:
			s = socket.socket()
			s.settimeout(120)
			s.bind(('',4010))
			s.listen(5)
			print ("Waiting for accept")
			(conn, addr) = s.accept()
			print("Connected", addr)
			with conn:
					data = conn.read()
					print(data)
	finally:
			s.close()
			lte.disconnect()
			lte.dettach()

#2

I’m having a similar issue. Using a different python script (the one that follows the example). Data is only received one out of maybe 10 times. Using a RaspberryPi3 B+ and Nova.


#3

Hi jbutzine, are you still having issues? I have yet to successfully send a message, and I’m still trying to figure out if it’s on my end or Hologram’s.


#4

Just chiming in that I’m also experiencing this.

I’m following benstr’s github demo here: https://github.com/HologramEducation/AT-Workshop and unable to receive a message from Hologram dashboard.


#5

I tried again today and now I can send data from the Hologram cloud to my device. However, Hologram immediately adds the “Socket error: timed out” error once the data is received by the device.

Can anyone from Hologram chime in on what’s going on with the cloud service and the socket API?


#6

The cloud will wait for a reply back for a little bit and if it doesn’t get anything then it will print that message. Try writing back some response to the socket after you get the data.


#7

BTW, some very recently activated SIMs (within the last week or two) might have had issues here due to a carrier routing issue that was fixed a couple days ago. That might explain the trouble you were having.
Also, on Cat-M sometimes things don’t work because the radio stays powered off for a longer period of time than 3G. We’re working on a fix for this.


#8

Thanks for that info, Reuben.

The issue was with my code. I was originally using the following code to send data from the cloud to the device and then respond:

s = socket.socket()
s.settimeout(120)
s.bind(('',4010))
s.listen(5)
print ("Waiting for accept")
(conn, addr) = s.accept()
print("Connecte ", addr)
data = conn.readall()
print(data)
print("sending response back")
conn.sendall("Data written!")
print("resposne sent...")

The issue with my code was in the data = conn.readall() statement. readall reads all of the data for the connection, and only returns once the connection is closed. I replaced readall with recv(1024) and everything is working as expected.


#9

Makes sense. Glad you got it working


#10

One other thing we discovered today. If you’re using a GPy and you can’t receive data, make sure the modem firmware is up to date.


closed #11

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.