k8055 control from php in Linux
What is the aim?
When users click on buttons on a website, various 230 V appliances can be switched on/off
The steps
- Setting up a Linux server
- Getting linux drivers etc for the k8055 module
- Fixing usb permissions (sigh)
- Controlling k8055 module from php
- Connecting the k8055 module to power-stuff
Setting up a Linux server
I went for the Ubuntu – Server Edition and adding the ubuntu-desktop by ’sudo apt-get ubuntu-desktop’ later.
This gave me:
- A LAMP setup done “automatically”
- A GUI to suit my newbie-needs
Getting the k8055 module running in Linux
I am using libk8055 – a nice linux library and a command line tool made by Sven Lindberg.
The library can be used in your own applications (c or Python) – but to my use, the k8055 command line tool does it all.
Installing the k8055 :
- Install libusb-dev – ’sudo apt-get install libusb-dev’
- Download and compile the libk8055 as instructed
- Use ‘lsusb’ to make sure the k8055 device is discovered by the system
- Test it: use ’sudo k8055 … ‘ until you have fixed the &%¤@ usb-permissions
Getting the USB permissions right
This turned out to be the real killer for me. Possibly because I am a Linux virgin.
Google gives you lots of links to doing the usb permissions for the k8055. But many will be misleading or wrong in your case.
Make sure: That the permissions instructions you use is valid for the linux-distribution you use.
What do I want?
- From php, using exec( “k8055 -d:1″) must control the k8055 (via the command line application)
Translated to permissions: “The world” must have access to the k8055.
This following did the trick for me in Ubuntu 8 Hardy Heron:
in the directory
/etc/udev/rules.d
add a file named like this
41-k8055.rules
and in this file write
SUBSYSTEM=="usb", ENV{devtype}=="usb_device", ATTRS{idVendor}=="10cf", ATTRS{idProduct}=="5500", MODE:="0666"
idProduct depends on your jumper setting in k8055. view it by typing
lsusb
Controlling the k8055 from php
Once the permissions is set, the exec( ) command in php is all I need.
Setting outputs:
- exec( “k8055 -d:1″) – This sets the digital port #1
Reading from the k8055:
- exec( “k8055 -d:1″, $output) – $output will return an array of the output from the application
See ‘man k8055′ : Output
timestamp);(digital);(analog1);(analog2);(counter1);(counter2)
Hi
I’m another user of the 8055 board, under linux (ubuntu dapper) with the great lib k8055. Another way more simple to get the privilege to access the boarf for the user wich runs the web daemon (user www-data under ubuntu), its to add it to the plugdev group (sudo adduser www-data plugdev).
I’m pretty sure than in Hardy a a usb device from the subsystem usb_device is allready associated to the plugdev group in r/w mode. Isn’t in dapper. Dapper user’s should add GROUP=”plugdev” at the end of the line of SUBSYSTEM==”usb_device”,
Regards from France.
Hi
I Just followed your guide and it worked kind a for me, I just had some troubles with the usb rights, I finally figured out that I had to restart the udev (on ubuntu 9.10 Karmic Koala: “sudo restart udev” as “/etc/init.d/udev restart” wouldn’t do the trick for me) If that still doesn’t do the trick. You’ll just have to reboot: “sudo shutdown -r now”
Thats all!
Regards from the Netherlands
Hi,
I have a debian etch 64 bit system.
I have installed libusb v1.06 in /usr/local.
I have added /usr/local to LD_LIBRARY_PATH.
I have installed libusb-dev.
I cannot compile the K8055 source code:
chris@peterpan:~/velleman/src$ make
gcc -O2 -DDAEMON -DVERSION=’”0.3″‘ -Wall -c -g -fPIC libk8055.c
libk8055.c: In function ‘init_usb’:
libk8055.c:145: warning: implicit declaration of function ‘usb_init’
libk8055.c:146: warning: implicit declaration of function ‘usb_find_busses’
libk8055.c:147: warning: implicit declaration of function ‘usb_find_devices’
libk8055.c:148: warning: implicit declaration of function ‘usb_get_busses’
libk8055.c:148: warning: assignment makes pointer from integer without a cast
I am not a C person. Seems to me I need a usb header file with above missing function definitions. Where do I get them from? What have I done wrong?
Regards,
Chris.
I read some more posts elsewhere and found others with this same problem in other development environments. The fix for them was to hard code the path to usb.h in the include statement. I tried that and it worked!
So in libk8055.c in have
/* #include */
#include “/usr/include/usb.h”
I have no idea why this should be necessary.
Chris.
Hi Chris
I am glad you got it working. My knowledge about k8055 and linux is very thin.
I have moved to use the Arduino board now, mostly. You should check that out. Cheap and very easy to use.
yt
Christian
I have a Ubuntu 10.04 system. I have the LIBK8055 library installed. The K8055 board working well from the command line and a script file. Permissions are open for the world. However, when I attempt to run it from a php script it cannot open the k8055 port. Any ideas?
Duane
Thank you jotape99. Changing the group to plugdev in the rules file corrected my problem.
I just want to say that adding the k8055 executable to the /etc/sudoers file was my solution of the problem of accessing the usb from the PHP file.
I think this is quite a “safe” option.
I did this on my Netgear ReadyNas.