diff --git a/meshtastic/remote_hardware.py b/meshtastic/remote_hardware.py index dca05af..1f28937 100644 --- a/meshtastic/remote_hardware.py +++ b/meshtastic/remote_hardware.py @@ -1,12 +1,21 @@ from . import portnums_pb2, remote_hardware_pb2 +from pubsub import pub + +def onGPIOreceive(packet, interface): + """Callback for received GPIO responses + + FIXME figure out how to do closures with methods in python""" + pb = remote_hardware_pb2.HardwareMessage() + pb.ParseFromString(packet["decoded"]["data"]["payload"]) + print(f"Received RemoteHardware typ={pb.typ}, gpio_value={pb.gpio_value}") -""" -This is the client code to control/monitor simple hardware built into the -meshtastic devices. It is intended to be both a useful API/service and example -code for how you can connect to your own custom meshtastic services -""" class RemoteHardwareClient: + """ + This is the client code to control/monitor simple hardware built into the + meshtastic devices. It is intended to be both a useful API/service and example + code for how you can connect to your own custom meshtastic services + """ def __init__(self, iface): """ @@ -16,6 +25,7 @@ class RemoteHardwareClient: """ self.iface = iface + pub.subscribe(onGPIOreceive, "meshtastic.receive.data.REMOTE_HARDWARE_APP") def writeGPIOs(self, nodeid, mask, vals): """ @@ -30,4 +40,7 @@ class RemoteHardwareClient: def readGPIOs(self, nodeid, mask): """Read the specified bits from GPIO inputs on the device""" - pass \ No newline at end of file + r = remote_hardware_pb2.HardwareMessage() + r.typ = remote_hardware_pb2.HardwareMessage.Type.READ_GPIOS + r.gpio_mask = mask + return self.iface.sendData(r, nodeid, portnums_pb2.REMOTE_HARDWARE_APP, wantAck = True)