Skip to content
Snippets Groups Projects
Commit 69720349 authored by LANGLAIS Charlotte's avatar LANGLAIS Charlotte
Browse files

Delete main.py

parent b7cc456a
No related branches found
No related tags found
No related merge requests found
from network import LoRa
import socket
import time
import struct
import ubinascii
import pycom
def connect_to_ttn(lora_object):
"""Receives a lora object and tries to join"""
# join a network using OTAA (Over the Air Activation)
lora_object.join(activation=LoRa.OTAA, auth=(dev_eui, app_eui, app_key), timeout=0, dr=0)
# wait until the module has joined the network
while not lora_object.has_joined():
time.sleep(5)
print('Not yet joined...')
pycom.rgbled(0x7f7f00) #yellow
app_eui = ubinascii.unhexlify('0000000000000000')
app_key = ubinascii.unhexlify('310A3C251B1397A74E7DAF902DCD9DD0')
#uncomment to use LoRaWAN application provided dev_eui
dev_eui = ubinascii.unhexlify('70B3D5499A64CD75')
#for channel in range(0, 72):
#lora.add_channel(channel, frequency=903900000, dr_min=0, dr_max=3)
pycom.rgbled(0xff0000) #red
lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.EU868, device_class=LoRa.CLASS_C)
lora.nvram_restore() #if there is nothing to restore it will return a False
connect_to_ttn(lora)
print("CONNECTED!!")
pycom.rgbled(0x00ff00) #green
lora.nvram_erase()
# create a LoRa socket
s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
# set the LoRaWAN data rate
s.setsockopt(socket.SOL_LORA, socket.SO_DR, 0)
# make the socket blocking
s.setblocking(True)
for i in range (20):
pkt = b'PKT ' + bytes([i])
print('Sending:', pkt)
s.send(pkt)
time.sleep(4)
rx, port = s.recvfrom(256)
if rx:
print('Received: {}, on port: {}'.format(rx, port))
time.sleep(6)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment