Hi everyone,
I’ve been through a lot of forum to try and find a solution before posting my problem but didn’t manage to find it.
So here is the deal, I’m trying to send packets via LoRa Wan from my Lopy4 using The Things Indoor Gateway. It works pretty fine if I do it without deep sleep, but I need to use deep sleep because I want my application to run longer. I’m calling lora.nvram_save() before deep sleep and lora.nvram_restore() after instancianting lora object at the begining of my script. The firts time it works well and I can see my data on TTN, but after deep sleep none of my packet arrive to my application in TTN.
Here is my code :
#***********************************************************************
#*****
#***** INITIALISATION
#*****
#***********************************************************************
#-----------------------------------------------------------------------
# IMPORTS / INCLUDE
#-----------------------------------------------------------------------
import pycom
import time
from network import LoRa
import socket
import machine
from machine import Pin
import binascii
import dht
#-----------------------------------------------------------------------
# DEFINITION DES CONSTANTES
#-----------------------------------------------------------------------
#-----------------------------------------------------------------------
# FONCTIONS COMMUNES QUI SERONT APPELEES
#-----------------------------------------------------------------------
pycom.wifi_on_boot(False) #pour eviter crash
#***********************************************************************
#*****
#***** CONFIGURATION
#*****
#***********************************************************************
pycom.heartbeat(False)
#-----------------------------------------------------------------------
# INSTANCIATIONS
#-----------------------------------------------------------------------
th = dht.DTH(Pin('P22', mode=Pin.OPEN_DRAIN),1)
# initialize LoRa in LORAWAN mode.
# Please pick the region that matches where you are using the device:
# Asia = LoRa.AS923
# Australia = LoRa.AU915
# Europe = LoRa.EU868
# United States = LoRa.US915
#SF=[7;12] répartir les SF entre les capteurs
LORA_NODE_DR = 5
if machine.reset_cause() == machine.DEEPSLEEP_RESET:
lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.EU868,sf=7,bandwidth=LoRa.BW_125KHZ)
lora.nvram_restore()
s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
s.setsockopt(socket.SOL_LORA, socket.SO_DR, LORA_NODE_DR)
s.setblocking(False)
s.bind(2)
else:
lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.EU868,sf=7,bandwidth=LoRa.BW_125KHZ)
app_eui = binascii.unhexlify('70BXXX25718') #unique pour l'application
app_key = binascii.unhexlify('07A6599XXXXXXXX1') #a changer pour chaque capteur
lora.join(activation=LoRa.OTAA, auth=(app_eui, app_key), timeout=0) # join a network using OTAA (Over the Air Activation)
while not lora.has_joined(): # wait until the module has joined the network
time.sleep(2.5)
print("not joined yet first time")
s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
s.setsockopt(socket.SOL_LORA, socket.SO_DR, LORA_NODE_DR)
s.setblocking(False)
s.bind(1)
# set the 3 default channels to the same frequency (must be before sending the OTAA join request)
lora.add_channel(0, frequency=868100000, dr_min=0, dr_max=5)
lora.add_channel(1, frequency=868100000, dr_min=0, dr_max=5)
lora.add_channel(2, frequency=868100000, dr_min=0, dr_max=5)
# remove all the non-default channels
for i in range(3, 16):
lora.remove_channel(i)
#***********************************************************************
#*****
#***** BOUCLE PRINCIPALE
#*****
#***********************************************************************
def run():
result = th.read()
s.send(str(result.temperature))
pycom.rgbled(0xff00) #led verte après envoi de message
time.sleep(0.4)
pycom.rgbled(0x0000)
return 0
run()
#reset au bout de 20 sec
lora.nvram_save()
s.close()
machine.deepsleep(20000)
I feel I have tried everything and done the same thing as everybody in the forums but it doesn’t work for me… I’m a bit lost and hope I have a very stupid mistake, if you could help me it would be very nice
here is my application on TTN, we can see I receive the first message, but then nothing is received…
I also tried to use an other SF, but the join request and join accept are always send on SF7 BW125kHz…
If we look at the traffic going through my gateway :
Thanks in advance