Skip to content

Commit

Permalink
Add 'LoRa_Gateway_for_WUSN/' from commit 'bf69febbee13b90e9d9c53e2e23…
Browse files Browse the repository at this point in the history
…43e2a60d125ed'

git-subtree-dir: LoRa_Gateway_for_WUSN
git-subtree-mainline: d7c80cf
git-subtree-split: bf69feb
  • Loading branch information
jdede committed Apr 14, 2021
2 parents d7c80cf + bf69feb commit 4850c53
Show file tree
Hide file tree
Showing 59 changed files with 489,519 additions and 0 deletions.
Empty file.
485 changes: 485 additions & 0 deletions LoRa_Gateway_for_WUSN/Deepsleep/lib/RFM69.py

Large diffs are not rendered by default.

1,093 changes: 1,093 additions & 0 deletions LoRa_Gateway_for_WUSN/Deepsleep/lib/RFM69registers.py

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions LoRa_Gateway_for_WUSN/Deepsleep/lib/mytestlib.py
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)
117 changes: 117 additions & 0 deletions LoRa_Gateway_for_WUSN/Deepsleep/main.py
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 not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 4850c53

Please sign in to comment.