communicate with my raspberry PI, through my webserver - node.js

I want to communicate with my raspberry pi, through my webserver.
I want to use a web interface on my server, with which I can control an LED on my PI.
Can I use "node js" for this? or does anyone have a good idea or examples?
regards

You can indeed use just about any web server to communicate with the pi and thereby control its GPIO pins.
I wrote a web server specifically to interface with the pi's GPIO capabilities complete with utilities and examples if you want to try it out. It's a very lightweight native-code (C++) web server that you can use to control your LEDs (or what have you) with about 5 mins of setup:
OliWeb on GitHub
You can install it using git with:
sudo git clone https://github.com/m2ware/OliWeb.git
You could also install just about any other web server out there (Nginx, Node.JS, take your pick) and set up CGIs to call command-line utilities to drive the LED pins. Gordon's WiringPi utilities are easy to use and install - installation and usage instructions are below.
Gordon's WiringPi Utility
Each web server will have its own particulars in terms of invoking command line interfaces via CGI. If you're interested in NodeJS specifically, this describes how to invoke command-line functionality from Node:
How to invoke external scripts programs from node js

I know it is a little bit late, although for those who may be still interested I've recently developed a school project which does exactly this job.
I've used WebSocket and GPIO handling.
Here's the repo for the client: https://github.com/jkomyno/material-led-controller/
Here's the one for the server (you gotta put this on your RPI):

Related

What would be the recommended way to exchange data from a WebGL application running on a Raspberry Pi to write to the Pi's serial interface?

Here's the full problem:
I have a WebGL build of a Unity project running on a Pi, and I need the data from this process written to the Pi's serial interface (and vice versa). The best possible solution I can think of is hosting the WebGL server using Express, and utilizing nodejs for the backend process of somehow running some python code that works the serial interface. Problem is, I'm super inexperienced with these platforms and I don't have enough familiarity with how they all work together to intuitively feel out what to do. Hoping I can get some guidance on any recommended paths.
Pre answered questions:
Unity project on a Pi?: I have a simulation running in Unity, and I need it running on a lightweight computing platform. The only way to run this on a Pi is in a WebGL build.
What are you trying to achieve?: I'm trying to achieve a communication pipeline with this WebGL process and an Arduino, specifically over serial.
What I've tried:
I've tried running the WebGL process utilizing systems like Banyan, which would allow communication with a server, but it seems the WebGL build does not allow sockets.
I've tried hosting the server using Express through nodejs, and the app does actually work, I just need help understanding how this system works such that I can exchange data from the WebGL app and a python script that is running the serial comms. As stated above, I'm very new to the nodejs system so I may not even be using the nomenclature properly.

CGI version of expressjs

