Puck.js + Television… What could go wrong?

by | Apr 28, 2017 | Uncategorized | 0 comments

It was a few weeks ago when I first discovered and visited DoES, and I quickly realised that I’ve got to learn a whole lot more about telemetry for the IoT project I’m working on. I’ve been dabbling with LoRaWAN, WiFi and, most recently, BLE (Bluetooth Low Energy).

In particular, I’m really interested in Beacons – what many refer to as “The Physical Web“. Beacons advertise small packets of information to their local vicinity, and anyone with a mobile (or other suitable device) wandering by will get a notification so they can interact with the beacon in some way…

There’s two de facto beacon standards: Apple iBeacon and Google Eddystone. I went hunting for a beacon that could do both and found two – Puck.js and RuuviTag, both of which are open source.  The Ruuvi isn’t widely available yet, so I’m starting with the Puck. It’s a tiny beacon complete with sensors, and it’s programmed via the web browser using simple JavaScript (primarily ES5). It arrived today; I immediately set about the IoT-equivalent of “Hello World” – in other words flashing a LED!

A puck.js beacon with some Javascript code to flash one of the on-board LEDs.

It was really easy – just launch the IDE in a “Web Bluetooth API”-compatible browser, click the connect button and choose which beacon to update. It’s the same workflow as the Arduino IDE, but without the wires – it’s all done over Bluetooth. In less than 30 seconds, I’d created yet another IoT blinkenlight.

So, what can the Puck do? It’s got a bunch of onboard sensors and LEDs, all of which come with associated Javascript APIs that make interacting with them trivial. And, obviously, it can do the beacon stuff too. So, naturally, I set about a small project with the IR (Infrared) transmitter.

I don’t quite remember how or why I ended up messing with the IR stuff, it just sort of happened. I’ll get to the beacon stuff in a future experiment.

So, IR transmitter… what do I have in the house that responds to IR? A television!

Sending an IR sequence on the Puck is trivial:

Puck.IR(command);

To get the command, you can either attach an IR receiver to your Puck and record direct from your remote control, or head over to IRDB (InfraRed DataBase) and see if your target device is listed there. Luckily for me, my TV – a Samsung – was on the IRDB list. Here’s the hexadecimal sequence for power on/off:

0000 006C 0000 0022 00AD 00AD 0016 0041 0016 0041 0016 0041 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0041 0016 0041 0016 0041 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0041 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0041 0016 0016 0016 0041 0016 0041 0016 0041 0016 0041 0016 0041 0016 0041 0016 06FB

The website displays it as a string, so you’ll need to convert it to an array of numbers – luckily, the Puck has a ready made API for that too:

var pronto  = require("pronto");
var command = pronto.decode( long_hex_string_goes_here );

So, now I’ve got the command, I’ve converted it to the correct format, and I can immediately send it to the IR transmitter – but I want an easy way to choose when to send it. The Puck has that covered too – there’s a button on the underside of the PCB which turns the whole device in to a push-button. And there’s an easy way to trigger some code when the button is pushed too:

setWatch(
  function() {
    // your code here
  },
  BTN, // pin to watch
  {edge:"rising", debounce:25, repeat:true} // settings
);

It watches the specified pin (in this case “BTN”) for a rising edge, and when found it runs your code.

Here’s the final script:

var Green   = LED2; // more semantic name for the LED
var pronto  = require("pronto");
var command = pronto.decode( "0000 006C 0000 0022 00AD 00AD 0016 0041 0016 0041 0016 0041 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0041 0016 0041 0016 0041 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0041 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0041 0016 0016 0016 0041 0016 0041 0016 0041 0016 0041 0016 0041 0016 0041 0016 06FB" );

setWatch(
  function() {
    Green.set(); // turn on green LED
    console.log("Power toggle"); // debug message to REPL
    Puck.IR(command); // send the IR command
    Green.reset(); // turn off green LED
  },
  BTN,
  {edge:"rising", debounce:25, repeat:true}
);

All that remains now is to test it on my TV! The IR transmitter on the Puck is really small, so I had to hold the Puck close to the IR receiver on the TV. Anyway, here’s the results…

So, it mostly worked then 🙂

Community Maker Events

Maker Events are regular meetings organised by DoES Liverpool to provide a space for people to learn, experiment and work on projects related to Physical computing, Laser cutting, Arduino, Electronics, 3D printing…

Need a Desk or Workshop space?

Choose the perfect plan for you.

Hotdesking

£7.50/half day
£15/day

