Raspberry PI based ROV

Anything to do with the Raspberry Pi
perfo
Posts: 151
Joined: Jan 27th, 2015, 12:05 am

Re: Raspberry PI based ROV

Post by perfo »

It's not a question of saying please or not,,,, its' how many pleases will it take :)

I don't want you to spend ages on it but if it is a quick easy job for you to knock up an example then I will indeed be most grateful.

Please, Please ...

thanks...
perfo
Posts: 151
Joined: Jan 27th, 2015, 12:05 am

Re: Raspberry PI based ROV

Post by perfo »

Ah yes I see the bit where you've named the canvas as RovContext and then referenced that further down the script.. So I think I've go the HTML5 bit sorted now...hmmm well only the drawing stuff on the screen bit of the HTML5 the socket bit is still evading me though I am honing in of the beast...
I'm wading through java script stuff at the moment.....
User avatar
Moki
Posts: 119
Joined: Oct 21st, 2014, 2:19 am
Location: The Netherlands

Re: Raspberry PI based ROV

Post by Moki »

Right... did some deleting on the the code... just to get a keyup/keydown socket event.
Using 3 files (server.js package.json and public/index.html)

server.js

Code: Select all

//
// Copyright (c) 2015, Eric van Dijken <eric@team-moki.nl>
//

var version = "0.0.1";

var express = require('express');
var app = express();
var server = require("http").Server(app);
var io = require("socket.io")(server);

/* Server config */
app.set("ipaddr", "192.168.1.128");
app.set("port", 3000);
app.set("views", __dirname + "/views");
app.use(express.static("public", __dirname + "/public"));
app.get("/", function(request, response) {
        res.sendfile('index.html');
});

/* Socket.IO events */
io.on('connection', function(socket){
  console.log('connected');

  socket.on('disconnect', function(){
    console.log('disconnected');
  });

  socket.on('keydown', function(event) {
    console.log('Keydown request: %s', event);
    socket.emit("command","ON");
  });

  socket.on('keyup', function(event) {
    console.log('Keyup request: %s', event);
    socket.emit("command","OFF");
  });

});

//Start the http server at port and IP defined before
server.listen(app.get("port"), app.get("ipaddr"), function() {
  console.log("PERFO Server up and running. Go to http://" + app.get("ipaddr") + ":" + app.get("port"));
});
package.json

Code: Select all

{
  "name": "Perfo",
  "version": "0.0.1",
  "description": "Raspberry PI nodejs example",
  "main": "server.js",
  "repository": {
    "type": "git",
    "url": "https://github.com/Moki38/perfo.git"
  },
  "keywords": [
    "Raspberry PI"
  ],
  "dependencies": {
    "express": ">= 4.6.1",
    "socket.io": ">= 1.0.6"
  },
  "author": {
        "name": "Eric van Dijken <eric@team-moki.nl>"
        },
  "contributors": [
    {
      "name": "None",
      "email": "@",
      "url": "https://github.com/none"
    }
  ],
"scripts": {
        "start": "node server.js"
    },
  "license": "MIT"
}
public/index.html

Code: Select all

<!doctype html>
<html>
  <head>
    <title>Raspberry PI Perfo (V0.0.1)</title>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
    <script src="http://code.jquery.com/jquery-1.11.1.js"></script>
    <script src="/socket.io/socket.io.js"></script>

    <script type="text/javascript">
     var socket = io.connect();

     wIsDown = false;

     $(window).keydown(function(e){
        switch(e.which){
          case 87:
            if(wIsDown) return;
            wIsDown = true;
            socket.emit('keydown', 'ON');
            break;
        }
     });

     $(window).keyup(function(e){
        command = "Stop";
        switch(e.which){
          case 87:
            if(!wIsDown) return;
            wIsDown = false;
            socket.emit('keyup', 'OFF');
            break;
        }
     });

     </script>

  </head>

</script>

<body bgcolor="#00000000">
</body>

</html>

Run commands
- npm install (needed for the express module)
- node server.js
perfo
Posts: 151
Joined: Jan 27th, 2015, 12:05 am

Re: Raspberry PI based ROV

Post by perfo »

Thanks... I'll pick through that and see If I can learn something...

what does this bit do ?
<script src="http://code.jquery.com/jquery-1.11.1.js"></script>
I mean I know it is making the stuff in jquery available in this module but what do we need that's in jquery that we haven't got in the code ?

I'm afraid I still can't see what express is doing,
It looks to be doing the same thing as Node will do anyway, but never mind I'm sure I'll figure it in the end... :)

