I’ve had a sorta kinda Pebble alternative on my arm for some months now and thoroughly enjoy the refound love for developing on a wrist watch that doesn’t need to recharge three times a day.
It’s been a bit of a roller coaster to get started developing for it (wth is “Web Bluetooth?… oooooh, interesting. But wow, is this _quirky_…”) but having had some hands on experience with this it’s starting to become second nature.
What are we doing?
We’re proposing a way to use Docker to compartmentalize the toolset needed when developing for the Bangle.js 2.
What’s needed for this?
- A Bangle.js 2 wrist watch
- Docker (tested on windows inside WSL 2 and Ubuntu 20.04)
- A git clone of the BangleApps repo (don’t forget to sync the submodules)
- Bluetooth 4.0 compatible device (built in or not, I’m using an ASUS BT400 with good results. Test connectivity at the Bangle.js App Loader)
- Self signed SSL certificate
How do we do this?
Starting out with the Docker parts, I’m using compose files for my setup. You can choose to accomplish this without compose, but this only covers a compose setup. Here’s the file contents:
services: node: image: "node:16" working_dir: "/home/node/app" user: node volumes: - ./:/home/node/app environment: - NODE_ENV=production ports: - "8080:8080" command: "npm run locals"
In order for this to work, we need to do two additional things
- Create the SSL certificate
- Add the “locals” command to ‘package.json’
Creating the SSL certificate
Creating an SSL certificate is a fairly straightforward one liner (as long as all packages are installed and you’re using some kind of *nix environment (i _did_ mention using WSL 2 and Ubuntu 20.04)) taken from Stackoverflow (note the instructions point out entering “127.0.0.1” as the Common Name)
openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -keyout key.pem -out cert.pem
With that generated, let’s fix the last step;
Add the “locals” command
You don’t _have_ to do this, but there’s already a “local” command and I find it to be in the spirit of things to extend on that. Edit the ‘package.json’ file and add (I chose to duplicate the “local” command) the following in the “scripts” section
"locals": "npm-watch & npx http-server -a 0.0.0.0 -S -C cert.pem -o",
And…. that’s it! When you start the container, e.g. through
docker compose up, it should ideally start the node scripts needed for you to open up Chrome (or another supported browser) and browse to https://127.0.0.1:8080, try to connect your watch, and if that works, you’ll be able to develop and push code locally.