More Power, More Angular, More ng-beacon!
Here’s a rundown of the new updates:
I’ve upgraded from using the nRF51822 module to the nRF52832 module for ng-beacon! What does this mean, you ask?
Essentially, with the new chip we get double program memory (512kb instead of 256kb), four times the ram (64kb instead of 16kb), and many more hardware features, such as BLE 5-readiness. And yes, it’s still super fun to put together:
The expanded program memory and extra RAM gives us a lot more space to play, which leads to the next major improvement…
ng-beacon and JS: a Match Made in Heaven
(p.s. —I’ve included source code for this below ;-)
New Management App, Written With Angular + Web Bluetooth
I’ve also created a new ng-beacon management app using the latest from Angular 4, angular-material, and angular-web-bluetooth:
The app allows you to see the battery status, software version and uptime of the beacon, rename the beacon, and configure it either as a Physical Web beacon, iBeacon, or a standard Bluetooth temperature sensor. It is a simple way to get started, but you can always write your own code, of course!
A Better Bootloader
As mentioned in the initial post, if you wanted to update the firmware of the ng-beacon, you needed an extra piece of hardware, called J-Link programmer, or a Raspberry Pi:
Not anymore! We now have a BLE Bootloader, so that you will be able to do DFU (Device Firmware Update) over the air.
The hardware part is implemented by Espruino, based on Nordic’s own bootloader (Nordic being the company which manufacturers the nRF52832 chip that we used). Their bootloader is optional and had not been enabled in previous versions of the firmware.
Nordic provides an app, called nRF Toolbox, that can do DFU with their bootloader. Unfortunately, the only way you could actually do the DFU was to get the Zip file with the new firmware to your Android device (I used Google Drive) and then use their app to send the update.
Of course, I didn’t find this a very convenient way to update the firmware, and I was a little frustrated with the fact that you couldn’t do the DFU with Web Bluetooth, rather than with just their specific Android app. So I sat down for a couple of hours and hacked a PoC for a Web Bluetooth based DFU updater.
The Web Bluetooth DFU means you can also do the updates from the convenience of the Desktop or from Android without having to install an app first. The most amazing part is that it actually works — I’ve used it several times already!
The original prototype could live on a CR2032 battery for about 5 hours. Cool for a demo, but not very useful for a beacon that you may want to set and forget. Following a few improvement to the software, we can now achieve several months of operation without changing the battery — depending on the actual usage pattern. For now, we have a beacon running for 25 days already, and the battery is still about 2.8 volts strong.
Some Example Use Cases
As mentioned above, one thing you can now do with ng-beacon is connect to Magic Blue smart bulb and change its color according to the reading from the on-board temperature sensor:
The code above will set the bulb color to blue below 22℃, and red above that. The beacon will automatically connect to the bulb and control it — no need for any computer or smartphone. Just two IoT devices directly speak to each other.
You may noticed that the code above looks very much like the Web Bluetooth API. This is not a coincidence — the Bluetooth API of Espruino was designed to closely mirror Web Bluetooth. It’s also very similar to the code used my Progressive Web App post.
Another (perhaps obvious) use case I thought up for ng-beacon was to set it up as standard BLE environment sensor (temperature + humidity) — you can check out my ngVikings post to see how we can build a game around this concept. This is all the code you need:
0x181A is the standard Bluetooth service code for the standard Bluetooth Environmental Sensing service, while
0x2A6F are the numbers for the standard Temperature and Humidity characteristics. The values for these characteristic is expected to be a short integer.
You can learn more about the BLE functions of ng-beacon in the Espruino API Reference page.
Some (More) Example Use Cases from the Community
In my initial post, I included a link to a survey for the community to provide input into the project. In addition to everyone confirming they’d like to be able to program the beacons, they came up with some creative use cases, too:
- “Check if my dog is peeing in wrong places.” (my personal favorite)
- “Living room or basement temperature and humidity sensor”
- “Proximity beacon finder from a drone”
- “BLE packet exchanges with IoT devices using web bluetooth for security” (I am not sure what this even means…)
- “Probably a simple “Who’s near me” app. People could program a special message to have the beacon broadcast, along with (optionally) their name.”
But of course, that wasn’t all the feedback we got…
ng-beacon Prototyping Area
Yes, ng-beacon now has a prototyping area! As with, well, some things, it all started with a tweet…
…and then eventually, a pull request that landed:
Add a prototype area with PO.26, 27, SDA, and SCL. by mgiambalvo · Pull Request #1 · urish/ng…
Fair warning, I haven't used Eagle in forever, so this probably needs some cleanup. Here's what I did: Moved the…
On top of that, I also added a small LED and a miniature button, which lets you easily switch to DFU mode (just keep it pressed while switching the beacon on), for the over-the-air firmware update I mentioned earlier.
Here is what it looks like all put together:
I love the idea that such contributors come from the community. Remember, community was the reason I created ng-beacons in the first place, and I love seeing the boomerang effect — how the community gives back. And, as one good turn deserves another, there’s going to be an proto-area equipped ng-beacon with Mike’s name on it next week at ng-conf :-)
With the prototype area, you can easily connect third party sensors such as accelerometers, light sensors, etc. It is also pin-compatible with the Grove System, which means you can connect many existing sensor daughter boards using a standard Grove connector. That said, you can also use the small prototype area above the board to make it compatible with boards which have different pinout, such as this accelerometer module I connected:
Disclaimer: When connecting third-party modules, please make sure they can operate on 3V (some modules require 3.6V or even 5V to operate), and that they do not consume more current than the battery is able to supply (anything which consumes more than 10mA is probably too much).
PSA: ng-beacon Will Be Coming to ng-conf!
As you may know, ng-conf, the official Angular conference, is going on in Salt Lake City this week.
I will be bringing some ng-beacons to ng-conf, and we’ll have a fun beacon-based scavenger hunt game for those attending the conference. The idea is to give the community members an opportunity to experiment hands-on with the Physical Web and Bluetooth Low Energy and ng-beacons.
There will be a series of challenges, which will involve attendee interacting with the beacons, and there will also be some fabulous prizes, including an ng-cruise ticket, an ng-beacon and a MiP robot!
Also, you’re more than welcome to come find me during ng-conf and take a look at/play with the beacons :)
Supporting Espruino & Chance to win an ng-beacon
Finally, a word of thanks, and a request for support.
Gordon is currently accepting donations, which helps to support the project. Since we’ve benefited so much from his hard work, I’d like to put on a little competition so as to help the project move forward:
If you donate to Espruino during the month of April, you’ll have a chance to win your very own ng-beacon, shipped right to your door!
To participate, all you need to do after you donate is forward your receipt to firstname.lastname@example.org. You can donate to Gordon’s project below: