I'm attempting to write a basic html page to control hardware on the 
BeagleBone Black. The HTML file looks like this:
<!DOCTYPE html>
<html>
<head>
    <script src="/socket.io/socket.io.js"></script>
    <script src="http://code.jquery.com/jquery-2.1.1.min.js";></script>
    <script>
        var socket = io.connect();
        socket.on('ledstatus', function (data) {
            console.log(data);
            $('body').css('background-color', data);
        });
        
        function ledOn(){
            socket.emit('led', 'on');
        }
        
        function ledOff(){
            socket.emit('led', 'off');
        }
    </script>
</head>
<body>
    <input type="button" name="on" id="onButton" value="on" 
onClick="ledOn();">
    <input type="button" name="off" id="offButton" value="off" 
onClick="ledOff();">
</body>
</html>

And the .js file looks like this:
var app = require('http').createServer(handler);
var io = require('socket.io').listen(app);
var fs = require('fs');
var bb = require('bonescript');
 
app.listen(8090);

console.log('Server running on: http://' + bb.getPlatform().ipAddress + 
':8090');
 
bb.pinMode('USR3', 'out');
bb.digitalWrite('USR3', 0);
 
function handler (req, res) {
  fs.readFile('index.html',
  function (err, data) {
    if (err) {
      res.writeHead(500);
      return res.end('Error loading index.html');
    }
 
    res.writeHead(200);
    res.end(data);
  });
}
 
io.sockets.on('connection', function (socket) {
  socket.on('led', function (data) {
    console.log(data);
    if (data == 'on') {
        bb.digitalWrite('USR3', 1);
        socket.emit('ledstatus', 'green');
        socket.broadcast.emit('ledupdate', 'green');
    }
    else {
        bb.digitalWrite('USR3', 0);
        socket.emit('ledstatus', 'red');
        socket.broadcast.emit('ledupdate', 'red');
    }
  });
});

And it works just fine. The problem is that my application will not have 
internet access which makes this line problematic:
<script src="http://code.jquery.com/jquery-2.1.1.min.js";></script>

So I downloaded jquery-2.1.1.min.js to the same directory as the HTML and 
.js files, and changed the above line to:
<script src="jquery-2.1.1.min.js"></script>

And it stops working, and I get the following errors when I use Chrome's 
inspect element tool:
Uncaught SyntaxError: Unexpected token < 
Uncaught ReferenceError: $ is not defined 

Anybody know what's going on here?

-- 
For more options, visit http://beagleboard.org/discuss
--- 
You received this message because you are subscribed to the Google Groups 
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to