Error sending payload. SiPy Sigfox. **SOLVED**
-
Hello, good day to all.
I have done tests from the console sending data to Sigfox's Backend, however when I do it from the code it is blocked the moment it is sent:
s.send(bytes(payload))
And this is the code I use:
import pycom import time, utime, machine, dht, socket from machine import Pin, Timer, WDT from network import Sigfox ID_ESTACION=2 T_ESTACION=114 #114 es la R en DEC --- 99 es la C en DEC --- 97 es la A en DEC FlagWDT = 0 #Bandera del WDT #wdt = WDT(timeout=60000) #inicializamos WDT con tiempo de 1 minuto pycom.heartbeat(False) #Apagamos el led #Código para leer Temperatura y Humedad th = dht.DTH(Pin('P11', mode=Pin.OPEN_DRAIN),1) tem=0 hum=0 result=0 cont=0 #time.sleep(2) #result = th.read() def readTemHum(): global tem, hum cont=0 #time.sleep(2) result = th.read() while result.is_valid()==False: result = th.read() if result.is_valid(): tem=result.temperature/1.0 hum=result.humidity/1.0 #print('Temperatura: {:3.2f}'.format(tem)) #print('Humedad: {:3.2f}'.format(hum)) else: tem=tem hum=hum #print('Temperatura: {:3.2f}'.format(tem)) #print('Humedad: {:3.2f}'.format(hum)) #FIN Código para leer Temperatura y Humedad #Código para leer e interpretar el ULTRASONIDO Pin('P5', mode=Pin.OUT, value=1) def tramaUltrasonic(): uart1.readline() dist = 0 cont=0 for cont in range(0,5): Pin('P5', mode=Pin.OUT, value=1) dist=uart1.readline() Pin('P5', mode=Pin.OUT, value=0) time.sleep(0.15) return dist last_value=0 def readUltrasonic(): global last_value #separado = 0 dist=tramaUltrasonic() valS=str(dist) #print(valS) try: separado=valS.split("b'R") separado = separado[1].split("\\") separado = separado[0] last_value=int(separado) return last_value except IndexError: #print("error") return last_value pass #FIN del Código para leer e interpretar el ULTRASONIDO #Pasar valor de los sensores a Bytes def int_to_bytes(value,length): result = [] for i in range(0, length): result.append(value >> (i * 8) & 0xff) result.reverse() return result #FIN de Pasar valor de los sensores a Bytes #Codigo de conexión Sigfox sigfox = Sigfox(mode=Sigfox.SIGFOX, rcz=Sigfox.RCZ4) s = socket.socket(socket.AF_SIGFOX, socket.SOCK_RAW) s.setblocking(True) s.setsockopt(socket.SOL_SIGFOX, socket.SO_RX, False) def sendsig(payload): print("Enviando Datos...") envio.callback(None) print(payload) print(bytes(payload)) #s.send(bytes(payload)) pycom.rgbled(0x7f0000) #ROJO print("Pasa el time: ",payload) #FIN Codigo de conexión Sigfox #Código para Enviar Datos payload=0 envio = Timer.Alarm(None, 25, periodic = True) #299 segundos para 5 minutos def EnviarDatos(alarm): global payload pycom.rgbled(0x007f00) #Verde ultra=readUltrasonic() readTemHum() ID_EST=int_to_bytes(ID_ESTACION,1) ultraB=int_to_bytes(ultra,2) temB=int_to_bytes(int(tem*10),2) humB=int_to_bytes(int(hum),1) T_EST=int_to_bytes(T_ESTACION,1) payload=int(ID_EST[0]),int(ultraB[0]),int(ultraB[1]),int(temB[0]),int(temB[1]),int(humB[0]),int(T_EST[0])#Debe estar ordenado según se reciben en el Backend de Sigfox print("Valor a enviar: ",payload) print(type(payload[0])) sendsig(payload) #wdt.feed() #Alimentamos el WDT pycom.rgbled(0x000000) #Negro global FlagWDT FlagWDT=1 envio.callback(None) #FIN del código para Enviar Datos while FlagWDT==0: envio.callback(EnviarDatos) time.sleep(2) #machine.deepsleep(588000) #duerme 9,8 min + 30 segundos que demora enviar el mensaje serían 10,30 min, equivalentes a 139.8 mensajes al día
The payload that is sent is of this type:
>>> print(payload) (2, 2, 183, 1, 38, 55, 114) >>>type(payload) <class 'tuple'>
I've done the testing by sending this payload from the console and I have no problem, but when I load the code in SiPy, it crashes.
I hope you can help me. Thank you and happy day.
-
Hi everyone.
I want to tell you that I have already solved the problem. There is a conflict with the line in which I declare a Pin as output and the moment in which it is transmitted:
Pin('P5', mode=Pin.OUT, value=1)
What I did was change the pin to P13, this ended the problem and I was able to transmit without any inconvenience and see the data in the Sigfox Backend.:
Pin('P13', mode=Pin.OUT, value=1)
-
Ok, I've noticed that there is a compatibility problem between the UART read and the socket to send to the Sigfox network.
I will try to solve it and then we will see.