-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 'LoRa_Gateway_for_WUSN/' from commit 'bf69febbee13b90e9d9c53e2e23…
…43e2a60d125ed' git-subtree-dir: LoRa_Gateway_for_WUSN git-subtree-mainline: d7c80cf git-subtree-split: bf69feb
- Loading branch information
Showing
59 changed files
with
489,519 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
Large diffs are not rendered by default.
Oops, something went wrong.
1,093 changes: 1,093 additions & 0 deletions
1,093
LoRa_Gateway_for_WUSN/Deepsleep/lib/RFM69registers.py
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import pycom | ||
import time | ||
|
||
pycom.heartbeat(False) | ||
|
||
class printing(object): | ||
def __init__(self): | ||
print("TEST MIT KLASSE") | ||
|
||
def longGreenBlink(): | ||
pycom.rgbled(0x00FF00) # Green | ||
time.sleep(5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import pycom | ||
import RFM69 | ||
from RFM69registers import * | ||
import time | ||
from network import LoRa | ||
import machine | ||
import socket | ||
import ubinascii | ||
import struct | ||
|
||
#lower power consumption | ||
pycom.heartbeat(False) | ||
pycom.rgbled(0x000000) | ||
pycom.wifi_on_boot(False) | ||
|
||
###########VARS################# | ||
receivedData =[] | ||
|
||
###########SETUP RFM################ | ||
if machine.wake_reason()[0] == 0: #If the LoPy just got startet, configure RFM69 and go to deepsleep for power saving | ||
print("Gerade hochgefahren, führe Setup durch") | ||
rfm = RFM69.RFM69(RF69_433MHZ, 1, 42, False) | ||
results = rfm.readAllRegs() | ||
for result in results: | ||
print(result) | ||
rfm.rcCalibration() | ||
rfm.setHighPower(True) | ||
rfm.encrypt("sampleEncryptKey") | ||
rfm.receiveBegin() | ||
f = open('/flash/data.csv', 'w') | ||
f.write('') | ||
f.close() | ||
print("Gute Nacht") | ||
machine.pin_deepsleep_wakeup(['P9'], machine.WAKEUP_ANY_HIGH) | ||
machine.deepsleep(200000) | ||
|
||
elif machine.wake_reason()[0] == 2: | ||
print("Timer interrupt") | ||
elif machine.wake_reason()[0] == 1: #If the LoPy woke up from deepsleep, define the class, but don't reset the RFM chip | ||
print("Pin Interrupt") | ||
rfm = RFM69.RFM69(RF69_433MHZ, 1, 42, False, wakeup = True) | ||
rfm.receiveMessage() | ||
receivedData = (["".join([chr(letter) for letter in rfm.DATA]), rfm.SENDERID, rfm.RSSI]) | ||
if rfm.ACKRequested(): | ||
rfm.sendACK() | ||
|
||
# #####UNGETESTET########## | ||
# f = open('/flash/data.csv', 'a') | ||
# oldData = f.readall() | ||
# if oldData == '': | ||
# f.write(currentData) | ||
# f.close() | ||
# #put RFM69 in receiving Mode and put it back to deepsleep | ||
# rfm.receiveBegin() | ||
# print("Gute Nacht") | ||
# machine.pin_deepsleep_wakeup(['P9'], machine.WAKEUP_ANY_HIGH) | ||
# machine.deepsleep(200000) | ||
# elif len(oldData.split(';')) < 5: | ||
# f.write(';' + str(currentData)) | ||
# f.close() | ||
# #put RFM69 in receiving Mode and put it back to deepsleep | ||
# rfm.receiveBegin() | ||
# print("Gute Nacht") | ||
# machine.pin_deepsleep_wakeup(['P9'], machine.WAKEUP_ANY_HIGH) | ||
# machine.deepsleep(200000) | ||
# else: | ||
# receivedData = oldData.split(';').append(currentData) | ||
# f.close() | ||
# f.open('/flash/data.csv', 'a') | ||
# f.write('') | ||
# f.close() | ||
|
||
|
||
###########SETUP LORA############### | ||
# Initialise LoRa in LORAWAN mode. | ||
lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.EU868) | ||
|
||
# create an OTAA authentication parameters | ||
app_eui = ubinascii.unhexlify('70B3D57ED001A20A') | ||
app_key = ubinascii.unhexlify('10DC7520366D57071EB4B4AC23968E39') | ||
|
||
# join a network using ABP (Activation By Personalization) | ||
lora.join(activation=LoRa.OTAA, auth=(app_eui, app_key), timeout=0) | ||
|
||
# wait until the module has joined the network | ||
while not lora.has_joined(): | ||
time.sleep(2.5) | ||
print('Not yet joined...') | ||
|
||
# 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, 5) | ||
# selecting confirmed type of messages | ||
s.setsockopt(socket.SOL_LORA, socket.SO_CONFIRMED, True) | ||
|
||
# make the socket blocking | ||
# (waits for the data to be sent and for the 2 receive windows to expire) | ||
s.setblocking(True) | ||
|
||
print("SENDING") | ||
# send receivedData | ||
try: | ||
s.send(str(receivedData)) | ||
except: | ||
print("Senden fehlgeschlagen") | ||
|
||
# make the socket non-blocking | ||
# (because if there's no data received it will block forever...) | ||
s.setblocking(False) | ||
|
||
#put RFM69 in receiving Mode and put it back to deepsleep | ||
rfm.receiveBegin() | ||
print("Gute Nacht") | ||
machine.pin_deepsleep_wakeup(['P9'], machine.WAKEUP_ANY_HIGH) | ||
machine.deepsleep(200000) |
Binary file added
BIN
+35.8 KB
LoRa_Gateway_for_WUSN/Field_Experiment/Field_experiment_2020_06_12.ods
Binary file not shown.
Binary file added
BIN
+78.8 KB
LoRa_Gateway_for_WUSN/Field_Experiment/Field_experiment_2020_06_16.ods
Binary file not shown.
Binary file added
BIN
+200 KB
LoRa_Gateway_for_WUSN/Field_Experiment/Field_experiment_2020_06_18.ods
Binary file not shown.
Oops, something went wrong.