Go Down

Topic: PHP / XAMP web server / x10 module (smart home) (Read 1 time) previous topic - next topic


dear all, i made simple interface HTML to control light via light module form X10 ( on / off / dim / bright ) and for fan ( on /off ) but i would like to make it in PHP page with mySQL .

i use arduino uno with Ethernet shield and i want the ardunio take the command form the server XAMPP and to be as client .

my code :

Code: [Select]

  Web Server with X10 Firecracker control
  No need for a app, or a program on the PC, this simple arduino program allows web based html button control of the arduino from any browser, on a PC, IPAD, IPOD, smart phone. 

* Ethernet shield attached to pins 10, 11, 12, 13
*  x10 Firecracker attaches to pins 8 and 9


#include <SPI.h>
#include <Ethernet.h>
#include <X10Firecracker.h>
#include <WString.h>

#define RTS_PIN     8                 // RTS line for C17A - DB9 pin 7
#define DTR_PIN     9                 // DTR line for C17A - DB9 pin 4
#define BIT_DELAY   1                   // mS delay between bits (1 mS OK)

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,178);

String s = String(30); //string for fetching data from address
String cmd = "/X" ; //X is an example of the command that will come after the ethernet address in the GET...

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);

void setup() {
// Open serial communications and wait for port to open:
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  Serial.print("Pgm started  ");

  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  Serial.print("server is at ");


void loop() {
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    boolean DoPage=true;
    while (client.connected()) {
        if (client.available()) {
               char c = client.read();
               if (s.length() < 7) { s.concat(c); }   // build up a short string to parse
               if(s.substring(0,3) == "GET" & DoPage)
               {    // check for the GET from the web page
                     cmd=s.substring(4,6);        // get the 2 letters in the string out and call this the CMD,  /A, or /B or /H etc, these come in after the GET
                     // Serial.println("CMD=");
                     // Got a GET so, compare the received command to the specific command and then do something
                     if (cmd == "/A" && DoPage) {
                                Serial.println(F("Turn on the Light"));     
                                X10.sendCmd( hcA, 1, cmdOn );
                               DoPage = false;
                      if (cmd == "/B" && DoPage) {
                                Serial.println(F(" Light Dim"));
                                X10.sendCmd( hcA, 1, cmdDim );
                               DoPage = false;
                     if (cmd == "/H" && DoPage) {
                                Serial.println(F(" Light Bright"));
                                X10.sendCmd( hcA, 1, cmdBright );
                               DoPage = false;
                     if (cmd == "/C" && DoPage) {
                                Serial.println(F("Turn Off the light"));
                                X10.sendCmd( hcA, 1, cmdOff );
                               DoPage = false;
                     if (cmd == "/M" && DoPage) {
                                Serial.println(F("Turn On the FAN"));     
                                X10.sendCmd( hcA, 2, cmdOn );
                               DoPage = false;
                      if (cmd == "/O" && DoPage) {
                                Serial.println(F("Turn Off the FAN"));
                                X10.sendCmd( hcA, 2, cmdOff );
                               DoPage = false;
              // if you've gotten to the end of the line (received a newline
              // character) and the line is blank, the http request has ended,
              // so you can send a reply
              if (c == '\n' && currentLineIsBlank) {
              // send a standard http response header
                      client.println(F("HTTP/1.1 200 OK"));
                      client.println(F("Content-Type: text/html"));
                      client.println(F("Connnection: close"));
                      client.println(F("<!DOCTYPE HTML>"));
                      client.println(F("<meta content='text/html; charset=ISO-8859-1'http-equiv='content-type'>"));
                      client.println(F("<title>Welcome to Alwafi Arduino Program"));
                      // the next line sets the background color to something nice like blue
                      client.println(F("<body style='background-color: rgb(0, 0, 153); color: rgb(255, 255, 0);'alink='#cc6600' link='#cc0000' vlink='#993300'>"));
                      //  load in a background .jpg for the web page.
                      client.println(F("<BODY BACKGROUND='http://www.aou.edu.kw/images/hand2.JPG' style='width: 481px; height: 690px;'></span><br>"));
                      //  set up some HTML that has buttons with specific actions that link back to the arduino at the address of the arduino and have a specific string
                      client.println(F("<FORM METHOD='LINK' ACTION='\r'><INPUT TYPE='submit' VALUE='Turn on the Light'></FORM>  "));                 
                      client.println(F("<FORM METHOD='LINK' ACTION='\r'><INPUT TYPE='submit' VALUE='Turn Off the light'></FORM>  "));
                      client.println(F("<FORM METHOD='LINK' ACTION='\r'><INPUT TYPE='submit' VALUE='dim light'></FORM>  "));
                      client.println(F("<FORM METHOD='LINK' ACTION='\r'><INPUT TYPE='submit' VALUE='Bright the light'></FORM>  "));
                      client.println(F("<FORM METHOD='LINK' ACTION='\r'><INPUT TYPE='submit' VALUE='Turn On the FAN'></FORM>  "));
                      client.println(F("<FORM METHOD='LINK' ACTION='\r'><INPUT TYPE='submit' VALUE='Turn Off the FAN'></FORM>  "));         
                      // Clear out the received string
                if (c == '\n') {
                      currentLineIsBlank = true;
                else if (c != '\r') {
                      currentLineIsBlank = false;
    Serial.println("client disonnected");
}  // end


need your help to make my interface for controlling the device (PHP page) rather than simple HTML in the ardunio ??

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131