Lets say I have constructed a grid of LEDs. the LEDs and be controlled via commands send to the serial port. On my website I have a graphical mock-up of this grid which users can click on. Their clicks will turn off or turn on the corresponding real life LED.
Basically, how can I take the user’s action on my webpage, “deliver” it to my computer and have it sent out to the serial port?
Obviously my LED idea is pretty pointless but conceivably it could be replaced with any sort of device one wanted to control via the internet.
Hopefully someone will come along with a handy-dandy circuit for connecting a serial port to a relay (I would prefer USB) – I did a quick search for a USB interface and found some very pricy units.
Anyway, once you have the hardware, the software shouldn’t be an issue. You will have to run a web server of some type on your machine. This could be an MS server or Apache or whatever. You need to be able to run CGI scripts or some other kind of dynamic scripts.
All you need to do is set up a URL that will call your custom CGI script that parses out the LED number from the URL params and then calls the controller program for your serial/usb port widget.
For a different approach, here’s a cool device that has a web server and does ports and such, all by itself with no PC needed. That’s neat.
First start by taking the webserver out of the equation. Write an application in your language of choice to do the serial port control of your LED display. Set it up so you can control the various LEDs in the same way you want the webserver to be able to control them.
Then, once you’ve got a stand-alone application controlling the LEDs, put an interface on that to allow it to be called externally. This could be as simple as making it a command-line executable which took input parameters. On a Win32 box you could put a DLL interface on it so it could be called by another app. On Linux/Unix, you can do the same thing with shared library files.
Next, using your webserver programming language of choice, write server-side code to call your LED control app. This can be any server-side language you choose (Java servlet, PHP, ASP, Perl, etc.) as long as your webserver supports it and it can make the appropriate calls to your LED controller.
Lastly, once you’ve got a server-side script doing what you want, put a nice HTML GUI on it to give the users the choices you want to provide.
All of that is very vague, but you have to make some decisions on languages and architectures before anyone can be more specific. Do you want to use a specific language? A specific webserver and server-side scripting language? Do you have experience with things like COM DLLs or Java RMIs, or would you prefer something simpler like a command-line interface to your controller?
I built one of the circuits from this page http://discolitez.com/circuits.shtml to control incandescent lamps via WinAmp a few years back. I used the triac circuit, but you shouldn’t have any problem modifying even the 32-light circuit to run with LEDs. There’s an SDK for download that should allow for easy integration with your project.
Things like this have actually been done a few times. Here’s one I found quickly via google, but you should be able to find a few more if you look, and some explanations of how they work. http://bastilleweb.techhouse.org/photos-play.html
You can drive a single relay directly off of one of the handshaking lines on the serial port, though the serial port wasn’t designed to work this way. The RS-232 signals only supply 20 mA, so you’ll need a drive transistor. You’ll want to reverse bias the relay with a snubbing diode as well.
If you want to drive multiple relays, or a bunch of LEDs, probably the easiest thing would be to use a microcontroller. PICs are popular, and you can buy one with a serial port built in. You can also get 8051’s and numerous other micros with the serial port built in. The I/O lines on the micro might not be able to drive the relay directly, so again you’d need a drive transistor (and a snubber diode).
For USB, replace the microcontroller above with one that has a USB port. I know you can get them in 8051 versions and PICs, and I’m sure it’s available for other micros as well. I just checked digikeys web site, and a PIC 16C745 will set you back all of about 5 bucks.
The electrical portion of the project isn’t the problem; I know how to do that stuff.
It’s how to “downmix” the user-website interaction into the serial port signal in real time.
Just out of curiosity… what is supposed to happen if two people click on the same light in their web page at the same time? Or other situations in which two people at the same website might enter conflicting orders??
You need to keep in mind that the web is by its nature a multiuser environment with some weird contraints. For instance, there’s no clearly defined limit on how long any user can keep a page open and then submit a command based on it. For instance:
Users A and B surf to the same site at the same time and get the readout of current status.
User A clicks cell 24 on and gets the corresponding update back, (along with some unrelated change that user C has been making, perhaps.)
User B then clicks cell 24 on, because he didn’t see that user A already did that. At the same time, user B is clicking cell 24 off. :]
The only way I know how to do it is with CGI stuff (which was already mentioned) but I’m no hard core web programmer either. If you search for CGI programming info you’ll find plenty of examples on how to get information from a web page into your own c program, and from there it’s pretty trivial to send data out the serial port.
I’m sure a hard core web programmer will come along shortly and show you a better way to do it.
I realize that… on the other hand, my point was, I think, relevant to the whole class. You’re talking about a web interface to control a simple electronic device in the real world. Given that the device in the real world is singular, and that the web is by nature multiuser, there’s always the possibility of conflicting commands.
Now, if you set up a login system for the control interface so that only one person can be logged in and ‘in control’ at a time, then that’s an answer. But the question is relevant, darnit!! :]
I’ve done a lot of web programming myself, mostly through ASP and similar ISAPI techniques that tend to isolate the web server processes from the peripherals attached to the computer, mostly for that very reason of conflicting requests. (Web sites in general are built for scalability, the notion of having as many surfers on the site with as few conflicts as possible.)
Definitely relevant, but also easy to handle. I’ve seen a lot of sites that use a first-come-first-served login system with a timeout. That is, you log in and get in a queue, and when the current user times out, the next one in the queue gains control. If that user doesn’t respond in a few seconds, they get bumped and the queue moves again. I’ve seen a couple of sites like this that used a Java applet for the client-side controls, both to provide a rich GUI client and to make sure you had the client-server feedback mechanism to run the queue promptly. However, you could just as easily do it with a plain HTML client as long as you provide a way for the user to refresh their info on the queue status.
You could also just write a client-side app that ran completely separate from the browser but used HTTP to communicate with your website. Since the OP already has skills in VB and C++, this might be the easiest way. Building on the separation of tasks I mentioned in my first reply, you could build a standalone app to run the LEDs which consisted of a user interface controller and an underlying LED controller. Then you just need to put an HTTP communication link in between to make it web-enabled.
CGI is not the only way to run the server side. Almost any server-side code would work (e.g. CGI, PHP, ASP, Java servlet, etc.). Even some of the low-function server-side systems like Cold Fusion probably provide enough access to the underlying OS that you could run an interface on a command-line app or DLL. You could even build your HTTP listener into your LED controller app and set it to listen on a different port than your regular website. This isolates the functions and might make it easier to debug the server-side code, but it means re-inventing the wheel a bit unless you just embed an existing HTTP server component in your code.