Building the Pinoccio PomodoroPosted: July 2nd, 2014 | Author: quintendf | Filed under: Uncategorized | View Comments
This week, I had the chance to hang with the team at Pinoccio – they’re building magical little wireless microcontrollers that talk to each other (via a radio mesh) and to a web API (via wifi). When you combine those boards with prebuilt “backpacks” of sensors and other tools, you get a powerful tool for building your personal internet of things.
After poking around with a few ideas, I decided to build a little Pomodoro timer, powered by Pinoccio. I spend a lot of time at my desk context switching between writing/programming on my laptop, and reading/studying on my kindle or paper textbook. Having a big, visual indicator telling me to focus or take a break would be really useful – sort of a needlessly technical version of Chris Poole’s chart.
Once you’re all setup, take a minute to play around with your troop in Pinoccio HQ. Turn your LED’s on/off, and make sure your scouts are responding to scoutscript commands (you can type them right there in the browser!).
Next, lets install the Pinoccio node module. After you login, run the “pinoccio token” command to make sure you’re setup properly. Save the token that returns, as we’ll need it in just a minute.
The first console.log() is a quick test to make sure we’re properly connected. run your app from the terminal, and you should see a stream of JSON on your screen. Press the button on your scout, and you should see new data being reported.
Next, delete or comment out the first console.log(), and uncomment console.log(“Button-press task started.”). Rerun your app. Now, you’ll see “button press task started” each time you press the button on your scout. Not working? Make sure you’ve have the correct value for your troop and scout names.
Now, we need to write two simple functions to interact with the user via the command line, and to pass messages down to the pinoccio that will display our timer light. Starting with the user interaction, we’ll use a simple instance of the “prompt” module which makes it really easy to interact with users on the command line. Our code for this method looks like this:
The prompt documentation has a good explanation of the different configuration options, if you want to make any changes. To wrap everything up, we just need our actual timer method.
Most important here are the two calls we make to the Pinoccio REST API. We use the node module to post led.red to the scout when the timer begins, and when the timer expires we change post a new command to switch to green.
These commands are simple ScoutScript, so read the docs and experiment with making changes: make the LED turn different colors, or pass entirely different commands.
So, now all that remains is putting it all together. The complete code:
You should note the addition of the call to setTimer() when a button press is detected in the API listener. The same call is added to the “yes” answer if-statement in the runPrompt() function.
So that’s it! You should now have a working indicator light that responds to either a button press or console command. Each time you start a new timer, it will run for 25 minutes, before prompting you to start a new pomodoro.
As a next step, I plan to add better tracking of completed tasks (maybe some sort of goal/progress tracking), and maybe figure out a few more interesting Pinoccio interactions to add in. I’ll probably also hook the lead scout (with LED) up to a larger board that can be hung up over my desk.