Skip to content

Commit

Permalink
Merge pull request #79 from jeremiah-k/windows-serial-fix
Browse files Browse the repository at this point in the history
Windows serial port detection fix
  • Loading branch information
jeremiah-k authored Oct 3, 2024
2 parents d4b015e + 889f47c commit da9fef0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
13 changes: 10 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,26 @@ jobs:
pip install -r requirements.txt
pip install pyinstaller
- name: Get version number
id: get_version
run: echo "::set-output name=version::${GITHUB_REF##*/}"

- name: Build executable
run: pyinstaller --name=mmrelay.exe --onefile --console main.py
run: pyinstaller --name=mmrelay_${{ steps.get_version.outputs.version }}.exe --onefile --console main.py

- name: Build installer
uses: nadeemjazmawe/[email protected]
with:
filepath: "/DAppVersion=${{ github.ref_name }} ./mmrelay.iss"

- name: Rename installer
run: ren MMRelay_setup.exe MMRelay_setup_${{ steps.get_version.outputs.version }}.exe

- name: Upload setup.exe to release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: MMRelay_setup.exe
asset_name: MMRelay_setup.exe
file: MMRelay_setup_${{ steps.get_version.outputs.version }}.exe
asset_name: MMRelay_setup_${{ steps.get_version.outputs.version }}.exe
tag: ${{ github.ref }}
overwrite: true
16 changes: 15 additions & 1 deletion meshtastic_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import threading
import os
import serial # For serial port exceptions
import serial.tools.list_ports # Import serial tools for port listing
from typing import List

import meshtastic.tcp_interface
Expand Down Expand Up @@ -32,6 +33,19 @@
shutting_down = False
reconnect_task = None # To keep track of the reconnect task

def serial_port_exists(port_name):
"""
Check if the specified serial port exists.
Args:
port_name (str): The name of the serial port (e.g., 'COM15' or '/dev/ttyACM0').
Returns:
bool: True if the port exists, False otherwise.
"""
ports = [port.device for port in serial.tools.list_ports.comports()]
return port_name in ports

def connect_meshtastic(force_connect=False):
"""
Establish a connection to the Meshtastic device.
Expand Down Expand Up @@ -72,7 +86,7 @@ def connect_meshtastic(force_connect=False):
logger.info(f"Connecting to serial port {serial_port} ...")

# Check if serial port exists
if not os.path.exists(serial_port):
if not serial_port_exists(serial_port):
logger.warning(f"Serial port {serial_port} does not exist. Waiting...")
time.sleep(5)
attempts += 1
Expand Down

0 comments on commit da9fef0

Please sign in to comment.