Skip to content

Instantly share code, notes, and snippets.

@mddub
Created August 16, 2016 03:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mddub/a172e11920e2e06eb5a1ef56d7bb905e to your computer and use it in GitHub Desktop.
Save mddub/a172e11920e2e06eb5a1ef56d7bb905e to your computer and use it in GitHub Desktop.
no-appmessage-timeout: libpebble2 code
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