GithubHelp home page GithubHelp logo

pebble-setup's Introduction

Pebble Development Setup

After the shutdown of CloudPebble, developing apps for Pebble has been much harder, especially on Windows machines. However, using Windows Subsystem for Linux, this is entirely possible. Additionally, due to some broken links on the developer.rebble.io page, the general instructions for installation are hard to find and sometimes outdated, so this guide will also serve as a host for the instructions for Mac and Linux as well.

Linux/Windows

The Windows installation is almost entirely the same as the Linux installation, but the Windows Subsystem for Linux (WSL) needs to be set up. Go to the Windows Store and download your preferred distro of Linux. This guide uses Ubuntu but any distro should work. Launch it and run the installation.

Install Dependencies

On Ubuntu 20.04 (and some other distros) certain older packages aren't available through the default apt package manager. Run these commands based on your distro.

On ≤ Ubuntu 18.04 (and other older distros)

# Python 2.7 + pip + virtualenv
sudo apt install -y python2.7 python2.7-dev
curl https://bootstrap.pypa.io/get-pip.py --output get-pip.py
sudo python2 get-pip.py
sudo -H python2.7 -m pip install -U pip setuptools wheel virtualenv

# Node.js + npm (will take a few minutes if npm isn't already installed)
sudo apt install -y libssl1.0-dev nodejs-dev npm

# Emulator dependencies
sudo apt install -y libsdl1.2debian libfdt1 libpixman-1-0

On ≥ Ubuntu 20.04 (and other newer distros)

# Python 2.7 + pip + virtualenv
sudo apt update
sudo apt install python2
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1 
curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py
sudo python2 get-pip.py
sudo -H python2.7 -m pip install -U pip setuptools wheel virtualenv
sudo apt install python2-dev

# Node.js + npm (will take a few minutes if npm isn't already installed)
sudo apt install libnode-dev npm 

# Emulator dependencies
sudo apt install -y libsdl1.2debian libfdt1 libpixman-1-0

Install Pebble SDK

Create a folder called pebble-dev/ in the location you want to store the SDK (using mkdir pebble-dev). This guide uses ~/pebble-dev/ (the home directory) but you can swap in any path for ~ (marked in green).

Run the following commands to extract the SDK:

cd ~/pebble-dev/
[ -e pebble-sdk-4.5-linux64.tar.bz2 ] || wget https://developer.rebble.io/s3.amazonaws.com/assets.getpebble.com/pebble-tool/pebble-sdk-4.5-linux64.tar.bz2
[ -e pebble-sdk-4.5-linux64 ] || tar -xf pebble-sdk-4.5-linux64.tar.bz2
cd pebble-sdk-4.5-linux64

You should now be in the directory ~/pebble-dev/pebble-sdk-4.5-linux64 with the SDK files and directories inside it.

Now add the pebble command to your path by running:

echo 'export PATH=~/pebble-dev/pebble-sdk-4.5-linux64/bin:$PATH' >> ~/.bashrc &&. ~/.bashrc

Update outdated dependencies:

# Fix pypkjs in requirements.txt
if [ "$(grep 'pebble-sdk-homebrew' requirements.txt)" ]; then cp requirements.txt requirements.txt.OLD; grep -v pypkjs requirements.txt.OLD > requirements.txt; echo 'git+https://github.com/pebble/pypkjs.git' >> requirements.txt; fi

# Replace pebble-tool
if [ "$(grep 'sdk.getpebble.com' pebble-tool/pebble_tool/sdk/manager.py)" ]; then sudo mv pebble-tool pebble-tool.OLD; sudo git clone https://github.com/pebble-dev/pebble-tool.git; fi

Install the Python library dependencies locally:

# Install requirements
[ -e .env ] || virtualenv --python=python2.7 .env
. .env/bin/activate
pip install -r requirements.txt
pip install -r pebble-tool/requirements.txt
deactivate

Finally, install the latest SDK

pebble sdk install latest

IMPORTANT: On Windows, it's advisable to keep your project files (not any of the SDK files you've just installed) in the regular Windows path, since regular Windows files are accessible from WSL, but not vice versa. You can access them at /mnt/<drive letter>/<windows>/<path>/ .

Mac

The Mac installation uses the Nix package manager. If you don't want to install it, (possibly outdated) alternatives are in the old Reddit post.

Install Dependencies

# Install Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

# Install freetype
brew install freetype

Install Nix

You can install Nix from the internet with one command, but it depends on your macOS version (due to a filesystem change on macOS 10.15 Catalina)

