Help , Wi-Fi Shield - Sending data Randomly !!

I have problem with my system , i’m working on a Home Automation system, I’m using arduino wi-fi shield as a receiver that receive orders from any mobile device (smart phone) , and i put a X-Bee as a sender that send orders to other receiving circuits around the home.

the code is working very good with one smart phone , but the problem is when i send two orders from two different phones in the same moment , the arduino is coming confused and send data randomly

for example ;

i’m using one button to send code (S)
and another button to send code (A)

if i pressed them in the same moment , the one should send (A) now is sending (S) and the one should send (S) now is sending (A).

so, is there any method to clear that register that storing data inside.
or any way to avoid that happening

please help :frowning: :frowning: :frowning:

this is my code ;

#include <SPI.h>
#include <WiFi.h>

// #include <SoftwareSerial.h>

// SoftwareSerial xbee(2,3 ); // RX, TX

//IPAddress ip(192, 168, 0, 177);

char ssid = “My Home”; // your network SSID (name)
char pass = “123456789”; // your network password
int keyIndex = 0; // your network key Index number (needed only for WEP)
char server_IP = “”;

unsigned long test_flag=0;
int i=0;
int status = WL_IDLE_STATUS;
WiFiClient client_IP;
WiFiServer server(80);

void setup() {

pinMode(8, OUTPUT);

// check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD) {
//Serial.println(“WiFi shield not present”);
while(true); // don’t continue

// attempt to connect to Wifi network:
while ( status != WL_CONNECTED) {
////Serial.print("Attempting to connect to Network named: ");
//Serial.println(ssid); // print the network name (SSID);

// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
server.begin(); // start the web server on port 80
printWifiStatus(); // you’re connected now, so print out the status

void loop() {

if(Serial.available() > 0){
byte inChar;
inChar =;
if(inChar == ‘a’){
//Serial.println("\nStarting connection to dnsdynamic…");
// if you get a connection, report back via serial:
if (client_IP.connect(server_IP, 80)) {
//Serial.println(“connected to server”);

// client_IP.println(“GET / HTTP/1.1”);
// client_IP.println(“”);
// client_IP.println(“Connection: close”);
// client_IP.println();

else {
//Serial.println(“connection failed”);
int b = client_IP.available();
while(client_IP.connected() && !client_IP.available()) delay(1); //waits for data
while (client_IP.connected() || client_IP.available()) { //connected or data available
char c =;




WiFiClient client = server.available(); // listen for incoming clients
if (client) { // if you get a client,
//Serial.println(“new client”); // print a message out the serial port
String currentLine = “”; // make a String to hold incoming data from the client
while (client.connected()) { // loop while the client’s connected

if (client.available()) { // if there’s bytes to read from the client,

char c =; // read a byte, then

//Serial.write(c); // print it out the serial monitor
if (c == ‘\n’) { // if the byte is a newline character

// if the current line is blank, you got two newline characters in a row.
// that’s the end of the client HTTP request, so send a response:
if (currentLine.length() == 0) {
//HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
// and a content-type so the client knows what’s coming, then a blank line:
client.println(“HTTP/1.1 200 OK”);

// the content of the HTTP response follows the header:
client.print(“Click <a href=”/Smart">here to chose the Smart control
client.print(“Click <a href=”/Classic”>here to chose the Classic control
client.print(“Click <a href=”/ON”>here to turn Light ON
client.print(“Click <a href=”/OFF”>here to turn Light OFF

// The HTTP response ends with another blank line:

// break out of the while loop:
else { // if you got a newline, then clear currentLine:
currentLine = “”;

else if (c != ‘\r’) { // if you got anything else but a carriage return character,
currentLine += c; // add it to the end of the currentLine


// Circuit No.1 - Living Room

if (currentLine.endsWith(“GET /Smart”)) {



if (currentLine.endsWith(“GET /Classic”)) {



if (currentLine.endsWith(“GET /ON”)) {



if (currentLine.endsWith(“GET /OFF”)) {



// close the connection:
//Serial.println(“client disonnected”);


void printWifiStatus() {
// print the SSID of the network you’re attached to:
//Serial.print("SSID: ");

// print your WiFi shield’s IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");

// print the received signal strength:
// long rssi = WiFi.RSSI();
//Serial.print(“signal strength (RSSI):”);
//Serial.println(" dBm");
// print where to go in a browser:
//Serial.print(“To see this page in action, open a browser to http://”);

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. Using code tags and other important information is explained in the How to use this forum post. Please read it.

Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read.

Please remove unnecessary blank lines from your code before posting to the forum. One or two to separate code into sections is fine but large spaces for no reason just make for more scrolling when we’re trying to read your code.