-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
37 lines (27 loc) · 1.1 KB
/
server.py
File metadata and controls
37 lines (27 loc) · 1.1 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
import threading, queue
from sb import util, radio, collector, processor
from sb.radio import NRF24Radio
from sb.collector import SensorDataCollector
from sb.processor import SensorDataProcessor, WebServiceProcessor, DatabaseProcessor
from twisted.internet import reactor, task
from sb.util import Log
globalLog = Log().buildLogger()
#handle shutting down all the things
def shutdown(radio):
radio.end()
globalLog.info("Finished shutting down the radio and GPIO.")
if __name__ == "__main__":
globalLog.info("Startin up NRF24 radio")
radio = NRF24Radio()
radio.listen()
collector = SensorDataCollector(radio)
globalLog.info("Collector created")
processor = SensorDataProcessor()
processor.addConsumer(WebServiceProcessor())
processor.addConsumer(DatabaseProcessor())
collector.addConsumer(processor)
radio.irqCallback(lambda _: reactor.callFromThread(collector.listenForData))
globalLog.info("About to start the application server")
reactor.suggestThreadPoolSize(20)
reactor.addSystemEventTrigger("before", "shutdown", shutdown, radio)
reactor.run()