Introduction: Remote Control With Raspberry Pi and Phidget WebService
Enable your Raspberry to control relay, led, sensor and digital input remotely with Phidget WebService. "The Phidget WebService is a background process that broadcasts all events and data from a USB Phidget over the network: It uses link local addressing which allows you to use simple server names in your code. The link local addressing is provided by the programs Bonjour, avahi, or mDNSResponder, depending on your system, and the correct program is either installed already or with the Phidget libraries. You can listen to the Phidget data and control the Phidgets over the network using one or more computers."More info
You need a Raspberry with Raspbian preinstalled, a Phidgets IO Board, I use a 1011_0 - PhidgetInterfaceKit 2/2/2, a small usb Dongle with 2 Analog Inputs, 2 Digital Inputs and 2 Digital Outputs, two analog sensor, in this tutorial I use a 1133_0 - Sound Sensor and a 1142_0 - Light Sensor 1000 lux, two led connected to digital output, one toggle switch and a Miniature Magnetic Contact Switch connected to digital input.
Step 1: Install Phidget Library
Update the packages with
sudo apt-get updateand
sudo apt-get upgradeInstall libusb (Library for programming USB applications without the knowledge of Linux kernel internals).
sudo apt-get install libusb-1.0-0-devdownload and install the Phidgets libraries.
wget http://www.phidgets.com/downloads/libraries/libphidget.tar.gzthen
tar zxvf libphidget.tar.gzmove in the decompressed folder, in this example
cd libphidget-2.1.8.20150410/
From the main unpacked libraries directory, run:
./configure
makethis takes a long time, you can go get a coffee
sudo make install
This will compile phidget21.h and place the library into your gcc path
Step 2: Install the WebService
Download the webservice
wget http://www.phidgets.com/downloads/libraries/phidgetwebservice.tar.gzthen
tar zxvf phidgetwebservice.tar.gzmove in the decompressed folder in this example
cd phidgetwebservice-2.1.8.20150410/From the unpacked WebService source code directory, run:
./configure
make
sudo make installThis will compile the executable phidgetwebservice21 and place it into /usr/bin/phidgetwebservice21
Create a file to manage start and stop for the webservice
sudo nano /home/pi/phidgetwebservicewith this content
#!/bin/sh ### BEGIN INIT INFO # Provides: phidgetwebservice # Required-Start: $network $remote_fs # Required-Stop: $network $remote_fs # Should-Start: avahi # Should-Stop: avahi # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Phidget WebService # Description: Phidget WebService for controlling Phidgets over the network. ### END INIT INFO DESC="Phidget WebService" NAME=phidgetwebservice BIN=phidgetwebservice21 DAEMON=/usr/bin/$BIN PIDFILE=/var/run/$NAME.pid CFG=/etc/default/$NAME # Gracefully exit if the package has been removed. test -x $DAEMON || exit 0 # load config pws_port="5001" pws_serverid="" pws_password="" [ -f $CFG ] && . $CFG start() { [ -z "$pws_port" ] || OPTIONS="-p $pws_port " [ -z "$pws_password" ] || OPTIONS="$OPTIONS-P $pws_password " if [ -z "$pws_serverid" ]; then OPTIONS="$OPTIONS -n $( hostname )" else OPTIONS="$OPTIONS -n $pws_serverid" fi echo -n "Starting $DESC: " start-stop-daemon -S -b -q -p $PIDFILE -m -x $DAEMON -- $OPTIONS && echo "OK" || echo "ALREADY RUNNING" } stop() { echo -n "Stopping $DESC: " start-stop-daemon -K -q -p $PIDFILE -x $DAEMON && echo "OK" || echo "NOT RUNNING" } case "$1" in start) start ;; stop) stop ;; restart|force-reload) stop sleep 1 start ;; *) echo "Usage: $0 {start|stop|restart}" esac exit 0give it executable permission
sudo chmod -R 0755 /home/pi/phidgetwebservicethen try to start with command
sudo sh phidgetwebservice startTo start the web service automatically
sudo mv /home/pi/phidgetwebservice /etc/init.d/phidgetwebservice
sudo insserv -d phidgetwebservicereboot raspberry
sudo reboot
Step 3: Use It
Ok now we can control the 1011 remotely.
For Windows open the Phidgets control panel, in tab Web Service / Bonjour you can see all boards Phidgets connected to Raspberry
Double click on Phidget InterfaceKit 2/2/2 open this window, where you can read input analogic - digital and interact with output, turn on/off the leds
For Mac
In this tutorial I used the control panel Phidgets to test the operation, of course you can write your application in a language you want and with the operating system that you use normally. If you need more inputs outputs you can use the 1018 or 1012.
Discussions