# if on macOS <= 10.14 (Mojave)
sh <(curl -L https://nixos.org/nix/install) --daemon

# if on macOS >= 10.15 (Catalina)
sh <(curl -L https://nixos.org/nix/install) --darwin-use-unencrypted-nix-store-volume

Reload your terminal by closing and reopening it, and verify your installation by running nix-env --version

Install Cachix

Cachix is a Nix extension that speeds up building. Install Cachix and point it to the Pebble cache.

nix-env -i cachix
cachix use pebble

Reboot your system for the cache to take hold.

Setup Nix Shell

If you haven't already, create a folder to hold your Pebble projects (this guide will use pebble-dev but you can call it whatever your want) with mkdir pebble-dev. Enter that directory using cd pebble-dev.

Create a file called shell.nix in TextEdit (or another text editor)

(import
  (builtins.fetchTarball https://github.com/Sorixelle/pebble.nix/archive/master.tar.gz)
).pebbleEnv { }

Run nix-shellto enter the Nix shell, where you're able to run the pebble command. The first time you run it, it might take a few seconds to download dependencies.

Once you're in the shell, install the Pebble SDK.

pebble sdk install latest

IMPORTANT: In each project directory that you create, you need to copy the shell.nix file into it, and activate the Nix shell with nix-shell before running pebble commands.

Create and Run Demo App

Your Pebble development environment should now be set up! Go to the directory you want your projects to be stored in, and clone a project from github or create a new one using pebble new-project Test that the SDK works correctly by building the app using pebble build.

You can install the built app either on an emulator or on your phone.

  • Emulator Note: On Windows, to run an emulator, it needs a display server, as WSL cannot natively display graphical windows. For this I'm using Xming, but you can use any server you want. Download and install it, then run it. (It won't do anything except show an icon in the system tray-- that's what we want.) Run echo 'export DISPLAY=:0' >> ~/.bash_profile && . ~/.bash_profile to link WSL to Xming. You might want to set Xming to launch at startup so you won't need to run it each time you boot your computer

    Run pebble install --emulator [aplite, basalt, chalk], and a window with the emulator in it running the app should appear.

  • Phone Turn on the Developer Connection in the Pebble app on your phone (in the Settings menu). Run pebble install --phone <IP address in developer settings> in the command line, and the app should appear on your Pebble.

Writing Apps

Once all of this is set up, having a code editor makes working with these projects much easier, and is another missing feature from CloudPebble. VSCode is a popular editor, but any code editor works. Also, be sure to check the #app-dev channel on the Rebble discord if you have any issues or questions during development.

Development Options

There are 3 main options for developing Pebble apps and watchfaces, each catering to a different use case.

Pebble C

Write watch apps or watchfaces in C, with a phone side server. The phone-side server is usually PebbleKit JS, where you write the server in Javascript and it runs on both iOS and Android (recommended), or if you need platform-specific features, you can use PebbleKit Android and PebbleKit iOS to interface with companion Android and iOS apps respectively.

If you want to make a watch app, this is the most flexible option, though C is a harder language to learn than the other Javascript-only options.

Pebble.js

Framework that runs inside of PebbleKit JS that automatically creates the C watch app based on your JavaScript code. Much easier to learn than C-based watch apps, but the UIs it can create are significantly less flexible, and it requires a connection to the phone at all times (whereas C-based apps can work even with Bluetooth disconnected).

Rocky.js

Framework to write watchfaces (no watch apps) in Javascript that run natively on the watch. Unlike Pebble.js, these work without a connection to the phone, but the framework itself was never fully completed, so some things might not work.

References

Pebble Developer Guides https://developer.rebble.io/developer.pebble.com/guides/index.html

Pebble API Reference https://developer.rebble.io/developer.pebble.com/docs/index.html

Learning C with Pebble https://pebble.gitbooks.io/learning-c-with-pebble

Pebble C App Examples https://github.com/pebble-examples, https://github.com/pebble/pebble-sdk-examples


Other Options

If you don't want to set it up on your local system, or if something from this guide isn't working, you can use these options to get a prebuilt development environment.

Ubuntu Virtual Machine Image https://rebble.io/hackathon-001/vm/

Docker Image https://hub.docker.com/r/rebble/pebble-sdk


Anyways, I hoped this helped some people get set up with developing for Pebble. If you have any questions or if I missed anything, let me know by filing an issue or on the Rebble discord.

This guide is mostly based off of these links:

https://developer.rebble.io/developer.pebble.com/sdk/download/index.html

https://gist.github.com/zeevro/ce20d0d74a869d73119e9d1522b7caa7

https://gist.github.com/pauleeeeee/37942295077da184000f8ac9ab1aad40

https://github.com/Sorixelle/pebble.nix

pebble-setup's People

Contributors

andyburris avatar nugenjs avatar protowalker 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

Watchers

 avatar  avatar  avatar

pebble-setup's Issues

Problem compiling because of Jinja2 package

I was trying to set up the environment and compile my old project and encountered the following problem. The setup went fine and I issue the "pebble build" command. It throws the following error:

Jinja2 module is missing, you probably forgot to patch your current sdk
Fix the problem by executing the following command and relaunch your build:

"/home/vasil/.pebble-sdk/SDKs/current/sdk-core/../.env/bin/python" -m pip install -r "/mnt/c/Users/vasil/MyDocuments/My/Pebble/workaday/node_modules/enamel/requirements.txt"

But when I try to run the command proposed, I got another error:

Collecting Jinja2==2.7.2 (from -r /mnt/c/Users/vasil/MyDocuments/My/Pebble/workaday/node_modules/enamel/requirements.txt (line 1))
  Using cached https://files.pythonhosted.org/packages/23/94/ca42176bf7a252ce1f5d165953013573dffdbe4b5dac07f57146146ea432/Jinja2-2.7.2.tar.gz
Collecting markupsafe (from Jinja2==2.7.2->-r /mnt/c/Users/vasil/MyDocuments/My/Pebble/workaday/node_modules/enamel/requirements.txt (line 1))
  Using cached https://files.pythonhosted.org/packages/6d/7c/59a3248f411813f8ccba92a55feaac4bf360d29e2ff05ee7d8e1ef2d7dbf/MarkupSafe-2.1.3.tar.gz
   Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 20, in <module>
      File "/tmp/pip-build-2ZPuXa/markupsafe/setup.py", line 26
        raise BuildFailed() from e
                               ^
    SyntaxError: invalid syntax

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-2ZPuXa/markupsafe

and the build won't run either.

I'm not familiar with Python but as far as I got the probem is as following. Jinja2 version 2.7.2 (as required for enamel package) uses another package called markupsafe, and the reference to markupsafe is specified without version constraint. So package manager tries to download the latest markupsafe version, and it isn't compatible with obsolete Python 2.7 used for building.
I've resolved the problem in a following way. I've manually installed the old markupsafe package with the following command:
"/home/vasil/.pebble-sdk/SDKs/current/sdk-core/../.env/bin/python" -m pip install "markupsafe==0.23"
Then the command proposed for fixing Jinja2 error ran fine and I was able to build my project.
Hope this would help someone.
Please note paths in commands above - they are specific to my environment. As far as I understand, the only thing that changes is username (e.g. instead of /home/vasil/... you use /home/<your_username>/...)

Update link to new vm

Hey!

Thanks so much for writing this guide. I'll be sure to point people to it (and might even pull it in to help.rebble.io if you're okay with that?)

There's a newer VM based on Ubuntu 22.04 that was built for the hackathon. Could you please point people to that instead? It's available at https://rebble.io/hackathon-001/vm/

Thanks!

python: command not found; dirname: missing operand

After attempting to run "pebble sdk install latest", I get the following message:

/home/karoly/pebble-dev/pebble-sdk-4.5-linux64/bin/pebble: line 4: python: command not found
dirname: missing operand
Try 'dirname --help' for more information.
/home/karoly/pebble-dev/pebble-sdk-4.5-linux64/bin/pebble: line 4: python: command not found
You must set up a virtualenv before you can use the pebble tool.
Try these commands from :

virtualenv --no-site-packages .env
source .env/bin/activate
pip install -r requirements.txt
deactivate

If you don't have 'virtualenv', try `sudo pip install virtualenv`.'
If you don't have 'pip', try `sudo easy_install pip`.
If you still need help, contact [email protected].

I tried running the suggestion given in the terminal, but to no avail. It seems to run fine, but then trying to run "pebble sdk install latest" gives the same error.

I am running the WSL on Windows 11. Any help would be appreciated, and thanks for the awesome tutorial!

Package urllib missing

Trying to install the latest SDK results in the following Error

pebble sdk install latest                                                                  
Traceback (most recent call last):
  File "/home/tl044cn/programs/pebble-sdk-4.5-linux64/pebble-tool/pebble.py", line 4, in <module>
    import pebble_tool
  File "/home/tl044cn/programs/pebble-sdk-4.5-linux64/pebble-tool/pebble_tool/__init__.py", line 8, in <module>
    import requests.packages.urllib3 as urllib3
ImportError: No module named requests.packages.urllib3

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.