Created
August 16, 2016 03:34
-
-
Save mddub/a172e11920e2e06eb5a1ef56d7bb905e to your computer and use it in GitHub Desktop.
no-appmessage-timeout: libpebble2 code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from threading import Event | |
from libpebble2.communication import PebbleConnection | |
from libpebble2.communication.transports.serial import SerialTransport | |
from libpebble2.protocol.appmessage import AppMessage | |
from libpebble2.protocol.appmessage import AppMessageACK | |
from libpebble2.protocol.appmessage import AppMessagePush | |
pebble = PebbleConnection(SerialTransport("/dev/rfcomm0")) | |
pebble.connect() | |
pebble.run_async() | |
print "connected" | |
sent_ack_once = False | |
e = Event() | |
def handle_message(packet): | |
global e, sent_ack_once | |
print "message received: {}".format(packet) | |
if isinstance(packet.data, AppMessagePush): | |
if sent_ack_once: | |
print "doing nothing" | |
else: | |
print "ACKing" | |
pebble.send_packet(AppMessage(transaction_id=packet.transaction_id, data=AppMessageACK())) | |
sent_ack_once = True | |
e.set() | |
pebble.register_endpoint(AppMessage, handle_message) | |
print "waiting..." | |
e.wait() | |
e = Event() | |
print "waiting again..." | |
e.wait() | |
e = Event() | |
print "waiting a third time..." | |
e.wait() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment