<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Error sending payload. SiPy Sigfox.  **SOLVED**]]></title><description><![CDATA[<p dir="auto">Hello, good day to all.</p>
<p dir="auto">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:</p>
<pre><code>s.send(bytes(payload))
</code></pre>
<p dir="auto">And this is the code I use:</p>
<pre><code>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(&quot;b'R&quot;)
        separado = separado[1].split(&quot;\\&quot;)
        separado = separado[0]
        last_value=int(separado)
        return last_value
    except IndexError:
        #print(&quot;error&quot;)
        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 &gt;&gt; (i * 8) &amp; 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(&quot;Enviando Datos...&quot;)
    envio.callback(None)
    print(payload)
    print(bytes(payload))
    #s.send(bytes(payload))
    pycom.rgbled(0x7f0000) #ROJO
    print(&quot;Pasa el time: &quot;,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(&quot;Valor a enviar: &quot;,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
</code></pre>
<p dir="auto">The payload that is sent is of this type:</p>
<pre><code>&gt;&gt;&gt; print(payload)
(2, 2, 183, 1, 38, 55, 114)
&gt;&gt;&gt;type(payload)
&lt;class 'tuple'&gt;
</code></pre>
<p dir="auto">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.</p>
<p dir="auto">I hope you can help me. Thank you and happy day.</p>
]]></description><link>https://forum.pycom.io/topic/1729/error-sending-payload-sipy-sigfox-solved</link><generator>RSS for Node</generator><lastBuildDate>Fri, 11 Sep 2026 14:04:03 GMT</lastBuildDate><atom:link href="https://forum.pycom.io/topic/1729.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 25 Aug 2017 15:45:25 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Error sending payload. SiPy Sigfox.  **SOLVED** on Fri, 08 Sep 2017 14:08:11 GMT]]></title><description><![CDATA[<p dir="auto">Hello, good day to all.</p>
<p dir="auto">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:</p>
<pre><code>s.send(bytes(payload))
</code></pre>
<p dir="auto">And this is the code I use:</p>
<pre><code>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(&quot;b'R&quot;)
        separado = separado[1].split(&quot;\\&quot;)
        separado = separado[0]
        last_value=int(separado)
        return last_value
    except IndexError:
        #print(&quot;error&quot;)
        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 &gt;&gt; (i * 8) &amp; 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(&quot;Enviando Datos...&quot;)
    envio.callback(None)
    print(payload)
    print(bytes(payload))
    #s.send(bytes(payload))
    pycom.rgbled(0x7f0000) #ROJO
    print(&quot;Pasa el time: &quot;,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(&quot;Valor a enviar: &quot;,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
</code></pre>
<p dir="auto">The payload that is sent is of this type:</p>
<pre><code>&gt;&gt;&gt; print(payload)
(2, 2, 183, 1, 38, 55, 114)
&gt;&gt;&gt;type(payload)
&lt;class 'tuple'&gt;
</code></pre>
<p dir="auto">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.</p>
<p dir="auto">I hope you can help me. Thank you and happy day.</p>
]]></description><link>https://forum.pycom.io/post/10633</link><guid isPermaLink="true">https://forum.pycom.io/post/10633</guid><dc:creator><![CDATA[scg94]]></dc:creator><pubDate>Fri, 08 Sep 2017 14:08:11 GMT</pubDate></item><item><title><![CDATA[Reply to Error sending payload. SiPy Sigfox.  **SOLVED** on Wed, 06 Sep 2017 20:15:29 GMT]]></title><description><![CDATA[<p dir="auto">Ok, I've noticed that there is a compatibility problem between the UART read and the socket to send to the Sigfox network.</p>
<p dir="auto">I will try to solve it and then we will see.</p>
]]></description><link>https://forum.pycom.io/post/10929</link><guid isPermaLink="true">https://forum.pycom.io/post/10929</guid><dc:creator><![CDATA[scg94]]></dc:creator><pubDate>Wed, 06 Sep 2017 20:15:29 GMT</pubDate></item><item><title><![CDATA[Reply to Error sending payload. SiPy Sigfox.  **SOLVED** on Fri, 08 Sep 2017 14:14:43 GMT]]></title><description><![CDATA[<p dir="auto">Hi everyone.</p>
<p dir="auto">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:</p>
<pre><code>Pin('P5', mode=Pin.OUT, value=1)
</code></pre>
<p dir="auto">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.:</p>
<pre><code>Pin('P13', mode=Pin.OUT, value=1)
</code></pre>
<p dir="auto"><img src="/assets/uploads/files/1504880079593-upload-1af3b981-1883-46c5-afa3-16dfe2bcb8ef.png" alt="0_1504880078593_upload-1af3b981-1883-46c5-afa3-16dfe2bcb8ef" class="img-responsive img-markdown" /></p>
]]></description><link>https://forum.pycom.io/post/10961</link><guid isPermaLink="true">https://forum.pycom.io/post/10961</guid><dc:creator><![CDATA[scg94]]></dc:creator><pubDate>Fri, 08 Sep 2017 14:14:43 GMT</pubDate></item></channel></rss>