mirror of
https://github.com/TheCommsChannel/TC2-BBS-mesh.git
synced 2025-12-14 23:44:42 -05:00
I added a flag and function to handle when the connection to the node is lost. This will now close the script and docker should detect this and restart the container
101 lines
3.5 KiB
Python
101 lines
3.5 KiB
Python
#!/usr/bin/env python3
|
|
|
|
"""
|
|
TC²-BBS Server for Meshtastic by TheCommsChannel (TC²)
|
|
Date: 07/14/2024
|
|
Version: 0.1.6
|
|
|
|
Description:
|
|
The system allows for mail message handling, bulletin boards, and a channel
|
|
directory. It uses a configuration file for setup details and an SQLite3
|
|
database for data storage. Mail messages and bulletins are synced with
|
|
other BBS servers listed in the config.ini file.
|
|
"""
|
|
|
|
import logging
|
|
import time
|
|
|
|
from config_init import initialize_config, get_interface, init_cli_parser, merge_config
|
|
from db_operations import initialize_database
|
|
from js8call_integration import JS8CallClient
|
|
from message_processing import on_receive
|
|
from pubsub import pub
|
|
|
|
# General logging
|
|
logging.basicConfig(
|
|
level=logging.INFO,
|
|
format='%(asctime)s - %(levelname)s - %(message)s',
|
|
datefmt='%Y-%m-%d %H:%M:%S'
|
|
)
|
|
|
|
# JS8Call logging
|
|
js8call_logger = logging.getLogger('js8call')
|
|
js8call_logger.setLevel(logging.DEBUG)
|
|
js8call_handler = logging.StreamHandler()
|
|
js8call_handler.setLevel(logging.DEBUG)
|
|
js8call_formatter = logging.Formatter('%(asctime)s - JS8Call - %(levelname)s - %(message)s', '%Y-%m-%d %H:%M:%S')
|
|
js8call_handler.setFormatter(js8call_formatter)
|
|
js8call_logger.addHandler(js8call_handler)
|
|
|
|
continue_running = True
|
|
|
|
def display_banner():
|
|
banner = """
|
|
████████╗ ██████╗██████╗ ██████╗ ██████╗ ███████╗
|
|
╚══██╔══╝██╔════╝╚════██╗ ██╔══██╗██╔══██╗██╔════╝
|
|
██║ ██║ █████╔╝█████╗██████╔╝██████╔╝███████╗
|
|
██║ ██║ ██╔═══╝ ╚════╝██╔══██╗██╔══██╗╚════██║
|
|
██║ ╚██████╗███████╗ ██████╔╝██████╔╝███████║
|
|
╚═╝ ╚═════╝╚══════╝ ╚═════╝ ╚═════╝ ╚══════╝
|
|
Meshtastic Version
|
|
"""
|
|
print(banner)
|
|
|
|
def main():
|
|
display_banner()
|
|
args = init_cli_parser()
|
|
config_file = None
|
|
if args.config is not None:
|
|
config_file = args.config
|
|
system_config = initialize_config(config_file)
|
|
|
|
merge_config(system_config, args)
|
|
|
|
interface = get_interface(system_config)
|
|
interface.bbs_nodes = system_config['bbs_nodes']
|
|
interface.allowed_nodes = system_config['allowed_nodes']
|
|
|
|
logging.info(f"TC²-BBS is running on {system_config['interface_type']} interface...")
|
|
|
|
initialize_database()
|
|
|
|
def receive_packet(packet, interface):
|
|
on_receive(packet, interface)
|
|
|
|
def on_connection_loss(interface):
|
|
logging.error("Connection to Meshtastic device lost.")
|
|
global continue_running
|
|
continue_running = False
|
|
|
|
pub.subscribe(receive_packet, system_config['mqtt_topic'])
|
|
pub.subscribe(on_connection_loss, 'meshtastic.connection.lost')
|
|
|
|
# Initialize and start JS8Call Client if configured
|
|
js8call_client = JS8CallClient(interface)
|
|
js8call_client.logger = js8call_logger
|
|
|
|
if js8call_client.db_conn:
|
|
js8call_client.connect()
|
|
|
|
try:
|
|
while continue_running:
|
|
time.sleep(1)
|
|
|
|
except KeyboardInterrupt:
|
|
logging.info("Shutting down the server...")
|
|
interface.close()
|
|
if js8call_client.connected:
|
|
js8call_client.close()
|
|
|
|
if __name__ == "__main__":
|
|
main()
|