Skip to content

Communication between Raspberry Pi and PC (Node.js)

mktk1117 edited this page Aug 19, 2016 · 3 revisions

In here, we use Node.js and Socket.IO to communicate between Raspberry Pi and PC. In addition, it can be used to communicate between other process in Raspberry Pi.

In this project, image processing is done by C++ and OpenCV and, Node.js server recieves the control signal from image processing. At the same time, the server can recieve the signal from other PC, so the user can stop or control the vehicle remotely.

#What the server does in this project

  • Receive messages from image processing process
  • Receive messages from PC
  • Translate the control command to Arduino command
  • Send command to Arduino with serial
  • Visualize the results and control command

#Node.js

Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient. Node.js' package ecosystem, npm, is the largest ecosystem of open source libraries in the world.

How to install latest version of Node.js

####1. Install nodejs, npm usually

 $ sudo apt-get install -y nodejs npm

####2. Introduce n package

$ sudo npm cache clean
$ sudo npm install n -g

####3. Install node with n package

$ sudo n stable
$ sudo ln -sf /usr/local/bin/node /usr/bin/node

####4. Remove the old versions

$ sudo apt-get purge -y nodejs npm

####5. Check if successfully intsalled

$ node -v

Socket.IO

Socket.IO enables real-time bidirectional event-based communication. It works on every platform, browser or device, focusing equally on reliability and speed.

Official Page, github

###Install First, move to the working folder.

cd /path/to/working/directory

Then, install socket.io at the folder.

 npm install socket.io