GithubHelp home page GithubHelp logo

libpebble2's Introduction

libpebble2

image

libpebble2 is a python library for interacting with Pebble devices. It:

  • Supports connections to Pebble QEMU instances and to watches via the Pebble mobile app or Bluetooth serial.
  • Supports connection to watches running both 2.x and 3.x firmware on aplite or basalt hardware
  • Provides automatic serialisation and deserialisation of pebble protocol messages
  • Asynchronous information is provided by a usable event system
  • Features a simple DSL for defining new message types
  • Provides ready-made implementations several Pebble Protocol services, including BlobDB and app installation
  • Works on Python 2.7 and 3.4

Installation

pip install libpebble2

Or, grab the source from https://github.com/pebble/libpebble2 and: :

python setup.py install

Documentation

Over here!

libpebble2's People

Contributors

bradtgmurray avatar cjwilliams avatar hexxeh avatar katharine avatar martijnthe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

libpebble2's Issues

"TypeError: Type str doesn't support the buffer API" when receiving CString appmessage from Pebble

After sending a CString using dict_write_cstring the following error occurs

Traceback (most recent call last):
  File "/usr/lib/python3.2/threading.py", line 740, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.2/threading.py", line 693, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.2/dist-packages/libpebble2/communication/__init__   .py", line 88, in run_sync
    self.pump_reader()
  File "/usr/local/lib/python3.2/dist-packages/libpebble2/communication/__init__   .py", line 75, in pump_reader
    self._handle_watch_message(message)
  File "/usr/local/lib/python3.2/dist-packages/libpebble2/communication/__init__   .py", line 139, in _handle_watch_message
    self.event_handler.broadcast_event((_EventType.Watch, type(packet)), packet)
  File "/usr/local/lib/python3.2/dist-packages/libpebble2/events/threaded.py", l   ine 44, in broadcast_event
    handler(*args)
  File "/usr/local/lib/python3.2/dist-packages/libpebble2/services/appmessage.py   ", line 58, in _handle_message
    result[t.key] = t.data.split('\x00')[0]
TypeError: Type str doesn't support the buffer API

changing

elif t.type == AppMessageTuple.Type.CString:
    result[t.key] = t.data.split('\x00')[0]

to

elif t.type == AppMessageTuple.Type.CString:
    result[t.key] = t.data.decode("utf-8")

seems to fix this issue

SerialTransport failing

I try to setup a serial communication between a Raspberry Pi and a Pebble-Watch. The Pi and the Pebble are connected, Serial port rfcomm0 is bound to the MAC-Adress of the Pebble but I get an Error when I try to connect them with LibPebble2:

pebble = PebbleConnection(SerialTransport("/dev/rfcomm0"))
Traceback (most recent call last):
File "<pyshell#34>", line 1, in
pebble = PebbleConnection(SerialTransport("/dev/rfcomm0"))
NameError: name 'SerialTransport' is not defined

Does anybody have an Idea what's wrong here (the code works with WebSocket and QEMU)?

Best regards

Oliver

Switching active watchface

Is there a way to switch the active watchface using this library?

When switching to a different watchface on my Pebble, the active watchface is not updated so every time I open a menu, the "wrong" watchface will show up.

Serial Transport on Ubuntu?

Can you please try pinging Pebble from Ubuntu directly via bluetooth serial connection? I'm having trouble with that. Much appreciated.

value_to_byte is given a float number

Hi pebblers !

While trying to send a notification (via WebSocketTransport), a problem occured.
When the notification is built, it creates some TimelineItem objects and one of them has a float value. So when it is serialised by PebblePacket.serialize(), Field.value_to_byte() is called and this line breaks :

return struct.pack(str(self.endianness or default_endianness) + self.struct_format, value)

In deed, since the endianness is a little indian < (for this case), it can convert only python int value.

Rigth now I just cast the value into an int and it works perfectly but I don't know if the fact that this float is given is actually a lib problem.

Thanks for your help !

PS : If it can help, here is my code

from libpebble2.communication import PebbleConnection
from libpebble2.communication.transports.websocket import WebsocketTransport
from libpebble2.services.notifications import Notifications

