arduino wifly led controll

Hello evryone i need some help with code i want to make that after i press the button on web page arduno will recevie signal to turn on led which connected to pin 2 wifly connects to wireless network i getting page on with the button but when i press it wifly shield red led indicates that its reciving communication but i cant turn the ligth on
my HTML part of code is

void loop()
{
 
  // Exit command mode if we haven't already
  SPI_Uart_println("exit");
  delay(500);
  Flush_RX();

    while(!Have_Client()); // Wait on client
    Serial.println("\n\rConnection opened.");

    // Send HTML
    HTML_print("<html>");
    HTML_print("<title>Led Control</title>");
    HTML_print("<h1><center>");
    HTML_print("LED CONTROLL");                                
    HTML_print("</center></h1>");
    HTML_print("PUSH THE BUTTON");
    HTML_print("<form type=\"submit\" action=\"\" method=\"post\">");
 //    HTML_print("<input type=\"hidden\" name=\"%\" value=\"1\">");
    HTML_print("<input type=\"submit\" value=\"%\" method=\"post\">");
    HTML_print("</form>");
  HTML_print("<h3>NOTHING HAPPENED LOL :)</h3><p>");
    HTML_print("</html>");
    delay(500);

    // Enter command mode and close connection
    SPI_Uart_print("$$");
    delay(500);
    SPI_Uart_println("close");
    delay(1000);
    SPI_Uart_println("exit");
    delay(500);
    Serial.println("Connection closed.\n\r");
    Flush_RX();
  }

and Parse_Request(void) is

void Parse_Request(void)

{
int val=0, i = 0;
int readval;
  char printflag = 0;
val =  SPI_Uart_ReadByte(RHR);  
        if((SPI_Uart_ReadByte(LSR) & 0x01))
         {
           incoming_data = SPI_Uart_ReadByte(RHR);
           if(printflag){
           val = val;
           i++;
           }
           else if (incoming_data == '%'){
           printflag = 1;
           }
           if (printflag = 1 ){
             digitalWrite(val,LOW); 
            }
            else
            {
             digitalWrite(val,HIGH);    //??????
             }
         }
          

}

this one supose to send data to arduino

i am using sparkfun tutorial WiFly Wireless Talking SpeakJet Server

and 10 led bar code to control it with c# application

i am just a beginer at programing so need some help with this one

Thank you.

anyone?

ok now LED turns on when i connecting to web page but not when i press button on it

still waiting for some help

So far my progress …
Led turns on after i enter page but do nothing when i press the button on it
still hope someone can help me better to understand this so it woud work as is shoud be

void loop()
{
 
  // Exit command mode if we haven't already
  SPI_Uart_println("exit");
  delay(500);
  Flush_RX();

    while(!Have_Client()); // Wait on client
    Serial.println("\n\rConnection opened.");

    // Send HTML
    HTML_print("<html>");
    HTML_print("<title>Led Control</title>");
    HTML_print("<h1><center>");
    HTML_print("LED CONTROLL");                                
    HTML_print("</center></h1>");
    HTML_print("PUSH THE BUTTON");
    HTML_print("<form name=\"%\" action=\"/\" method=\"POST\">");
    HTML_print("<input type=hidden name=\"%\" value=0>");
    HTML_print("<input type=\"submit\" value=\"OFF\">");
 //   HTML_print("<form name=\"%\" action=\"/\" method=\"POST\">");
 //   HTML_print("<input type=hidden name=\"%\" value=\"0\" />");
 // HTML_print("<input type=\"hidden\" name=\"%\" value=\"1\">");
 // HTML_print("<input type=\"submit\" name=\"%\" value=\"0\" />");
    HTML_print("</form>");
    HTML_print("<h3>NOTHING HAPPENED LOL :)</h3><p>");
    HTML_print("</html>");
    delay(500);

    // Enter command mode and close connection
    SPI_Uart_print("$$");
    delay(500);
    SPI_Uart_println("close");
    delay(1000);
    SPI_Uart_println("exit");
    delay(500);
    Serial.println("Connection closed.\n\r");
    Flush_RX();
  }

