This project was really fun and involved a nice combination of hardware, Twillio, express and johnny-five. The idea was to display any sms messages received by a Twillio number on a bluetooth connected lcd screen.
The Hardware:
- Microduino+ (arduino mega compaitible)
- 20x4 lcd screen
- HC-05 bluetooth module
Everything is connected using the following configuration:
The Software:
- Twilio
- Heroku deployment of page me bro source on github, deployed app
- Node code running using johnny-five
There and back again; from SMS to JSON:
Twillio receives a text message and submits a POST with the message information in JSON format to the pagemebro web site that emits a socket message to all clients connected, the final piece is the node script that connects to the pageMeBro web site via sockets and receives the message.
Demo:
Code :
var io = require('socket.io-client'),
socket = io.connect('http://pagemebro.herokuapp.com/'),
five = require("johnny-five"),
lcd,
board = new five.Board({
//here we specify the bluetooth port.
port: "/dev/tty.Arduino2-DevB"
});
var lcdPrint = function (lineOne, lineTwo) {
lcd.clear()
.cursor(0,0).print(lineOne)
.cursor(1,0).print(lineTwo);
};
board.on("ready", function() {
lcd = new five.LCD({
pins: [7, 8, 9, 10, 11, 12]
});
lcd.on("ready", function() {
//display the date when the lcd screen is ready.
var date = new Date();
lcdPrint(date.toDateString(),
date.toLocaleTimeString());
});
});
//subscribe to the socket and display the text.
socket.on('connect', function () {
// socket connected
socket.emit('deviceConnect', { device: 'pager' });
//respond to the new message event.
socket.on('message:new', function (data) {
lcdPrint(data.from, data.Body);
});
});
Too much just to receive a text message? yea but it was fun.