Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TP lora COOC
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Monitor
Incidents
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LANGLAIS Charlotte
TP lora COOC
Commits
4d06cf6f
Commit
4d06cf6f
authored
3 years ago
by
LANGLAIS Charlotte
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
69720349
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
OTAA/main_template.py
+55
-0
55 additions, 0 deletions
OTAA/main_template.py
with
55 additions
and
0 deletions
OTAA/main_template.py
0 → 100644
+
55
−
0
View file @
4d06cf6f
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),
# choose dr = 0 if the gateway is not close to your device, try different dr if needed
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
(
'
--------------------------------
'
)
# replace the dash by the AppKey provided by TTN
#uncomment to use LoRaWAN application provided dev_eui
dev_eui
=
ubinascii
.
unhexlify
(
'
----------------
'
)
# replace the dash by the DevEUI provided to TTN
pycom
.
rgbled
(
0xff0000
)
#red
lora
=
LoRa
(
mode
=
LoRa
.
LORAWAN
,
region
=
LoRa
.
EU868
)
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
)
# without downlink transmission first
#rx, port = s.recvfrom(256)
#if rx:
# print('Received: {}, on port: {}'.format(rx, port))
time
.
sleep
(
6
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment