-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
65 lines (52 loc) · 1.69 KB
/
main.py
File metadata and controls
65 lines (52 loc) · 1.69 KB
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
import sys
import time
#import your module
import rateTest as exampleModule
import digitalio
import board
import busio
import adafruit_rfm9x
import time
import os
RADIO_FREQ_MHZ = 915.0
CS = digitalio.DigitalInOut(board.GP5)
RESET = digitalio.DigitalInOut(board.GP6)
spi = busio.SPI(board.GP2, MOSI=board.GP3, MISO=board.GP4)
rfm9x = adafruit_rfm9x.RFM9x(spi, CS, RESET, RADIO_FREQ_MHZ)
rfm9x = adafruit_rfm9x.RFM9x(spi, CS, RESET, RADIO_FREQ_MHZ, baudrate=1000000)
rfm9x.coding_rate = 5
rfm9x.spreading_factor = 8
rfm9x.tx_power = 23
rfm9x.enable_crc = False
rfm9x.node = 200
rfm9x.destination = 201
#list will contain all data collection modules
modules = []
#append it to the list of modules
modules.append(exampleModule.exampleModule())
for module in modules:
#always use try except when calling module functions to prevent one module
# from crashing the whole program
try:
module.setup()
except:
print(f"an exception occurred while setting up {module.name}")
running = True
message_length = 64
while(running):
transmit = ""
for module in modules:
try:
print(module)
poll_result = module.wrap_poll()
if (poll_result is not None):
transmit += f"[\"{module.module_name}\", \"{poll_result}\"]"
except:
e = sys.exception()
transmit += f"an exception occurred when polling module \"{module.module_name}\" \n{e}"
for i in range(len(transmit) // message_length + 1):
message = transmit[i : min( (i + 1) * message_length, len(transmit) )]
if message != "":
rfm9x.send_with_ack(message)
print(f"sending: {message}")
# print("hello world")