Serial communication from browser

Hi everybody,

I'm trying to do the following:
I'm using a live chat application. The problem is that I'm not always looking at my monitor. To make sure I don't miss any chats I wanted to activate a flashing lamp when a chat opens.

What I've got now:
Program that talkes with Arduino through serial USB (prossessing on windows Vista), lamp connected to the Arduino through a relay. Chat window in which I can change the code (or implement an iframe if necessary).

What I still need:
A way to send serial commands (ethernet shield isn't an option) from the browser to the Arduino. It's only for 1 PC, so if I have to install software locally, that's possible.
Anybody that can point me in the right direction ?

Attached is the schema of what I'm trying to do.

arduino_brower_lamp.jpg

You'll probably need something like a webserver running on your PC, so you can go to http://localhost/popupmessage.php (or whatever language you want). Then your popupmessage.script can talk to the serial port. You might get all sorts of issues with cross-site scripting blocks and stuff, but I've never tried. There are some PHP classes that can talk to serial ports, I think. Perhaps google it.

Thanks for the tip !
Googling for serial and php gave tons of pages, but finally found something that works :slight_smile:
I used serialcomm.zip from http://missionduke.com/arduino-projects/

Leds flickering with a status update on the LCD: check, next step: connecting it to my relay.

First thought - why handle the stop button on the PC side. Having a physical button attached to the Arduino to handle this seems far simpler and also has the additional benefit of allowing for an amusing button:

That's actually a nice idea :slight_smile:
And true, the coolness factor increases 10-fold.

I currently have the following code:

#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
int ledPin13 = 13;                 // LED connected to digital pin 13
int incomingByte;      // a variable to read incoming serial data into
char* LCDStrings[]={"Incoming chat","Click stop flash","Alarm stopped","Have a good chat"};

void setup() {
  lcd.begin(16, 2);
  lcd.clear();
  pinMode(ledPin13, OUTPUT);      // sets the digital pin as output
  Serial.begin(9600); // initialize serial communication
}

void loop() {
 if (Serial.available() > 0) {
  incomingByte = Serial.read(); // read the oldest byte in the serial buffer

  while (incomingByte == 48) {
    PrintLCD(0);
    digitalWrite(ledPin13, HIGH);   // sets the LED on
    delay(250);
    digitalWrite(ledPin13, LOW);   // sets the LED on
    if (Serial.available() > 0) {
      incomingByte = Serial.read(); // read the oldest byte in the serial buffer
    }
    delay(250);
  } 
  if (incomingByte == 177) {
    digitalWrite(ledPin13, LOW);    // sets the LED off
    PrintLCD(2);
    delay(3000);
    lcd.clear();
  } 
 }
}

int PrintLCD(byte messageid) {
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(LCDStrings[messageid]);
  lcd.setCursor(0, 1);
  lcd.print(LCDStrings[messageid+1]);  
}

Is this ok ? Are there optimalizations possible ?