-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathmain.py
34 lines (29 loc) · 1.14 KB
/
main.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
# Copyright (C) 2023 Salvatore Sanfilippo <[email protected]>
# All Rights Reserved
#
# This code is released under the BSD 2 clause license.
# See the LICENSE file for more information
import uasyncio as asyncio
from freakwan import FreakWAN
fw = FreakWAN()
# Connect to WiFi ASAP if the configuration demands so.
wifi_network = fw.config.get('wifi_default_network')
if wifi_network:
fw.start_wifi(wifi_network, fw.config['wifi'][wifi_network])
# All the FreakWAN execution is performed in the 'run' loop, and
# in the callbacks registered during the initialization.
asyncio.create_task(fw.cron())
asyncio.create_task(fw.send_hello_message())
asyncio.create_task(fw.send_periodic_message())
asyncio.create_task(fw.receive_from_serial())
if fw.config.get('irc') and fw.config['irc']['enabled']: fw.start_irc()
if fw.bleuart: fw.bleuart.set_callback(fw.ble_receive_callback)
loop = asyncio.get_event_loop()
loop.set_exception_handler(fw.crash_handler)
try:
loop.run_forever()
except KeyboardInterrupt:
fw.scroller.print("")
fw.scroller.print("--- Stopped ---")
fw.scroller.refresh()
fw.lora.reset() # Avoid receiving messages while stopped