pebble = PebbleConnection(WebsocketTransport("ws://192.168.0.13:9000/"))
pebble.connect()
pebble.run_async()

print(pebble.watch_info.serial)

notif = Notifications(pebble)
notif.send_notification(u'Star Wars', u'Luke, I am your father', u'Dark vador')

libpebble2 doesn't install on python 3.5

Seems like enum34 is not compatible with 3.5.

% pip install libpebble2
Collecting libpebble2
Using cached libpebble2-0.0.8.tar.gz
Collecting enum34>=1.0.4 (from libpebble2)
Using cached enum34-1.0.4.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "/private/var/folders/q4/pr_xthvx0qj9b0995xb88xv00000gn/T/pip-build-c59u8yz2/enum34/enum/init.py", line 371, in getattr
return cls.member_map[name]
KeyError: '_convert'

Serial Connection with Windows Computer

I have tried to setup my Pebble Time smartwatch with my Windows 8 computer, everything seems to be OK.

I would like to connect directly to my smartwatch using a SerialTransport connection, but I'm not sure how to make it on windows.
I tried to use COM ports, but I'm not able to configure them.

Any suggestions?

'AppMessage' object has no attribute 'message'

I'm playing around with the Endomondo app, as it's a known entity and (probably) works fine.

After connecting to the watch, registering an "appmessage" handler, and manually opening the Endomondo app:

  • The event handler is called.
  • libpebble2 crashes when sending AppMessageACK

Am using version 0.0.2 from PyPI.

Here's the code:

import logging
import uuid

from libpebble2.communication import PebbleConnection
from libpebble2.communication.transports.websocket import WebsocketTransport
from libpebble2.protocol.base import types
from libpebble2.services.appmessage import AppMessageService

ENDOMONDO_UUID = uuid.UUID("7e4b6a11-d420-4601-a5d3-eb4409396a6f")

def did_receive_message(transaction_id, app_uuid, data):
    print "!! Called 'appmessage' event handler"

logging.basicConfig(level=logging.DEBUG)

transport = WebsocketTransport("ws://192.168.1.198:9000/")
pebble = PebbleConnection(transport, log_protocol_level=logging.DEBUG, log_packet_level=logging.DEBUG)
pebble.connect()
pebble.run_async()

app_message_service = AppMessageService(pebble)
app_message_service.register_handler("appmessage", did_receive_message)

And the output:

➤ python -i talktowatch.py
DEBUG:libpebble2.communication:-> WatchVersion(command=None, data=WatchVersionRequest())
DEBUG:libpebble2.communication:-> 0001001000
DEBUG:libpebble2.communication:<- 00960010015509b4fb76322e392e31000000000000000000000000000000000000000000000000000035343636346264000005015222545f76312e352e350000000000000000000000000000000000000000000000000000316331363237350001050152e2f832563352320000000000513135313235344530305832d102afe9170026658a035509b4fb656e5f55530000015858585858585800
DEBUG:libpebble2.communication:<- WatchVersion(command=1, data=WatchVersionResponse(running=WatchFirmwareVersion(timestamp=1426699515, version_tag=v2.9.1, git_hash=54664bd, is_recovery=False, hardware_platform=5, metadata_version=1), recovery=WatchFirmwareVersion(timestamp=1377981535, version_tag=v1.5.5, git_hash=1c16275, is_recovery=True, hardware_platform=5, metadata_version=1), bootloader_timestamp=1390606386, board=V3R2, serial=Q151254E00X2, bt_address=d102afe91700, resource_crc=644188675, resource_timestamp=1426699515, language=en_US, language_version=1, capabilities=24866934413088856, is_unfaithful=None))
>>> DEBUG:libpebble2.communication:<- 001e003001657e4b6a11d4204601a5d3eb4409396a6f0104000000010400312e3100
DEBUG:libpebble2.communication:<- AppMessage(command=1, transaction_id=101, data=AppMessagePush(uuid=7e4b6a11-d420-4601-a5d3-eb4409396a6f, count=1, dictionary=[AppMessageTuple(key=4, type=1, length=4, data=312e3100)]))
!! Called 'appmessage' event handler
Exception in thread PebbleConnection:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 763, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/home/nath/.ve/test/local/lib/python2.7/site-packages/libpebble2/communication/__init__.py", line 87, in run_sync
    self.pump_reader()
  File "/home/nath/.ve/test/local/lib/python2.7/site-packages/libpebble2/communication/__init__.py", line 74, in pump_reader
    self._handle_watch_message(message)
  File "/home/nath/.ve/test/local/lib/python2.7/site-packages/libpebble2/communication/__init__.py", line 119, in _handle_watch_message
    self.event_handler.broadcast_event((_EventType.Watch, type(packet)), packet)
  File "/home/nath/.ve/test/local/lib/python2.7/site-packages/libpebble2/events/threaded.py", line 44, in broadcast_event
    handler(*args)
  File "/home/nath/.ve/test/local/lib/python2.7/site-packages/libpebble2/services/appmessage.py", line 61, in _handle_message
    self._pebble.send_packet(AppMessage(transaction_id=packet.transaction_id, message=AppMessageACK()))
  File "/home/nath/.ve/test/local/lib/python2.7/site-packages/libpebble2/protocol/base/__init__.py", line 108, in __init__
    getattr(self, k)  # Throws an exception if the property doesn't exist.
