Skip to content

Instantly share code, notes, and snippets.

@omgmog
Created June 15, 2014 13:12
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save omgmog/55e51ad7b0ed0f558c65 to your computer and use it in GitHub Desktop.
Output basic weather to LCD on Arduino using Johnny-five
/*
wiring diagram: https://github.com/rwaldron/johnny-five/raw/master/docs/breadboard/lcd.png
usage:
npm install feedparser johnny-five request
node lcd.js
*/
var five = require("johnny-five"),
request = require("request"),
FeedParser = require("feedparser"),
board, lcd, req, feedparser,
item, items = [], message = [];
board = new five.Board();
req = request("http://open.live.bbc.co.uk/weather/feeds/en/ox4/observations.rss"),
feedparser = new FeedParser();
req.on('response', function (res) {
var stream = this;
if (res.statusCode != 200) return this.emit('error', new Error('Bad status code'));
stream.pipe(feedparser);
});
feedparser.on('error', function (err) {
console.log(err);
});
feedparser.on('readable', function () {
var stream = this, meta = this.meta;
while (item = stream.read()) {
var props = item['rss:title']['#'].split(', ');
message[0] = props[0].replace(/(\d{2}\:\d{2}).*$/,'$1');
message[1] = 'Temp: ' + props[1].replace(/\(.*$/, '');
}
});
board.on("ready", function() {
lcd = new five.LCD({
pins: [7, 8, 9, 10, 11, 12],
});
lcd.on("ready", function() {
lcd.cursor(0, 0);
lcd.print(message[0])
lcd.cursor(1, 0);
lcd.print(message[1]);
});
this.repl.inject({
lcd: lcd
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment