mirror of
https://github.com/meshtastic/python.git
synced 2025-12-26 17:37:51 -05:00
Compare commits
12 Commits
2.6.1
...
dependabot
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bf89edf106 | ||
|
|
622a435465 | ||
|
|
56680f8da6 | ||
|
|
321a960c13 | ||
|
|
4668852b0b | ||
|
|
c3973117c8 | ||
|
|
d456e4ce30 | ||
|
|
ec78f62992 | ||
|
|
dfc9547ffc | ||
|
|
ee0f73a20e | ||
|
|
2e73fe310c | ||
|
|
d4bc39153a |
@@ -83,6 +83,17 @@ class BLEInterface(MeshInterface):
|
||||
# Note: the on disconnected callback will call our self.close which will make us nicely wait for threads to exit
|
||||
self._exit_handler = atexit.register(self.client.disconnect)
|
||||
|
||||
def __repr__(self):
|
||||
rep = f"BLEInterface(address={self.client.address if self.client else None!r}"
|
||||
if self.debugOut is not None:
|
||||
rep += f", debugOut={self.debugOut!r}"
|
||||
if self.noProto:
|
||||
rep += ", noProto=True"
|
||||
if self.noNodes:
|
||||
rep += ", noNodes=True"
|
||||
rep += ")"
|
||||
return rep
|
||||
|
||||
def from_num_handler(self, _, b: bytes) -> None: # pylint: disable=C0116
|
||||
"""Handle callbacks for fromnum notify.
|
||||
Note: this method does not need to be async because it is just setting a bool.
|
||||
|
||||
@@ -42,6 +42,15 @@ class Node:
|
||||
|
||||
self.gotResponse = None
|
||||
|
||||
def __repr__(self):
|
||||
r = f"Node({self.iface!r}, 0x{self.nodeNum:08x}"
|
||||
if self.noProto:
|
||||
r += ", noProto=True"
|
||||
if self._timeout.expireTimeout != 300:
|
||||
r += ", timeout={self._timeout.expireTimeout!r}"
|
||||
r += ")"
|
||||
return r
|
||||
|
||||
def showChannels(self):
|
||||
"""Show human readable description of our channels."""
|
||||
print("Channels:")
|
||||
@@ -983,7 +992,7 @@ class Node:
|
||||
p,
|
||||
self.nodeNum,
|
||||
portNum=portnums_pb2.PortNum.ADMIN_APP,
|
||||
wantAck=False,
|
||||
wantAck=True,
|
||||
wantResponse=wantResponse,
|
||||
onResponse=onResponse,
|
||||
channelIndex=adminIndex,
|
||||
|
||||
44
meshtastic/protobuf/config_pb2.py
generated
44
meshtastic/protobuf/config_pb2.py
generated
File diff suppressed because one or more lines are too long
20
meshtastic/protobuf/config_pb2.pyi
generated
20
meshtastic/protobuf/config_pb2.pyi
generated
@@ -956,20 +956,24 @@ class Config(google.protobuf.message.Message):
|
||||
DESCRIPTOR: google.protobuf.descriptor.EnumDescriptor
|
||||
OLED_AUTO: Config.DisplayConfig._OledType.ValueType # 0
|
||||
"""
|
||||
Default / Auto
|
||||
Default / Autodetect
|
||||
"""
|
||||
OLED_SSD1306: Config.DisplayConfig._OledType.ValueType # 1
|
||||
"""
|
||||
Default / Auto
|
||||
Default / Autodetect
|
||||
"""
|
||||
OLED_SH1106: Config.DisplayConfig._OledType.ValueType # 2
|
||||
"""
|
||||
Default / Auto
|
||||
Default / Autodetect
|
||||
"""
|
||||
OLED_SH1107: Config.DisplayConfig._OledType.ValueType # 3
|
||||
"""
|
||||
Can not be auto detected but set by proto. Used for 128x128 screens
|
||||
"""
|
||||
OLED_SH1107_128_64: Config.DisplayConfig._OledType.ValueType # 4
|
||||
"""
|
||||
Can not be auto detected but set by proto. Used for 128x64 screens
|
||||
"""
|
||||
|
||||
class OledType(_OledType, metaclass=_OledTypeEnumTypeWrapper):
|
||||
"""
|
||||
@@ -978,20 +982,24 @@ class Config(google.protobuf.message.Message):
|
||||
|
||||
OLED_AUTO: Config.DisplayConfig.OledType.ValueType # 0
|
||||
"""
|
||||
Default / Auto
|
||||
Default / Autodetect
|
||||
"""
|
||||
OLED_SSD1306: Config.DisplayConfig.OledType.ValueType # 1
|
||||
"""
|
||||
Default / Auto
|
||||
Default / Autodetect
|
||||
"""
|
||||
OLED_SH1106: Config.DisplayConfig.OledType.ValueType # 2
|
||||
"""
|
||||
Default / Auto
|
||||
Default / Autodetect
|
||||
"""
|
||||
OLED_SH1107: Config.DisplayConfig.OledType.ValueType # 3
|
||||
"""
|
||||
Can not be auto detected but set by proto. Used for 128x128 screens
|
||||
"""
|
||||
OLED_SH1107_128_64: Config.DisplayConfig.OledType.ValueType # 4
|
||||
"""
|
||||
Can not be auto detected but set by proto. Used for 128x64 screens
|
||||
"""
|
||||
|
||||
class _DisplayMode:
|
||||
ValueType = typing.NewType("ValueType", builtins.int)
|
||||
|
||||
16
meshtastic/protobuf/mesh_pb2.py
generated
16
meshtastic/protobuf/mesh_pb2.py
generated
File diff suppressed because one or more lines are too long
56
meshtastic/protobuf/mesh_pb2.pyi
generated
56
meshtastic/protobuf/mesh_pb2.pyi
generated
@@ -421,6 +421,26 @@ class _HardwareModelEnumTypeWrapper(google.protobuf.internal.enum_type_wrapper._
|
||||
"""
|
||||
Heltec HRI-3621 industrial probe
|
||||
"""
|
||||
RESERVED_FRIED_CHICKEN: _HardwareModel.ValueType # 93
|
||||
"""
|
||||
Reserved Fried Chicken ID for future use
|
||||
"""
|
||||
HELTEC_MESH_POCKET: _HardwareModel.ValueType # 94
|
||||
"""
|
||||
Heltec Magnetic Power Bank with Meshtastic compatible
|
||||
"""
|
||||
SEEED_SOLAR_NODE: _HardwareModel.ValueType # 95
|
||||
"""
|
||||
Seeed Solar Node
|
||||
"""
|
||||
NOMADSTAR_METEOR_PRO: _HardwareModel.ValueType # 96
|
||||
"""
|
||||
NomadStar Meteor Pro https://nomadstar.ch/
|
||||
"""
|
||||
CROWPANEL: _HardwareModel.ValueType # 97
|
||||
"""
|
||||
Elecrow CrowPanel Advance models, ESP32-S3 and TFT with SX1262 radio plugin
|
||||
"""
|
||||
PRIVATE_HW: _HardwareModel.ValueType # 255
|
||||
"""
|
||||
------------------------------------------------------------------------------------------------------------------------------------------
|
||||
@@ -825,6 +845,26 @@ HELTEC_SENSOR_HUB: HardwareModel.ValueType # 92
|
||||
"""
|
||||
Heltec HRI-3621 industrial probe
|
||||
"""
|
||||
RESERVED_FRIED_CHICKEN: HardwareModel.ValueType # 93
|
||||
"""
|
||||
Reserved Fried Chicken ID for future use
|
||||
"""
|
||||
HELTEC_MESH_POCKET: HardwareModel.ValueType # 94
|
||||
"""
|
||||
Heltec Magnetic Power Bank with Meshtastic compatible
|
||||
"""
|
||||
SEEED_SOLAR_NODE: HardwareModel.ValueType # 95
|
||||
"""
|
||||
Seeed Solar Node
|
||||
"""
|
||||
NOMADSTAR_METEOR_PRO: HardwareModel.ValueType # 96
|
||||
"""
|
||||
NomadStar Meteor Pro https://nomadstar.ch/
|
||||
"""
|
||||
CROWPANEL: HardwareModel.ValueType # 97
|
||||
"""
|
||||
Elecrow CrowPanel Advance models, ESP32-S3 and TFT with SX1262 radio plugin
|
||||
"""
|
||||
PRIVATE_HW: HardwareModel.ValueType # 255
|
||||
"""
|
||||
------------------------------------------------------------------------------------------------------------------------------------------
|
||||
@@ -1068,6 +1108,14 @@ class _ExcludedModulesEnumTypeWrapper(google.protobuf.internal.enum_type_wrapper
|
||||
"""
|
||||
Paxcounter module
|
||||
"""
|
||||
BLUETOOTH_CONFIG: _ExcludedModules.ValueType # 8192
|
||||
"""
|
||||
Bluetooth config (not technically a module, but used to indicate bluetooth capabilities)
|
||||
"""
|
||||
NETWORK_CONFIG: _ExcludedModules.ValueType # 16384
|
||||
"""
|
||||
Network config (not technically a module, but used to indicate network capabilities)
|
||||
"""
|
||||
|
||||
class ExcludedModules(_ExcludedModules, metaclass=_ExcludedModulesEnumTypeWrapper):
|
||||
"""
|
||||
@@ -1132,6 +1180,14 @@ PAXCOUNTER_CONFIG: ExcludedModules.ValueType # 4096
|
||||
"""
|
||||
Paxcounter module
|
||||
"""
|
||||
BLUETOOTH_CONFIG: ExcludedModules.ValueType # 8192
|
||||
"""
|
||||
Bluetooth config (not technically a module, but used to indicate bluetooth capabilities)
|
||||
"""
|
||||
NETWORK_CONFIG: ExcludedModules.ValueType # 16384
|
||||
"""
|
||||
Network config (not technically a module, but used to indicate network capabilities)
|
||||
"""
|
||||
global___ExcludedModules = ExcludedModules
|
||||
|
||||
@typing.final
|
||||
|
||||
44
meshtastic/protobuf/module_config_pb2.py
generated
44
meshtastic/protobuf/module_config_pb2.py
generated
File diff suppressed because one or more lines are too long
8
meshtastic/protobuf/module_config_pb2.pyi
generated
8
meshtastic/protobuf/module_config_pb2.pyi
generated
@@ -554,6 +554,10 @@ class ModuleConfig(google.protobuf.message.Message):
|
||||
"""NMEA messages specifically tailored for CalTopo"""
|
||||
WS85: ModuleConfig.SerialConfig._Serial_Mode.ValueType # 6
|
||||
"""Ecowitt WS85 weather station"""
|
||||
VE_DIRECT: ModuleConfig.SerialConfig._Serial_Mode.ValueType # 7
|
||||
"""VE.Direct is a serial protocol used by Victron Energy products
|
||||
https://beta.ivc.no/wiki/index.php/Victron_VE_Direct_DIY_Cable
|
||||
"""
|
||||
|
||||
class Serial_Mode(_Serial_Mode, metaclass=_Serial_ModeEnumTypeWrapper):
|
||||
"""
|
||||
@@ -569,6 +573,10 @@ class ModuleConfig(google.protobuf.message.Message):
|
||||
"""NMEA messages specifically tailored for CalTopo"""
|
||||
WS85: ModuleConfig.SerialConfig.Serial_Mode.ValueType # 6
|
||||
"""Ecowitt WS85 weather station"""
|
||||
VE_DIRECT: ModuleConfig.SerialConfig.Serial_Mode.ValueType # 7
|
||||
"""VE.Direct is a serial protocol used by Victron Energy products
|
||||
https://beta.ivc.no/wiki/index.php/Victron_VE_Direct_DIY_Cable
|
||||
"""
|
||||
|
||||
ENABLED_FIELD_NUMBER: builtins.int
|
||||
ECHO_FIELD_NUMBER: builtins.int
|
||||
|
||||
2
meshtastic/protobuf/telemetry_pb2.pyi
generated
2
meshtastic/protobuf/telemetry_pb2.pyi
generated
@@ -723,7 +723,7 @@ class AirQualityMetrics(google.protobuf.message.Message):
|
||||
"""
|
||||
co2: builtins.int
|
||||
"""
|
||||
10.0um Particle Count
|
||||
CO2 concentration in ppm
|
||||
"""
|
||||
def __init__(
|
||||
self,
|
||||
|
||||
@@ -46,12 +46,7 @@ class SerialInterface(StreamInterface):
|
||||
|
||||
logging.debug(f"Connecting to {self.devPath}")
|
||||
|
||||
# set port to None to prevent automatically opening
|
||||
self.stream = serial.Serial(
|
||||
port=None, baudrate=115200, exclusive=True, timeout=0.5, write_timeout=0
|
||||
)
|
||||
|
||||
# first we need to clear HUPCL (UNIX) or clear RTS/DTR (Windows) so the device will not reboot based on RTS and/or DTR
|
||||
# first we need to set the HUPCL so the device will not reboot based on RTS and/or DTR
|
||||
# see https://github.com/pyserial/pyserial/issues/124
|
||||
if platform.system() != "Windows":
|
||||
with open(self.devPath, encoding="utf8") as f:
|
||||
@@ -60,14 +55,10 @@ class SerialInterface(StreamInterface):
|
||||
termios.tcsetattr(f, termios.TCSAFLUSH, attrs)
|
||||
f.close()
|
||||
time.sleep(0.1)
|
||||
else:
|
||||
self.stream.rts = 0
|
||||
self.stream.dtr = 0
|
||||
|
||||
# set proper port and open now that we've worked-around RTS/DTR issues
|
||||
self.stream.port = self.devPath
|
||||
self.stream.open()
|
||||
|
||||
self.stream = serial.Serial(
|
||||
self.devPath, 115200, exclusive=True, timeout=0.5, write_timeout=0
|
||||
)
|
||||
self.stream.flush() # type: ignore[attr-defined]
|
||||
time.sleep(0.1)
|
||||
|
||||
@@ -75,6 +66,17 @@ class SerialInterface(StreamInterface):
|
||||
self, debugOut=debugOut, noProto=noProto, connectNow=connectNow, noNodes=noNodes
|
||||
)
|
||||
|
||||
def __repr__(self):
|
||||
rep = f"SerialInterface(devPath={self.devPath!r}"
|
||||
if hasattr(self, 'debugOut') and self.debugOut is not None:
|
||||
rep += f", debugOut={self.debugOut!r}"
|
||||
if self.noProto:
|
||||
rep += ", noProto=True"
|
||||
if hasattr(self, 'noNodes') and self.noNodes:
|
||||
rep += ", noNodes=True"
|
||||
rep += ")"
|
||||
return rep
|
||||
|
||||
def close(self) -> None:
|
||||
"""Close a connection to the device"""
|
||||
if self.stream: # Stream can be null if we were already closed
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
"""TCPInterface class for interfacing with http endpoint
|
||||
"""
|
||||
# pylint: disable=R0917
|
||||
import contextlib
|
||||
import logging
|
||||
import socket
|
||||
from typing import Optional, cast
|
||||
import time
|
||||
from typing import Optional
|
||||
|
||||
from meshtastic.stream_interface import StreamInterface
|
||||
|
||||
@@ -35,52 +37,78 @@ class TCPInterface(StreamInterface):
|
||||
self.socket: Optional[socket.socket] = None
|
||||
|
||||
if connectNow:
|
||||
logging.debug(f"Connecting to {hostname}") # type: ignore[str-bytes-safe]
|
||||
server_address: tuple[str, int] = (hostname, portNumber)
|
||||
sock: Optional[socket.socket] = socket.create_connection(server_address)
|
||||
self.socket = sock
|
||||
self.myConnect()
|
||||
else:
|
||||
self.socket = None
|
||||
|
||||
StreamInterface.__init__(
|
||||
self, debugOut=debugOut, noProto=noProto, connectNow=connectNow, noNodes=noNodes
|
||||
)
|
||||
super().__init__(debugOut=debugOut, noProto=noProto, connectNow=connectNow, noNodes=noNodes)
|
||||
|
||||
def __repr__(self):
|
||||
rep = f"TCPInterface({self.hostname!r}"
|
||||
if self.debugOut is not None:
|
||||
rep += f", debugOut={self.debugOut!r}"
|
||||
if self.noProto:
|
||||
rep += ", noProto=True"
|
||||
if self.socket is None:
|
||||
rep += ", connectNow=False"
|
||||
if self.portNumber != DEFAULT_TCP_PORT:
|
||||
rep += f", portNumber={self.portNumber!r}"
|
||||
if self.noNodes:
|
||||
rep += ", noNodes=True"
|
||||
rep += ")"
|
||||
return rep
|
||||
|
||||
def _socket_shutdown(self) -> None:
|
||||
"""Shutdown the socket.
|
||||
Note: Broke out this line so the exception could be unit tested.
|
||||
"""
|
||||
if self.socket: #mian: please check that this should be "if self.socket:"
|
||||
cast(socket.socket, self.socket).shutdown(socket.SHUT_RDWR)
|
||||
if self.socket is not None:
|
||||
self.socket.shutdown(socket.SHUT_RDWR)
|
||||
|
||||
def myConnect(self) -> None:
|
||||
"""Connect to socket"""
|
||||
server_address: tuple[str, int] = (self.hostname, self.portNumber)
|
||||
sock: Optional[socket.socket] = socket.create_connection(server_address)
|
||||
self.socket = sock
|
||||
logging.debug(f"Connecting to {self.hostname}") # type: ignore[str-bytes-safe]
|
||||
server_address = (self.hostname, self.portNumber)
|
||||
self.socket = socket.create_connection(server_address)
|
||||
|
||||
def close(self) -> None:
|
||||
"""Close a connection to the device"""
|
||||
logging.debug("Closing TCP stream")
|
||||
StreamInterface.close(self)
|
||||
super().close()
|
||||
# Sometimes the socket read might be blocked in the reader thread.
|
||||
# Therefore we force the shutdown by closing the socket here
|
||||
self._wantExit: bool = True
|
||||
if not self.socket is None:
|
||||
try:
|
||||
self._wantExit = True
|
||||
if self.socket is not None:
|
||||
with contextlib.suppress(Exception): # Ignore errors in shutdown, because we might have a race with the server
|
||||
self._socket_shutdown()
|
||||
except:
|
||||
pass # Ignore errors in shutdown, because we might have a race with the server
|
||||
self.socket.close()
|
||||
|
||||
self.socket = None
|
||||
|
||||
def _writeBytes(self, b: bytes) -> None:
|
||||
"""Write an array of bytes to our stream and flush"""
|
||||
if self.socket:
|
||||
if self.socket is not None:
|
||||
self.socket.send(b)
|
||||
|
||||
def _readBytes(self, length) -> Optional[bytes]:
|
||||
"""Read an array of bytes from our stream"""
|
||||
if self.socket:
|
||||
return self.socket.recv(length)
|
||||
else:
|
||||
return None
|
||||
if self.socket is not None:
|
||||
data = self.socket.recv(length)
|
||||
# empty byte indicates a disconnected socket,
|
||||
# we need to handle it to avoid an infinite loop reading from null socket
|
||||
if data == b'':
|
||||
logging.debug("dead socket, re-connecting")
|
||||
# cleanup and reconnect socket without breaking reader thread
|
||||
with contextlib.suppress(Exception):
|
||||
self._socket_shutdown()
|
||||
self.socket.close()
|
||||
self.socket = None
|
||||
time.sleep(1)
|
||||
self.myConnect()
|
||||
self._startConfig()
|
||||
return None
|
||||
return data
|
||||
|
||||
# no socket, break reader thread
|
||||
self._wantExit = True
|
||||
return None
|
||||
|
||||
333
poetry.lock
generated
333
poetry.lock
generated
File diff suppressed because it is too large
Load Diff
Submodule protobufs updated: f00e96f12d...078ac8dfbe
@@ -1,6 +1,6 @@
|
||||
[tool.poetry]
|
||||
name = "meshtastic"
|
||||
version = "2.6.1"
|
||||
version = "2.6.3"
|
||||
description = "Python API & client shell for talking to Meshtastic devices"
|
||||
authors = ["Meshtastic Developers <contact@meshtastic.org>"]
|
||||
license = "GPL-3.0-only"
|
||||
|
||||
Reference in New Issue
Block a user