diff --git a/README.md b/README.md index a9ce47e..f9b527b 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ # MeshCore Bot -A Python bot that connects to MeshCore mesh networks via serial port or BLE. The bot responds to messages containing configured keywords, executes commands, and provides various data services including weather, solar conditions, and satellite pass information. +A Python bot that connects to MeshCore mesh networks via serial port, BLE, or TCP/IP. The bot responds to messages containing configured keywords, executes commands, and provides various data services including weather, solar conditions, and satellite pass information. ## Features -- **Connection Methods**: Serial port or BLE (Bluetooth Low Energy) +- **Connection Methods**: Serial port, BLE (Bluetooth Low Energy), or TCP/IP - **Keyword Responses**: Configurable keyword-response pairs with template variables - **Command System**: Plugin-based command architecture with built-in commands - **Rate Limiting**: Configurable rate limiting to prevent network spam @@ -76,8 +76,11 @@ The bot uses `config.ini` for all settings. Key configuration sections: ### Connection ```ini [Connection] -connection_type = serial # serial or ble -serial_port = /dev/ttyUSB0 # Serial port path +connection_type = serial # serial, ble, or tcp +serial_port = /dev/ttyUSB0 # Serial port path (for serial) +#hostname = 192.168.1.60 # TCP hostname/IP (for TCP) +#tcp_port = 5000 # TCP port (for TCP) +#ble_device_name = MeshCore # BLE device name (for BLE) timeout = 30 # Connection timeout ``` @@ -217,6 +220,17 @@ help = "Bot Help: test, ping, help, hello, cmd, wx, aqi, sun, moon, solar, hfcon ble_device_name = MeshCore ``` +### TCP Connection + +1. Ensure your MeshCore device has TCP/IP connectivity (e.g., via gateway or bridge) +2. Configure TCP in `config.ini`: + ```ini + [Connection] + connection_type = tcp + hostname = 192.168.1.60 # IP address or hostname + tcp_port = 5000 # TCP port (default: 5000) + ``` + ## Troubleshooting ### Common Issues @@ -231,11 +245,18 @@ help = "Bot Help: test, ping, help, hello, cmd, wx, aqi, sun, moon, solar, hfcon - Check device name in config - Verify BLE permissions -3. **Message Parsing Errors**: +3. **TCP Connection Issues**: + - Verify hostname/IP address is correct + - Check that TCP port is open and accessible + - Ensure network connectivity to the device + - Verify the MeshCore device supports TCP connections + - Check firewall settings if connection fails + +4. **Message Parsing Errors**: - Enable DEBUG logging for detailed information - Check meshcore library documentation for protocol details -4. **Rate Limiting**: +5. **Rate Limiting**: - Adjust `rate_limit_seconds` in config - Check logs for rate limiting messages diff --git a/config.ini.example b/config.ini.example index 3382606..d8fc182 100644 --- a/config.ini.example +++ b/config.ini.example @@ -1,7 +1,8 @@ [Connection] -# Connection type: serial or ble +# Connection type: serial, ble, or tcp # serial: Connect via USB serial port # ble: Connect via Bluetooth Low Energy +# tcp: Connect via TCP/IP connection_type = serial # Serial port (for serial connection) @@ -12,6 +13,11 @@ serial_port = /dev/ttyUSB0 # Leave commented out for auto-detection, or specify exact device name #ble_device_name = MeshCore +# TCP hostname or IP address (for TCP connection) +#hostname = 192.168.1.60 +# TCP port (for TCP connection) +#tcp_port = 5000 + # Connection timeout in seconds timeout = 30 diff --git a/modules/core.py b/modules/core.py index fa8cb27..b89b66e 100644 --- a/modules/core.py +++ b/modules/core.py @@ -122,9 +122,10 @@ class MeshCoreBot: def create_default_config(self): """Create default configuration file""" default_config = """[Connection] -# Connection type: serial or ble +# Connection type: serial, ble, or tcp # serial: Connect via USB serial port # ble: Connect via Bluetooth Low Energy +# tcp: Connect via TCP/IP connection_type = serial # Serial port (for serial connection) @@ -135,6 +136,11 @@ serial_port = /dev/ttyUSB0 # Leave commented out for auto-detection, or specify exact device name #ble_device_name = MeshCore +# TCP hostname or IP address (for TCP connection) +#hostname = 192.168.1.60 +# TCP port (for TCP connection) +#tcp_port = 5000 + # Connection timeout in seconds timeout = 30 @@ -548,6 +554,15 @@ use_zulu_time = false serial_port = self.config.get('Connection', 'serial_port', fallback='/dev/ttyUSB0') self.logger.info(f"Connecting via serial port: {serial_port}") self.meshcore = await meshcore.MeshCore.create_serial(serial_port, debug=False) + elif connection_type == 'tcp': + # Create TCP connection + hostname = self.config.get('Connection', 'hostname', fallback=None) + tcp_port = self.config.getint('Connection', 'tcp_port', fallback=5000) + if not hostname: + self.logger.error("TCP connection requires 'hostname' to be set in config") + return False + self.logger.info(f"Connecting via TCP: {hostname}:{tcp_port}") + self.meshcore = await meshcore.MeshCore.create_tcp(hostname, tcp_port, debug=False) else: # Create BLE connection (default) ble_device_name = self.config.get('Connection', 'ble_device_name', fallback=None)