Bonescript & Web

414 views
Skip to first unread message

Matt Richardson

unread,
Jan 14, 2012, 9:00:17 AM1/14/12
to BeagleBone
Hello,

I come from an Arduino background and I'm interested in the BeagleBone
for some of my projects. A lot of the stuff I do with the Arduino is
internet connected, and I like the idea of having a little more
processing power on the board (instead of offloading that onto an
external PHP server). Anyway, I've been playing with the bonescript
example and can get blinking LEDs, but I'd like a very basic example
of how to control LEDs via the web. I.e., a web page served by the
BeagleBone that has a button for "On" and "Off" to turn an LED on and
off. This would be immensely helpful in my quest to learn how this
stuff works. Can anyone point me to anything or give me any clues how
I should accomplish this?

Thanks,
Matt Richardson
http://mattrichardson.com/

Jim Richards

unread,
Jan 14, 2012, 12:11:03 PM1/14/12
to BeagleBone
I believe that bone script was written with Node.js. You should be
able to accomplish what you are trying to do with Node and a serial
comm package. Here is a link to a serial communications package
written in Node.

https://github.com/voodootikigod/node-serialport

Jim

Matt Richardson

unread,
Jan 14, 2012, 3:54:27 PM1/14/12
to beagl...@googlegroups.com
Thanks, Jim. I'm not quite up to the point that I need serial comm yet. As of right now, I'm looking for a basic "Hello World" of using a node.js-based web server to control GPIO on the BeagleBone. I'm learning how to set up a dynamic web server with node.js on the BeagleBone, and that is going well so far. I'm just looking for the best way to integrate digitalRead, digitalWrite, etc. that bonescript offers. So that:

http://10.0.1.5/on brings a GPIO pin high
http://10.0.1.5/off brings a GPIO pin low
http://10.0.1.5/status returns the status of the GPIO pin
http://10.0.1.5/blink blinks the GPIO pin

Thanks again,
Matt

ra...@raffy87.nl

unread,
Jan 19, 2012, 1:19:29 AM1/19/12
to BeagleBone
Matt,

I found a link for you the help you with your "Hello World" web
server.

http://support.cloud9ide.com/entries/20640198-lesson-3-writing-a-node-js-hello-world-program

I also come from an Arduino background. And always liked your
projects.

You`ll be hearing from me te tougle an output LED trou a web
interface.

Raphael Baars
The Netherlands

ra...@raffy87.nl

unread,
Jan 19, 2012, 5:38:31 AM1/19/12
to BeagleBone
Matt,

try this out,

var http = require('http');
var bb = require('./bonescript');

var ledPin = bone.USR3;
var statReturn = '/';

setup = function() {
pinMode(ledPin, OUTPUT);
};

loop = function() {
if (statReturn == "/?status=on" || statReturn == "/?status=LED+on")
{
digitalWrite(ledPin, HIGH);
}
else if (statReturn == "/?status=off" || statReturn == "/?
status=LED+off"){
digitalWrite(ledPin, LOW);
}
};

http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end('<html><body><CENTER><form><button name="status"
type="submit" value="on">LED on</button><BR><button name="status"
type="submit" value="off">LED off</button></form></body></html>' );
statReturn = req.url;
console.log(statReturn);
}).listen(80);

bb.run();

maybe it gives you some ideas.

Raphael

I got most of the info from http://nodejs.org/docs/latest/api/index.html

Matt Richardson

unread,
Jan 19, 2012, 4:10:30 PM1/19/12
to beagl...@googlegroups.com
Raphael,

This works perfectly. Thank you so much, it's just enough for me to started.

Thanks again,
Matt Richardson
Reply all
Reply to author
Forward
0 new messages