Demo: one Puck.js and your PC

Only one Puck.js? Here it joins a network simulated in the browser. The program really runs on the Puck, with its button, light, temperature and motion sensors; its neighbours are virtual.

  1. Free the PuckClose the Espruino Web IDE, or disconnect it: the Puck accepts one connection at a time.
  2. ConnectPress Connect and pick the Puck (Chrome or Edge).
  3. UploadChoose an example and press Upload to Puck. Every time you change example or edit program.js, upload again: the Puck keeps running the old program until you do.
  4. PlayFollow the example's instructions below. Drag the Puck node around the network: its LEDs take the colour of its node.
not connected

Puck console

How it works

On the Puck the program starts with target: 'host': instead of using the radio by itself, it waits for the PC. Every round the page sends it the messages of the simulated neighbours in range; the Puck runs the round with its own sensors and answers with its value and message, which the neighbours get in the next round. To the program, it is a real network.

The Puck reads sense('source') (its button toggles it), sense('light') (0 dark to 1 bright), sense('temp') (°C), and on a Puck.js v2 sense('tilt') (0 face up, 0.5 on its side, 1 upside down) and sense('shake') (true for a second after it turns fast). The simulated nodes get the same sensors from config.js. Its LEDs take the colour of its node on screen: the page sends it every time it changes.

After changing program.js, upload again: devices only understand each other when they run the same program.

This demo tests your program on the real interpreter and in conversation with other nodes. The radio between two boards, the ble target, needs at least two devices.