Parse request void

void Parse_Request(void)
// Parse POST data 
{
int val = 0, i = 0;
int readval;
//  char printflag = 0;
val =  SPI_Uart_ReadByte(RHR);  
        if((SPI_Uart_ReadByte(LSR) & 0x01))
         {
           incoming_data = SPI_Uart_ReadByte(RHR);
 if (incoming_data == '%'){
           val = 1;
           }
           if (val = 1 ){
             digitalWrite(led,HIGH); 
            }
            else
            {
             digitalWrite(led,LOW);    //??????
             }
         }
          

}

have client void

char Have_Client(void)
// Wait until we receive data (client request)
{
  if(SPI_Uart_ReadByte(LSR) & 0x01){ 
    Serial.println("Client request..."); 
//    is_get = 1;
    Parse_Request(); // Check if request is a POST
    Flush_RX();
    return 1; 
  }   
  else{ 
    return 0; 
  } 
}

You could change in 'Parse request void':

if (val = 1 ){

to

if (val == 1 ){

and see what happens.

Hallo NightTux thank you for you replay i just tryed it and it do not light up anymore not even i enter web page or trying to puss the button :(

i think its somthing to do with html code

Why are you using ‘%’ as the same name both on the form and the hidden value?
Does ‘%’ do anything special in here, if not I had to name it with some chars instead.
And action="" , shouldn’t that be the path to your script ‘Parse request void’ , or is it in same file? If so I thnk you could remove action="/".

I have never do anything with html on arduino, but have programmed some with html and php on linux.

Hello again i just done some reading and no my loop coid is like that

void loop()
{
 
  // Exit command mode if we haven't already
  SPI_Uart_println("exit");
  delay(500);
  Flush_RX();

    while(!Have_Client()); // Wait on client
    Serial.println("\n\rConnection opened.");

    // Send HTML
    HTML_print("<html>");
    HTML_print("<title>Led Control</title>");
    HTML_print("<h1><center>");
    HTML_print("LED CONTROLL");                                
    HTML_print("</center></h1>");
    HTML_print("PUSH THE BUTTON");
    HTML_print("<form method=\"POST\" name=\"LED\" >");
    HTML_print("<input type=\"submit\" name=\"LED\" value=\"ON\"></form>");
    HTML_print("<form method=\"POST\" name=\"LED\" >");
    HTML_print("<input type=\"submit\" name=\"LED\" value=\"OFF\"></form>");
    HTML_print("<h3>NOTHING HAPPENED LOL :)</h3><p>");
    HTML_print("</html>");
    delay(500);

    // Enter command mode and close connection
    SPI_Uart_print("$$");
    delay(500);
    SPI_Uart_println("close");
    delay(1000);
    SPI_Uart_println("exit");
    delay(500);
    Serial.println("Connection closed.\n\r");
    Flush_RX();
  }

done some testing and its sends ‘LED=ON’ and ‘LED=OFF’ but i thing is SPI UART which i cant understand how to get data from him
my full code is:

#include <string.h>
#include <SoftwareSerial.h>
//#include <avr/pgmspace.h>
boolean led = 0;

// SC16IS750 Register Definitions
#define THR        0x00 << 3 // Transmit Holding Register (THR)
#define RHR        0x00 << 3 // Receive Holding Register (RHR)
#define IER        0x01 << 3 // Interrupt Enable Register (IER)
#define FCR        0x02 << 3 // FIFO Control Register (FCR)
#define IIR        0x02 << 3 // Interrupt Identification Register (IIR)
#define LCR        0x03 << 3 // Line Control Register (LCR)
#define MCR        0x04 << 3 // Modem Control Register (MCR)
#define LSR        0x05 << 3 // Line Status Register (LSR)
#define MSR        0x06 << 3 // Modem Status Register (MSR)
#define SPR        0x07 << 3 // Scratchpad Register (SPR)
#define TXFIFO     0x08 << 3 // 
#define RXFIFO     0x09 << 3 //
#define DLAB       0x80 << 3 //
#define IODIR      0x0A << 3 // I/O pin Direction Register
#define IOSTATE    0x0B << 3 // I/O pin States Register
#define IOINTMSK   0x0C << 3 // 
#define IOCTRL     0x0E << 3 // I/O pins Control Register
#define EFCR       0x0F << 3 // Extra Features Register

#define DLL        0x00 << 3 // divisor latch LSB (DLL)[4]
#define DLM        0x01 << 3 // divisor latch MSB (DLH)[4]
#define EFR        0x02 << 3 // Enhanced Feature Register (EFR)[5]
#define XON1       0x04 << 3 //   Xon1 word[5]
#define XON2       0x05 << 3 // Xon2 word
#define XOFF1      0x06 << 3 // Xoff1 word
#define XOFF2      0x07 << 3 // Xoff2 word

// SPI pin definitions
#define CS         10  //Slave Select pin - allocated on each device which the master can use to enable and disable specific devices and avoid false transmissions due to line noise. 
#define MOSI       11  //Master Out Slave In (MOSI) - The Master line for sending data to the peripherals
#define MISO       12  //Master In Slave Out (MISO) - The Slave line for sending data to the master, 
#define SCK        13  //Serial Clock (SCK) - The clock pulses which synchronize data transmission generated by the master, and 

#define ASSOCIATE_TIMEOUT 5000

//char is_get = 1;

// Global variables
char incoming_data; 
char TX_Fifo_Address = THR; 

int i = 0;
int j = 0;
int k = 0;
char clr = 0;
char polling = 0;
// SC16IS750 communication parameters
struct SPI_UART_cfg
{
  char DivL,DivM,DataFormat,Flow;
};

struct SPI_UART_cfg SPI_Uart_config = {
  0x50,0x00,0x03,0x10};

// Wifi parameters
char auth_level[] = "1";
char auth_phrase[] = "";
char port_listen[] = "80";
char ssid[] = "3Com";

//LED SETUP

#define led 2

void setup()
{
  // SPI pin initialization
  pinMode(MOSI, OUTPUT);
  pinMode(MISO, INPUT);
  pinMode(SCK,OUTPUT);
  pinMode(CS,OUTPUT);
  digitalWrite(CS,HIGH); //disable device 
 #define led 2
  SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR1)|(1<<SPR0);
  clr=SPSR;
  clr=SPDR;
  delay(10); 

  Serial.begin(9600);
      pinMode(2,OUTPUT);
  digitalWrite(led, HIGH);
  delay(1000);
  digitalWrite(led, LOW);
  delay(1000);
  Serial.println("\n\r\n\rWiFly Shield Terminal Routine");
  if(SPI_Uart_Init()){ // Test SC16IS750 communication
    Serial.println("Bridge initialized successfully!"); 
  }
  else{ 
    Serial.println("Could not initialize bridge, locking up.\n\r"); 
    while(1); 
  }

  autoconnect();
}


void loop()
{
 
  // Exit command mode if we haven't already
  SPI_Uart_println("exit");
  delay(500);
  Flush_RX();

    while(!Have_Client()); // Wait on client
    Serial.println("\n\rConnection opened.");

    // Send HTML
    HTML_print("<html>");
    HTML_print("<title>Led Control</title>");
    HTML_print("<h1><center>");
    HTML_print("LED CONTROLL");                                
    HTML_print("</center></h1>");
    HTML_print("PUSH THE BUTTON");
    HTML_print("<form method=\"POST\" name=\"LED\" >");
    HTML_print("<input type=\"submit\" name=\"LED\" value=\"ON\"></form>");
    HTML_print("<form method=\"POST\" name=\"LED\" >");
    HTML_print("<input type=\"submit\" name=\"LED\" value=\"OFF\"></form>");
    HTML_print("<h3>NOTHING HAPPENED LOL :)</h3><p>");
    HTML_print("</html>");
    delay(500);

    // Enter command mode and close connection
    SPI_Uart_print("$$");
    delay(500);
    SPI_Uart_println("close");
    delay(1000);
    SPI_Uart_println("exit");
    delay(500);
    Serial.println("Connection closed.\n\r");
    Flush_RX();
  } 

void select(void)
{
  digitalWrite(CS,LOW);
}

void deselect(void)
{
  digitalWrite(CS,HIGH);
}

char Have_Client(void)
// Wait until we receive data (client request)
{
  if(SPI_Uart_ReadByte(LSR) & 0x01){ 
    Serial.println("Client request..."); 
//    is_get = 1;
    Parse_Request(); // Check if request is a POST
    Flush_RX();
    return 1; 
  }   
  else{ 
    return 0; 
  } 
}

char SPI_Uart_Init(void)
// Initialize SC16IS750
{
  char data = 0;

  SPI_Uart_WriteByte(LCR,0x80); // 0x80 to program baudrate
  SPI_Uart_WriteByte(DLL,SPI_Uart_config.DivL); //0x50 = 9600 with Xtal = 12.288MHz
  SPI_Uart_WriteByte(DLM,SPI_Uart_config.DivM); 

  SPI_Uart_WriteByte(LCR, 0xBF); // access EFR register
  SPI_Uart_WriteByte(EFR, SPI_Uart_config.Flow); // enable enhanced registers
  SPI_Uart_WriteByte(LCR, SPI_Uart_config.DataFormat); // 8 data bit, 1 stop bit, no parity
  SPI_Uart_WriteByte(FCR, 0x06); // reset TXFIFO, reset RXFIFO, non FIFO mode
  SPI_Uart_WriteByte(FCR, 0x01); // enable FIFO mode

  // Perform read/write test to check if UART is working
  SPI_Uart_WriteByte(SPR,'H');
  data = SPI_Uart_ReadByte(SPR);

  if(data == 'H'){ 
      return 1;
  }
  else{ 
    return 0; 
  }

}

and …

void SPI_Uart_WriteByte(char address, char data)
// Write <data> to SC16IS750 register at <address>
{
  long int length;
  char senddata[2];
  senddata[0] = address;
  senddata[1] = data;

  select();
  length = SPI_Write(senddata, 2);
  deselect();
}

long int SPI_Write(char* srcptr, long int length)
// Write string to SC16IS750
{
  for(long int i = 0; i < length; i++)
  {
    spi_transfer(srcptr[i]);
  }
  return length; 
}

void SPI_Uart_WriteArray(char *data, long int NumBytes)
// Write array to SC16IS750 THR
{
  long int length;
  select();
  length = SPI_Write(&TX_Fifo_Address,1);

  while(NumBytes > 16)
  {
    length = SPI_Write(data,16);
    NumBytes -= 16;
    data += 16;
  }
  length = SPI_Write(data,NumBytes);

  deselect();
}

char SPI_Uart_ReadByte(char address)
// Read from SC16IS750 register at <address>
{
  char data;

  address = (address | 0x80);

  select();
  spi_transfer(address);
  data = spi_transfer(0xFF);
  deselect();
  return data;  
}

char autoconnect(void)
{
  // Exit command mode if we haven't already
  SPI_Uart_println("");  
  SPI_Uart_println("exit");
  delay(500);

  // Enter command mode
  SPI_Uart_print("$$");
  delay(500);

  // Reboot to get device into known state
  Serial.println("Rebooting");
  SPI_Uart_println("reboot");
  delay(3000);

  // Enter command mode
  Serial.println("Entering command mode.");
  SPI_Uart_print("$$");
  delay(500);

  // Set authentication level to <auth_level>
  SPI_Uart_print("set w a ");
  SPI_Uart_println(auth_level); 
  delay(500);
  Serial.print("Set wlan to authorization level ");
  Serial.println(auth_level);

  // Set authentication phrase to <auth_phrase>
  SPI_Uart_print("set w k ");
  SPI_Uart_println(auth_phrase);
  delay(500);
  Serial.print("Set security phrase to ");
  Serial.println(auth_phrase);

  // Set localport to <port_listen>
  SPI_Uart_print("set i l ");
  SPI_Uart_println(port_listen);
  delay(500);
  Serial.print("Set IP localport to ");
  Serial.println(port_listen);

  // Turn off WiFly UART connection indicators
  SPI_Uart_println("set comm remote 0");
  delay(500);
  SPI_Uart_println("set comm open 0");
  delay(500);
  SPI_Uart_println("set comm close 0");
  delay(500);

  // Join wireless network <ssid>
  Serial.print("Joining '");
  Serial.print(ssid);
  Serial.println("'");
  delay(100);
  Flush_RX();
  delay(100);
  SPI_Uart_print("join ");
  SPI_Uart_println(ssid);  
  for(int p = 0; p < 40; p++)
  {
    Serial.print(".");
    delay(ASSOCIATE_TIMEOUT/30);
  }
  Serial.println("");

  Flush_RX();

  // Check for association
  SPI_Uart_println("show c");
  if(Wait_On_Response_Char(13) != '0')
  {
    Serial.print("Failed to associate with '");
    Serial.print(ssid);
    Serial.println("'\n\rRetrying...");
    Flush_RX();
    autoconnect();
  }
  else
  {
    Serial.println("Associated!");
    Flush_RX();
  }
}

void Flush_RX(void)
// Flush characters from SC16IS750
{
  int j = 0;
  while(j < 4000)
  {
    if((SPI_Uart_ReadByte(LSR) & 0x01))
    {
      incoming_data = SPI_Uart_ReadByte(RHR);
    }  
    else
    {
      j++;
    }
  }
}

char Wait_On_Response_Char(char num)
// Wait on char number <num> from a response and return it
{
  i = 1;
  while(1)
  {
    if((SPI_Uart_ReadByte(LSR) & 0x01))
    {
      incoming_data = SPI_Uart_ReadByte(RHR);
      //Serial.print(incoming_data, BYTE);
      if(i == num){ 
        return incoming_data; 
      }
      else{ 
        i++; 
      }
    }  
  }
}

void SPI_Uart_println(char *data)
// Print string <data> to SC16IS750 followed by a carriage return
{
  SPI_Uart_WriteArray(data,strlen(data));
  SPI_Uart_WriteByte(THR, 0x0d);
}

void SPI_Uart_print(char *data)
// Print string <data> to SC16IS750 using strlen instead of hard-coded length
{
  SPI_Uart_WriteArray(data,strlen(data));
}

char spi_transfer(volatile char data)
{
  SPDR = data;                    // Start the transmission
  while (!(SPSR & (1<<SPIF)))     // Wait for the end of the transmission
  {
  };
  return SPDR;                    // return the received byte
}

void HTML_print(char *data)
// Write <data> to THR of SC16IS750 followed by a delay
{
  SPI_Uart_WriteArray(data,strlen(data));
  delay(30);
}

void Parse_Request(void)
// Parse POST data 
{
int val = 0, i = 0;
int readval;  
 incoming_data = SPI_Uart_ReadByte(RHR);
 if (incoming_data == 'LED=ON'){
           val = 1;
           }

if (val = 1 ){
             digitalWrite(led,HIGH);    //??????
             }
         
          

}

SOLVED thaks to http://forum.sparkfun.com/viewtopic.php?f=13&t=21846 and

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1268667217