I'm working on a project at the moment that requires a web-based interface to actuate a relay, when then will turn on a series of lights. I'm familiar with PHP programming and I see a few examples of PHP classes on this forum for controlling Arduino. I have a few questions, however:
Which is the best Arduino board to use with PHP? Serial or USB?
What's the best/easiest platform to use with Arduino, Windows or Linux? (I'm familiar with both, so it's of no consequence to me which gets used.)
Do I need to use any additional software or drivers to access Arduino controls with PHP?
The reason this needs to be controlled through the web is that it will be integrated into an existing web application that our employees use. Flash and Java are not options.
Also, is there a command line level program that can run Arduino scripts? If so, wouldn't it be much simpler to use PHP to run a system command that executes a script?
The best board to use depends on the available ports on the computer. The USB version of Arduino looks like a normal serial port to software running on the PC and the firmware on the Arduino.
Again, the best easiest platform depends on the programmer. IMO, windows makes it a pain to get access to hardware ports from within a program, but a windows programmer would disagree with me.
Additional software depends what you're trying to do. If you have PHP running on a remote web server, you'll need to write a local program that reads the remote page and prints commands to the serial port (I've done this using a simple batch file and wget -- interfacing PHP to a PIC chip). If you're running PHP locally, you shouldn't need anything extra as long as PHP has what it needs to access the serial ports on your platform.
There is a web client example on that page that shows how an arduino can interact with a php script on a web server without the need of an intermediate pc.
Actually, the sole purpose of the machine this will be hosted on is to control relays. So the Arduino board can be directly connected via serial, USB, or what have you. I'll have direct physical access to the machine, and it won't need to be multi-purposed for anything else.
Oracle, you mentioned using a batch file to interact with the Arduino board. How exactly does this work?
Also does anyone know the best class to use with PHP for either Linux or Windows? And which versions of PHP that it is compatible with.
mem, now that I take a closer look at the web client example for the Ethernet shield, this seems like a brilliant idea for some applications, but I'm not sure if it will work for mine. If I understand correctly, the network-enabled Arduino can basically browse a web page and submit simple form data. I think that this can work in my environment, but would the Arduino be capable of bi-directional control?
For example, a request is sent to activate a relay on the Arduino. This relay breaks a circuit that turns a light on. This light is set up with an alarm-type configuration using relays so that until a circuit separate from the activation circuit is closed, the light stays on. The de-activation circuit is controlled on the remote end with a physical switch that someone presses to indicate that they have noticed the light going off. Would the Arduino be able to "read" whether or not the light has been shut off by say, checking for continuity on the de-activation circuit? And then I assume it would have to submit some form data on my web server over the network?
In web client mode, will the Arduino be available over the network, so if for instance the web server wants to find out whether or not the light is on, can it do so? That is, without waiting for the Arduino's refresh period to update the web server on the status of the Arduino?
This is going to be used in an instance where we have workers in a remote room that need to occasionally request assistance from supervisors in another area. Basically, the workers will give a quick detail of their help request using a web page and click submit. This turns the light on in the supervisor's area and the help request information will be displayed on a computer terminal near the light. When the supervisors have acknowledged the request, they turn the light off.
you could use pretty much anything (windows, linux, mac), attach the arduino via usb to a computer and then use the computer to connect to the web. set up a couple of pachube streams checking the light condition of the other end (or switch, or sensor, or whatever) and do what you need to with that info.
If you create a script that echos "turn on that relay" to the arduino com port, then php can call it and the arduino can receive the message and turn on the relay.
Note, you can probably also open the com port as a normal file within php and send commands to the arduino.
Pachuino is intruiquing, but now that I'm aware of the Ethernet shield, I'm very interested in using an Ethernet-attached Arduino. Our climate-controlled server room is close to 50 yards from where the Arduino needs to be. We already have a good network backbone throughout the building.
I guess it would help to restate my main question: Is it possible to use Arduino with an ethernet shield in "web client mode", that is, with the arduino accessing web pages to submit data, and at the same time have it in a "web server mode", of sorts. The arduino needs to update the server on its current status on a predefined polling interval. The arduino also needs to be accessed directly to trip relays.
Do you need to secure the arduino functions from the rest of the network i.e. would it be expensive/disastrous if someone hacked your relays or status info from their home computer? If so then controlling it from a direct serial connection from your web server would allow you to use the PC for a more secure/robust internet connection.
Security isn't important. The network is already well secured with VLANs. This device would be on a VLAN only accessible to servers and special workstations like mine.
Only other (really minor) consideration is the usb to pc connection includes power for the arduino. But with a bunch of relays to control, you might need to think about power distribution a bit more anyway.
Power isn't a concern. While PoE would be cool, it's far from necessary.
I see on the XPort's "about" section that it can make and receive connections like the other ethernet shield.
The biggie for me is, can it do both at the same time? Not literally the same time, but can I program it to serve up a web page that will turn relays on and off, and at the same time make it send requests to an external web server to update that server on it's status? Java applets were mentioned in the "about", are they necessary for operation?
Allthough this pachube seems like a pretty cool thingiemadoey, it also seems like it would be overcomplicating things. Now, I absolutely adore Rube Goldberg as much as the next geek, but the golden rule of enginering is after all: KISS, Keep It Simple, Stupid!
If you are confident in your linux skills, could you not just make a php script that writes directly to a serial port (/dev/ttyUSB0) on the linux box where it is hosted? On windows you have to revert back to Windows 98 or earlier to get direct access to the hardware ports, NT-systems "protect" us poor, stupid users from doing this without drivers etc.
Am I wrong in thinking that Linux allows you to open and write to any device as if it were a file? I remember beeing rather impressed when I ran "tail /dev/mouse0" or somesuch and saw the values sent by moving my mouse fill up the screen. :
If the COM-port device (or usb or whatever Arduino shows up as on Linux) can be handled like a file, all you need is a very, very simple php script and you're home safe!
There are "issues" with remy's php script. And no, the serial ftdi doesn't behave like a file, at least not with with php on Apache although that would be nice if it was that simple.
Having tested Remy's script on osx and XP, its "flaky", XP it didn't work and OSX it worked sometimes. I ended up writing a c++ wrapper for php on OSX, it might be different on Linux it would be interesting to know if anyone has succeeded = )
Are you sure? From what I've seen researching this, you can open the serial device like a file, fread from/fwrite to it like a file.. If course you have no options for setting baud rate, stop-bit, flow control etc. but that can be done with shell commands.
I must say, I would be very surprised if something as basic as serial ports do not work 100% properly in Linux...