Take a desk for a day or 6 months, the choice is yours.

 

N

Choose any available desk

N

Office Hours

Flexidesk

£96/month

Flexible drop-in access to office space

N

Intended for regular short periods of hot desk use

Permanent Desk

£210/month

Out of hours access  (with £150 deposit)

 

N

Unlimited access

N

Access to all rooms

N

Your own dedicated space with storage

Off-Peak Workshop

£42/month

Workshop access evenings and weekends

Out of hours access  (with £50 deposit)

N

Workshop use only

Workshop

£72/month

Unlimited workshop

Out of hours access (with £50 deposit)

 

N

Workshop use only

EXCELLENT
Google star 1Google star 2Google star 3Google star 4Google star 5
Based on 20 reviews
Posted on Google Google
Ali Poostchi profile picture
Ali Poostchi
Google star 1Google star 2Google star 3Google star 4Google star 5Trustindex verifies that the original source of the review is Google.
This place is basically my DIY dream come true! 🛠️ The team here is INCREDIBLE - super helpful and always ready to jump in with advice or lend a hand when you're stuck on a project. These folks have machines and tools for almost everything, from CNC machine to soldering iron, and you can literally bring any crazy idea to life. Want to prototype a wild invention? Craft something totally unique? Just experiment and see what happens? They've got all the gear you could possibly need. The best part? The combination of amazing equipment and even more amazing people who are genuinely passionate about helping you succeed. Every time I'm here, I'm surrounded by creativity, support, and endless possibilities. If you've got an idea brewing, this is definitely the place to make it real!
Posted on Google Google
The Duncan Reid Consultancy profile picture
The Duncan Reid Consultancy
Google star 1Google star 2Google star 3Google star 4Google star 5Trustindex verifies that the original source of the review is Google.
A great nest of geekery & creativity in the heart of the City's Fabric District. A welcoming community whether visiting, using the workshop or holding a permanent desk. My only regret is not getting in more often! DoES naturally attracts the mavericks, the do-ers, the creators, the crafty, the techies, the software gurus, the electronics bods and makers of all ilk. Highly recommended whether you need access to woodworking equipment, CNCs, laser cutters, fabric machines, electronics workbench or just simple deskspace.
Posted on Google Google
Andy Green profile picture
Andy Green
Google star 1Google star 2Google star 3Google star 4Google star 5Trustindex verifies that the original source of the review is Google.
DoES Liverpool provides is a co-working and maker space situated in Liverpool city centre. In addition to the standard workshop tools, it has 3D printers, laser cutters, a CNC router, heat press, soldering station and a range of printers and plotters. More important still is its human capital. There is such a wealth of knowledge, support and encouragement to tap into. And if they don't know, they almost certainly can put you in contact with someone who DoES!
Posted on Google Google
G Godfrey profile picture
G Godfrey
Google star 1Google star 2Google star 3Google star 4Google star 5Trustindex verifies that the original source of the review is Google.
Wonderful space for crafts of all types with a great range of equipment and tools. The lovely people at DoES have the skills to help with any project. If you're interested in getting membership, check it out on Thursday at Maker's Night or a Jelly Liverpool once a month.
Posted on Google Google
Magne Lauritzen profile picture
Magne Lauritzen
Google star 1Google star 2Google star 3Google star 4Google star 5Trustindex verifies that the original source of the review is Google.
Excellent makerspace. Good collection of equipment and tools for electronics, metalwork, woodwork, textiles, and everything in between. Great bunch of people, eager to help and easy to get along with.
Posted on Google Google
Eric Dingler profile picture
Eric Dingler
Google star 1Google star 2Google star 3Google star 4Google star 5Trustindex verifies that the original source of the review is Google.
As a digital nomad, I work in coworking spaces around the world. This is EASILY my favorite in all of the UK. In fact, in all of Europe.
Posted on Google Google
Neil Morrin profile picture
Neil Morrin
Google star 1Google star 2Google star 3Google star 4Google star 5Trustindex verifies that the original source of the review is Google.
DoES is a great maker space and coworking space situated only 10 Minutes from Lime Street Station. If you ask nicely they give you a guided tour around all workshops and offices. They have great machines, such as hireable 3D printers, Laser Cutters and CNC machines, sewing machines etc etc. Plus Free Coffee
Verified by Trustindex
Trustindex verified badge is the Universal Symbol of Trust. Only the greatest companies can get the verified badge who has a review score above 4.5, based on customer reviews over the past 12 months. Read more