AttributeError: 'AppMessage' object has no attribute 'message'

BLE

Would it be possible to open bluetooth low energy connections using this library?

Seria Transport freezes infinitly on windows 10

Hi pebblers,

I'm currently trying to get libpebble2 running on windows 10. I'm using the serial transport to communicate with my watch.
When I call pebble.run_async() the code doesn't do anything and never stop, without displaying anything.

I first thought that the problem was coming from python 3.5 but I tried it too on python 2.7 and it didn't work.

I am on windows 10 and here is my code :

import logging
import serial

from libpebble2.communication import PebbleConnection
from libpebble2.communication.transports.serial import SerialTransport

from libpebble2.protocol import *
from libpebble2.services.notifications import Notifications
from libpebble2.services.screenshot import Screenshot

logging.basicConfig(level=logging.DEBUG)

pebble = PebbleConnection(
    SerialTransport('COM3'),
    log_protocol_level=logging.DEBUG,
    log_packet_level=logging.DEBUG
    )

pebble.connect()
pebble.run_async()

Thank you for your help !

I got an error message "decoding.."

libpebble2.protocol:Exception decoding AppLogMessage.message
Exception in thread PebbleConnection:
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 810, in *bootstrap_inner
self.run()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 763, in run
self.__target(_self.__args, _self.__kwargs)
File "/usr/local/Cellar/pebble-sdk/4.3/libexec/vendor/lib/python2.7/site-packages/libpebble2/communication/__init
.py", line 88, in run_sync
self.pump_reader()
File "/usr/local/Cellar/pebble-sdk/4.3/libexec/vendor/lib/python2.7/site-packages/libpebble2/communication/init.py", line 75, in pump_reader
self._handle_watch_message(message)
File "/usr/local/Cellar/pebble-sdk/4.3/libexec/vendor/lib/python2.7/site-packages/libpebble2/communication/init.py", line 118, in _handle_watch_message
packet, length = PebblePacket.parse_message(message)
File "/usr/local/Cellar/pebble-sdk/4.3/libexec/vendor/lib/python2.7/site-packages/libpebble2/protocol/base/init.py", line 174, in parse_message
return _PacketRegistry[command].parse(message[4:length])[0], length
File "/usr/local/Cellar/pebble-sdk/4.3/libexec/vendor/lib/python2.7/site-packages/libpebble2/protocol/base/init.py", line 199, in parse
value, length = v.buffer_to_value(obj, message, offset, default_endianness=default_endianness)
File "/usr/local/Cellar/pebble-sdk/4.3/libexec/vendor/lib/python2.7/site-packages/libpebble2/protocol/base/types.py", line 404, in buffer_to_value
return struct.unpack_from('%ds' % length, buffer, offset)[0].split(b'\x00')[0].decode('utf-8'), length
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/encodings/utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode bytes in position 29-30: unexpected end of data

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.