Thanks a lot for that Moki .....
perfo
Posts: 151
Joined: Jan 27th, 2015, 12:05 am

Re: Raspberry PI based ROV

Post by perfo »

npm install...now I see the point of package.json I had erroneously thought it was a file to send with your project to check the right versions where installed. I hadn't realised using npm install actually used the file to install everything you need locally rather than the global express or whatever... This in itself has been a handy hint....
perfo
Posts: 151
Joined: Jan 27th, 2015, 12:05 am

Re: Raspberry PI based ROV

Post by perfo »

Does this mean anything to you :)

Code: Select all

npm WARN package.json Perfo@0.0.1 No README.md file found!
npm WARN unmet dependency /home/pi/Moki2/node_modules/socket.io/node_modules/socket.io-parser requires debug@'0.7.4' but will load
npm WARN unmet dependency /home/pi/Moki2/node_modules/socket.io/node_modules/debug,
npm WARN unmet dependency which is version 2.1.0
npm WARN unmet dependency /home/pi/Moki2/node_modules/socket.io/node_modules/socket.io-client/node_modules/engine.io-client/node_modules/engine.io-parser requires has-binary@'0.1.5' but will load
npm WARN unmet dependency /home/pi/Moki2/node_modules/socket.io/node_modules/socket.io-client/node_modules/has-binary,
npm WARN unmet dependency which is version 0.1.6
Then when I try and run it I get

Code: Select all

module.js:485
    throw err;
          ^
SyntaxError: /home/pi/Moki2/node_modules/express/node_modules/accepts/node_modules/mime-types/node_modules/mime-db/db.json: Unexpected token e
    at Object.parse (native)
    at Object.Module._extensions..json (module.js:482:27)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/home/pi/Moki2/node_modules/express/node_modules/accepts/node_modules/mime-types/node_modules/mime-db/index.js:11:18)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
User avatar
Moki
Posts: 119
Joined: Oct 21st, 2014, 2:19 am
Location: The Netherlands

Re: Raspberry PI based ROV

Post by Moki »

Never seen this error before ;)

Which version of node and npm do you use? (node -v and npm -v output please)

And remove the node_modules directory and try the "npm install" command again.
perfo
Posts: 151
Joined: Jan 27th, 2015, 12:05 am

Re: Raspberry PI based ROV

Post by perfo »

Okay cokay..
Node version 0.10.0 I think I rolled this back to an earlier version to get it to work with your rov software..
NPM version 1.2.14

I deleted node_modules and re run NPM install. All seemed good with no errors so I re tried
Node server.js and got

Code: Select all

 
events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: listen EADDRNOTAVAIL
    at errnoException (net.js:863:11)
    at Server._listen2 (net.js:989:19)
    at listen (net.js:1030:10)
    at net.js:1104:9
    at dns.js:72:18
    at process._tickCallback (node.js:415:13)
    at Function.Module.runMain (module.js:499:11)
    at startup (node.js:119:16)
    at node.js:903:3
however that was caused by me being thick... I had reinstalled server.js but not changed the IP address...
So deleting node_modules and re doing npm install fixed it.... I'll go and play now....thanks
perfo
Posts: 151
Joined: Jan 27th, 2015, 12:05 am

Re: Raspberry PI based ROV

Post by perfo »

Code: Select all

ReferenceError: res is not defined
   at /home/pi/Moki2/server.js:18:9
   at Layer.handle [as handle_request] (/home/pi/Moki2/node_modules/express/lib/router/layer.js:82:5)
   at next (/home/pi/Moki2/node_modules/express/lib/router/route.js:110:13)
   at Route.dispatch (/home/pi/Moki2/node_modules/express/lib/router/route.js:91:3)
   at Layer.handle [as handle_request] (/home/pi/Moki2/node_modules/express/lib/router/layer.js:82:5)
   at /home/pi/Moki2/node_modules/express/lib/router/index.js:267:22
   at Function.proto.process_params (/home/pi/Moki2/node_modules/express/lib/router/index.js:321:12)
   at next (/home/pi/Moki2/node_modules/express/lib/router/index.js:261:10)
   at SendStream.error (/home/pi/Moki2/node_modules/express/node_modules/serve-static/index.js:107:7)
   at SendStream.EventEmitter.emit (events.js:95:17)
hmmm sorry this is what I get now.. but the browser is connecting to the PI so sorta working...
User avatar
Moki
Posts: 119
Joined: Oct 21st, 2014, 2:19 am
Location: The Netherlands

Re: Raspberry PI based ROV

Post by Moki »

Not sure, but replace "res" with "response".
See if that helps, i think it will.
Post Reply