Skip to content

Commit

Permalink
johnny five and socketio
Browse files Browse the repository at this point in the history
  • Loading branch information
scc36 committed Oct 11, 2014
1 parent 0dc4383 commit a419fa8
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 4 deletions.
2 changes: 0 additions & 2 deletions ex9-socketIO.js

This file was deleted.

21 changes: 19 additions & 2 deletions exA-johnny5.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,19 @@
// Outputs "Hello World" to the console
console.log("Hello World");
// https://github.com/rwaldron/johnny-five/
// Johonny Five
// npm install johnny-five

// Be sure to install on Arduino: File > Examples > Firmata > StandardFirmata
// Connect your computer to the Arduino

// Sets module to variable "five"
var five = require("johnny-five");

// Attempts to find a connected device
// Will fail with error if none are found
var board = new five.Board();

// When device is connected...
board.on("ready", function() {
// Create an Led on pin 13 and strobe it on/off
(new five.Led(13)).strobe();
});
32 changes: 32 additions & 0 deletions exB-socketIO.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// This will be a combination of a socket.io and express.js server
// Socket.io functions as a communication platform

// Set express, application, then startup server
var express = require("express");
var app = express();

// Note that this part differs from previous examples, http is separated out
var http = require("http").Server(app);

// include the socket.io program and run it
var io = require("socket.io")(http);

// Sets the /static webpage route to the /public folder
app.use("/static", express.static(__dirname + "/public"));

// Add a "route" that leads to the req/res, as seen in Node.js
app.get("/", function(req, res){
// Grab a file and respond with that
res.sendFile(__dirname + "/public/socket.html");
});

// if someone connects to socket io
io.on("connection", function(socket){
console.log("a user connected");
io.emit("message", "Hello back");
});

// Starts up the server
var server = http.listen(1337, function() {

});
25 changes: 25 additions & 0 deletions public/socket.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Example Web Page</title>
</head>
<body>
<h1>My Webpage</h1>
<p>Here it is</p>

<!--- Note that /static is used, even if the picture is in /public --->
<img src="/static/makerbar.jpg" alt="Makerbar picture">

<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io();

socket.on("message", function(msg){
console.log(msg);
});
</script>
</body>
</html>

0 comments on commit a419fa8

Please sign in to comment.