-
Notifications
You must be signed in to change notification settings - Fork 0
/
HASviolet_RX.py
executable file
·152 lines (120 loc) · 3.87 KB
/
HASviolet_RX.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/usr/bin/python3
#
# HASviolet RX rf95
#
#
#
# Usage: HASviolet-rx.py [-r] [-s]
#
# OPTIONS
# -h, --help show this help message and exit
# -r, --raw_data Receive raw data
# -s, --signal Signal Strength
#
# REVISION: 20210312-1400
#
#
#
# Import Libraries
#
import argparse
import configparser
import signal
import sys
import time
import json
import subprocess
from HASvioletRF import HASrf
from HASvioletHID import HAShid
#
# STATICS
#
HASviolet_RXLOCK = False # True = RX is running
HASviolet_TXLOCK = False # True = TX is running
HASviolet_LOCAL = "/home/pi/hasviolet-local/" # Config file is in JSON format
HASviolet_SERVER = HASviolet_LOCAL + "server/" # Path to files. Change when Pi
HASviolet_ETC = HASviolet_LOCAL + "etc/" # Config file is in JSON format
HASviolet_CONFIG = HASviolet_ETC + "HASviolet.json" # Config file is in JSON format
HASviolet_SSL_KEY = HASviolet_ETC + "HASviolet.key" # SSL Key
HASviolet_SSL_CRT = HASviolet_ETC + "HASviolet.crt" # Cert Key
HASviolet_PWF = HASviolet_ETC + "HASviolet.pwf" # Password file user:hashedpasswd
HASviolet_MSGS = HASviolet_SERVER + "msgs/HASviolet.msgs" # radio writes msgs received here
HASviolet_LOGIN = HASviolet_SERVER + "HASviolet_LOGIN.html"
HASviolet_LOGINCSS = HASviolet_SERVER + "HASviolet_LOGIN.css"
HASviolet_INDEX = HASviolet_SERVER + "HASviolet_INDEX.html"
HASviolet_INDEXCSS = HASviolet_SERVER + "HASviolet.css"
HASvioletjs = HASviolet_SERVER + "HASviolet.js"
HVDN_LOGO = HASviolet_ETC + "HVDN_logo.xbm"
#
# VARIABLES
#
#
# FUNCTIONS
#
def sigs_handler(signal_received, frame):
# Handle any cleanup here
print('SIGINT or CTRL-C detected. Exiting gracefully')
HASit.cleanup() # rf95 library
#HASit.cleanup_pyl() # pyLora library
HAShat.OLED.text('Goodbye...', 0, 10, 1)
HAShat.OLED.show()
time.sleep(2)
HAShat.OLED.fill(0)
HAShat.OLED.show()
exit(0)
def rx_oled_scroll():
HAShat.OLED.fill(0)
HAShat.OLED.show()
HASit.ppayload = HASit.receive_ascii.split("|")
HAShat.OLED.fill(0)
HAShat.OLED.show()
HAShat.OLED.text(HASit.ppayload[0], 0, 1, 1)
HAShat.OLED.text("RSSI: " + HASit.receive_rssi, 0, 9, 1)
HAShat.OLED.show()
#
# Initialise HASviolet
#
HASit = HASrf()
HAShat = HAShid()
#
# IMPORT ARGS
#
parser = argparse.ArgumentParser(description='HASviolet RX')
parser.add_argument('-r','--raw_data', help='Receive raw data', action='store_true')
parser.add_argument('-s','--signal', help='Signal Strength', action='store_true')
args = vars(parser.parse_args())
arg_hvdn_rawdata = args['raw_data']
arg_signal_rssi = args['signal']
#
# SETUP
#
HAShat.logo(HVDN_LOGO)
# SIGTINT aka control-C is quit
signal.signal(signal.SIGINT, sigs_handler)
# RF and LoRa Config init
HASit.startradio() # rf95 library
#HASit.startradio_pyl() # pyLoraRFM9x Library
#HASit.rfm.on_recv(HASit.onreceive) # pyLoraRFM9x Library (Uses callback for receive)
prevpos = 0
currpos = 0
firstoledline = 7
lastoledline = 23
HAShat.OLED.fill(0)
HAShat.OLED.show()
#
# MAIN
#
# pyLoraRFM9x Library. Uses callback for receive so main is a infinite while loop with pass
# rf95 library. Needs to be executes within an infinite while loop
while True:
HASit.rx()
rx_oled_scroll()
if (arg_signal_rssi):
#datadisplay_string = 'RX:'+ HASit.receive_ascii +':RSSI:'+HASit.receive-rssi
print (HASit.receive_ascii,':RSSI:',HASit.receive_rssi)
else:
print (HASit.receive_ascii)
HAShat.OLED.fill(0)
HAShat.OLED.show()
HASit.cleanup() # rf95 library
#HASit.cleanup_pyl() # pyLora library