Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions src/meshcore/commands/messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,21 +307,28 @@ async def send_trace(

return await self.send(cmd_data, [EventType.MSG_SENT, EventType.ERROR])

async def send_raw_data(self, payload: bytes) -> Event:
async def send_raw_data(self, payload: bytes, path: bytes = b"") -> Event:
"""N09: Send raw data via CMD_SEND_RAW_DATA (25).

Sends an arbitrary payload through the mesh network.
Sends an arbitrary raw-data payload directly (no flood support yet).

Command format:
0x19 | path_len(1) | path(path_len bytes) | payload(>=4 bytes)

Args:
payload: Raw bytes to send.
payload: Raw bytes to send (minimum 4 bytes).
path: Optional path bytes for intermediate hops (default: empty = zero-hop direct).

Returns:
Event with MSG_SENT or ERROR.
Event with OK or ERROR.
"""
if not isinstance(payload, (bytes, bytearray)):
raise TypeError("payload must be bytes-like")
data = b"\x19" + bytes(payload)
return await self.send(data, [EventType.MSG_SENT, EventType.ERROR])
if len(payload) < 4:
raise ValueError("payload must be at least 4 bytes")
path = bytes(path)
data = bytes([0x19, len(path)]) + path + bytes(payload)
return await self.send(data, [EventType.OK, EventType.ERROR])

async def set_flood_scope(self, scope):
if scope is None:
Expand Down
3 changes: 2 additions & 1 deletion src/meshcore/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,8 @@ async def handle_rx(self, data: bytearray):
res = {}
res["SNR"] = int.from_bytes(dbuf.read(1), byteorder="little", signed=True) / 4
res["RSSI"] = int.from_bytes(dbuf.read(1), byteorder="little", signed=True)
res["payload"] = dbuf.read(4).hex()
dbuf.read(1) # skip reserved byte (0xFF, possibly path_len in future)
res["payload"] = dbuf.read().hex() # read all remaining payload bytes
logger.debug("Received raw data")
logger.debug(res)
await self.dispatcher.dispatch(Event(EventType.RAW_DATA, res))
Expand Down