Simple demo(via command)

i use a command to turn led on or off via wifi shield, it is just a simple demo , maybe you have a better one.

#include "Wifly.h"
#include <SoftwareSerial.h>
WiflyClass Wifly(2,3);


void setup()
{
  Serial.begin(9600);
  pinMode(8, OUTPUT);                    //the pin of your led
  Wifly.init();
  Wifly.setConfig("SSID","password"); //you need input SSID and password
  Wifly.join("SSID");                        //you need input SSID
  while(!Wifly.connect("Your IP address","90"));  //input IP address
  Wifly.writeToSocket("Connected!");
}

char dtaSocket[10];   //the max leng of command
int dtaLen = 0;           //actual leng of command
unsigned char getDta = 0;

unsigned char judge(char *str1, char *str2, int n)  //discriminant function
{
    for(int i = 0; i<n; i++)
    {
        if(str1[i] != str2[i])
        {
            return 0;
        }
    }
    return 1;
}
void loop()
{
  if(Wifly.canReadFromSocket())
  {
    dtaSocket[dtaLen++] = Wifly.readFromSocket();  
    if(dtaSocket[dtaLen-1]=='\n') 
    {
        getDta = 1;
    }
    if(dtaLen > 8)
    {
        getDta = 0;
        dtaLen = 0;
    }
    
  } 
  
  if(getDta)
  {
      getDta = 0;
     if(judge(dtaSocket, "on", 2) && dtaLen == 4)  //turn led on when you input "on"
     {
         //Serial.print("led on:\t");
         //Serial.println(dtaLen);
         digitalWrite(8, HIGH);
     }
     else if(judge(dtaSocket, "off", 3) && dtaLen == 5)  //turn led off when you input "off"
     {
         //Serial.print("led off:\t");
         //Serial.println(dtaLen);
         digitalWrite(8, LOW);
     }
     else 
     {
         //Serial.println("unavailable command");   //only two command is available,others are not
         digitalWrite(8,LOW);
     }
      dtaLen = 0;
  }
  
/*  while(Serial.available())
  {
    Wifly.print((char)Serial.read());
  }
*/
}

If you have some demo about wifi shield , show it with us , could you?
WifiShield.rar (4.38 KB)

Maybe you can have a try.

#include "RGBdriver.h"
#define CLK 2//pins definitions for the driver        
#define DIO 3
#include <SoftwareSerial.h>
RGBdriver Driver(CLK,DIO);

void setup()
{
Serial.begin(9600);
}

char dtaSocket[10];   //the max leng of command
int dtaLen = 0;           //actual leng of command
unsigned char getDta = 0;

unsigned char judge(char *str1, char *str2, int n)  //discriminant function
{
    for(int i = 0; i<n; i++)
    {
        if(str1[i] != str2[i])
        {
            return 0;
        }
    }
    return 1;
}

void loop()
{
  if(Serial.available())
  {
    dtaSocket[dtaLen++] = Serial.read(); 
    if(dtaSocket[dtaLen-1]=='\n')
    {
        getDta = 1;
    }
    if(dtaLen > 8)
    {
        getDta = 0;
        dtaLen = 0;
    }
   
  } 

 if(getDta)
  {
      getDta = 0;
     if(judge(dtaSocket, "Blue", 1) && dtaLen == 5)  //turn Blue led on when you input "Blue"
     {
         Serial.println("Blue:\t");
         Driver.begin(); // begin
         Driver.SetColor(0, 0, 255);//Blue. first node data
         Driver.end();
         delay(500);
     }
     else if(judge(dtaSocket, "Red", 1) && dtaLen == 4)  //turn Red led off when you input "Red"
     {
         Serial.println("Red:\t");
         Driver.begin(); // begin
         Driver.SetColor(255, 0, 0); //Red. first node data
         Driver.end();
         delay(500);
     }
     else if(judge(dtaSocket, "Green", 1) && dtaLen == 6) //turn Green led off when you input "Green"
    {
         Serial.println("Green:\t");
         Driver.begin(); // begin
         Driver.SetColor(0, 255, 0); //Green. first node data
         Driver.end();
         delay(500);
        
     }
      else
      {
      Serial.println("unavailable command");//others command are unavailable
      }
      dtaLen = 0;
}
}

this is what i did
and it works for me.
can u show me how to do this using http

#include <Wifly.h>

#include <SoftwareSerial.h>

WiflyClass Wifly(2,3);

int LedPin = 5;

void setup()

{
pinMode(LedPin, OUTPUT);
Serial.begin(9600);

Wifly.init();

Wifly.setConfig(“ac_wi”,“password”); //the Ethernet information

Wifly.join(“ac_wi”);

Wifly.checkAssociated();

while(!Wifly.connect(“192.168.43.218”,“8080”)); //remote server address and port number

Wifly.writeToSocket(“Connected!”);

}

void loop()

{
//if(Wifly.canReadFromSocket()) //check if any message sent from the server
//{
//Wifly.readFromSocket(); //print message sent from the server on SSCOM
if(Wifly.readFromSocket()== ‘1’) //set a key word to collect sensor value
{
digitalWrite(LedPin, HIGH);
//Wifly.print(digitalRead(tiltswitch)+48); //get the sensor value printed by “+48″,
//changeing int into char format
}
else if(Wifly.readFromSocket()== ‘2’)
{
digitalWrite(LedPin, LOW);
}
//}

if(Serial.available())

{

Wifly.print((char)Serial.read()); // print message sent from SSCOM

//on the screen of the server

}

}

Hi,your code have some bugs.such as: “1” or “12” or “123” both can turn led on,etc.

And you can control LED via TCP,it is the same to http.

you are saying that i can use the same code for http???
what are the changes that i will have to do in my code for http
how do i send “1” from my web server.
the get command is for posting data right?!

No, i mean they are the same function,but via different ways.
But you can use TCP to control led via wireless instead of http,now we have not a demo for http.