-
Notifications
You must be signed in to change notification settings - Fork 28
/
main.ttn.py
75 lines (60 loc) · 1.84 KB
/
main.ttn.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
# -*- coding: utf-8 -*-
#
# Hiveeyes MicroPython Datalogger
# https://github.com/hiveeyes/hiveeyes-micropython-firmware
#
# (c) 2019 Richard Pobering <richard@hiveeyes.org>
# (c) 2019 Andreas Motl <andreas@hiveeyes.org>
# License: GNU General Public License, Version 3
#
import time
import settings
from terkin import logging
from terkin.datalogger import TerkinDatalogger
log = logging.getLogger(__name__)
class ExampleDatalogger(TerkinDatalogger):
"""
Yet another data logger. This time for MicroPython.
"""
# Naming things.
name = 'Example MicroPython Datalogger'
def loop(self):
"""
Loop function. Do what I mean.
"""
# It's your turn.
log.info('Custom loop')
# Send dummy payload to TTN over LoRaWAN.
# TODO: Send real measurement data.
if self.settings.get('networking.lora.antenna_attached'):
self.ttn_test()
# Finally, schedule other system tasks.
super().loop()
def read_sensors(self):
# CayenneLPP example
# Payload Base64: AWf8sABnAag=
# Payload Hex: 0167FCB0006701A8
data = {
'temperature_0': 42.42,
'temperature_1': -84.84,
}
return data
def ttn_test(self):
"""
Send dummy payload to TTN over LoRaWAN, without taking too much Airtime.
"""
for i in range(1, 39):
j = i % 10
if j == 0 or i == 1:
payload = "ff"
success = self.device.networking.lora_send(payload)
if success:
print("[LoRa] send:", payload)
time.sleep(1)
def main():
"""Start the data logger application."""
datalogger = ExampleDatalogger(settings)
datalogger.start()
if __name__ == '__main__':
"""Main application entrypoint."""
main()