I want to create a small web service and for that I really want to use node.js and express.
I already have an Apache running on my little server (it's a Raspberry PI :P ) which receives all the traffic. How can I configure a VirtualHost to be served by node.js?
I searched a lot and I found many solutions, namely:
Use ProxyPass to forward requests from Apache to node.js
Use Rewrite rules in .htaccess file
Use VPS
But all these solutions require a running daemon for node.js and resources are scarce on Raspberry PI (it only has 256MB of RAM). So I searched a bit more and I found this solution:
GGI-Node provides the ability to run JavaScript on any web server just like PHP as a CGI using Node.js.
But again, this solution doesn't fulfill my requirements. GGI-Node is more of an adaptation of node.js to PHP and it's not possible to use with/like express.
So I came up with an idea: what about modifying express to keep the same behavior and functionality and, instead of creating a server, feeding express with info from Apache via CGI? I searched even more and I didn't find anything like that... Is this possible to do? How hard would it be to implement?
I know this solution doesn't take the advantages of node.js asynchronous I/O, but it's not important in my case.
Here's one possible solution: Get another Raspberry Pi or two :-)
No, I'm not kidding. Here's what I'm thinking:
With one additional Raspberry Pi:
Set up the Raspberry Pi running Apache as a proxy for your new virtual host & route all the traffic for that virtual host to Raspberry Pi #2. Set up node.js and your express application on Raspberry Pi #2.
With two more Raspberry Pis:
Leave Raspberry Pi #1 as is (with Apache & whatever other web site you have running on it).
Set up Raspberry Pi #2 with node.js & your express application
Setup up Raspberry Pi #3 with a proxy and proxy requests to #1 & #2. Apache can do it, although it's a pretty "heavy" solution - I'd go with nginx personally.
Actually, you could do it with just one Pi
Set up the Express app to listen on some arbitrary port & use Apache to proxy requests to the new virtual host to that port.
However...
How ever you do this, be advised that the Raspberry Pi (at least the earlier models) are not good at running node.js. I tried this (running an Express app) with an original Raspberry Pi and performance was not good (I wound up rewriting the code in go). You might have better luck with a Pi 2 or a Pi 3.
If you decide to go this route...
Here's a link to a Digital Ocean tutorial on using Apache as a proxy. I haven't followed this tutorial, so I can't vouch for it, but a cursory glance suggests that it's pretty complete.

Using 7" TouchScreen Cape on Beaglebone Black

So, im developing an robotics application that uses a BeagleboneBlack as a controller for 3 different servos.
I know how to access the pins and everything from Cloud9 IDE directly into the board.
However, im using a 7" cape ( 4d Systems, 4DCAPE-70T ) and when i connect them, Debian automatically starts up.
I guess my question is, how do you code an app with a UI that can be accessed from the Debian distro directly from the 7" screen?
All my research has lead me to a final decision, which is mounting a node.js server on the bbb and making an HTML interface and with the bonescript libs, access the pins.
Has anybody done anything similar to this?
If anybody has a another approach to this, that would be great
If any time traveller out there stumbles upon this question, here is how i figured it out:
1) Get rid of bonescript. It will give you a hard time assigning pins for PWM and some other uses. Instead, use octalbonescript. reference to repo
2) Install socket.io
try and start a local server with it. Follow various tutos out there. If you run into a boot-up error regarding the server, use port 8090.
3) Design a web page that connects to a local host ( beaglebone itself) using socket.io. Again, various tutos out there.
DONT TOUCH THE KERNEL, NOR THE FILE TREE. Its unnecesary.
4) Open that same web page on your beaglebone. That way, you dont need an internet connection or whatever. The javascript side of the web page will call the appropriate methods on the beaglebone through socket.io ( socket.emit() ).
Its important to understand that all the beaglebone-side instructions, such as pin access, pwm and such, are performed on the same file where the socket is made. The web page 'calls' this methods on the bbb.
5) Enjoy!
I was using it for a robotics project. We were building a delta robot controlled by the Beaglebone Black ( Rev C ). I am serious, start with what i am telling you, you will save a LOT of time.
Edit: Guess i forgot the most important part. The cape uses several of the pins, incluiding various PWM. Octalbonescript, as of this moment, does not support capes. It will, but not at the moment. So, dump the screen and use an ethernet cable to connect your beaglebone to the network. That way, you can access the interface from any device through a browser at beaglebone:8090. ( NOT beaglebone.local:8090 )

Local pi server running node and websockets

I'm just wondering is it possible to run a local server using node (node would be running on a raspberry pi) and communicate with it via a web browser on a different machine on the same network using websockets? I'm looking into using a browser as a control system for a project I'm working on. If it is possible is there any references I can look at?
Thank you,
Techhead55.
EDIT
I already have node up and running on the pi, it's just that I'm not sure if you can and how you implement a local server and use sockets to communicate with it in a bowser on the same network.
Not sure if you specifically ask about Node, but here is an example of a WebSocket server running on Pi, and browsers connecting to that server: http://tavendo.com/blog/post/pypy-on-the-pi/
The example does Publish & Subscribe over WebSocket using WAMP (http://wamp.ws).
Here is a similar example running on Arduino Yun that shows how to connected hardware, and publish data in real-time via WebSocket, receiving data in a browser, and real-time rendering a chart: http://tavendo.com/blog/post/arduino-yun-with-autobahn/
Disclosure: I am original author of Autobahn and work for Tavendo.
Yes.
Here is great manual from Matthias Rüedlinger:
http://blog.rueedlinger.ch/2013/03/raspberry-pi-and-nodejs-basic-setup/
Also installation of ghost with node on RPI is very nice :)
http://bit.ly/1cFwFAQ

RPC from Windows to linux

Is there some (working) example how to create RPC from windows to linux?
Client should be windows NT application, server is linux.
It needs to be MSRPC.
No Corba, no XML-RPC, SUN-RPC etc
MSDN says this:
RPC can be used in all client/server applications based on Windows
operating systems. It can also be used to create client and server
programs for heterogeneous network environments that include such
operating systems as Unix and Apple.
Unfortunately after spending few hours on google I'm giving up.
My expectation:
Linux node should have samba installed, because their MSRPC implementation works.
Using IDL file I generate stubs for both client and server
Client is built using MSVC
Server is build using gcc with some includes/libraries from samba (or other libs)
Linux node must have such RPC port mapper
Can someone point me out?
I think you have 2 possible ways to deal with this:
1- You can try using DCOM with wine, which means that you will actually write your code for windows, but at the same time you can test your results in the process and avoid using WinAPI calls that wine is not able to handle properly. This approach will allow you to generate stubs code from your IDL files.
2- You can try using Samba RPC Pluggable Modules, but I am afraid in this case the RPC communication will be more primitive.
Edit:
It seems there are many other ways. I found a list of libraries in DCOM-Wikipedia, j-Interop for example looks particularly promising.

Resources