Receive Data XBee and Transmit It Back

hi, i want to transmit data in multi-hop way. i have 3 node. between node 1 and 2 communication using radio frequency XBee and between node 2 and 3 communication using wifi.
so here’s my ‘topology’:
(node1) (node 2) (node 3)
Arduino+XBee=====(RF)=====Arduino+Arduino Wifi Shield+XBee====(WiFi)=====PC

in node 2, i run this program and no error, but i’ve got problem in client.print() there just receive data from node 1 per character, not all character. the data that i send from node 1 is random character number from analog pin. so, how to capture all this character and put them to database?

here’s my node2 code:

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

SoftwareSerial mySerial(2, 3);

char ssid[] = "AccessPoint";     // your network password
int keyIndex = 0;                 // your network key Index number (needed only for WEP)
int sensor;
int status = WL_IDLE_STATUS;
   
WiFiServer server(80);
void setup() {
 
  Serial.begin(9600); 
  mySerial.begin(9600);
  setTime(1385759040);
  while (!Serial) {
  }

  if (WiFi.status() == WL_NO_SHIELD) {
  Serial.println("WiFi shield not present"); 
  while(true);
  } 

  while ( status != WL_CONNECTED) { 
  Serial.print("Attempting to connect to SSID: ");
  Serial.println(ssid);
  status = WiFi.begin(ssid);
  delay(10000);
  } 
  server.begin();
  printWifiStatus();
}

void loop() {
  WiFiClient client = server.available();
  if (mySerial.available()) {  
  sensor = mySerial.read();
  Serial.write(sensor);
  }
  
  if (client) {
    Serial.println("new client");
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
         if (c == '\n' && currentLineIsBlank) {
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connnection: close");
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          client.println("<meta http-equiv=\"refresh\" content=\"5\">");
          client.println("<head>");
          client.println("<script>");

          client.println("function showUser()");
          client.println("{");
          client.println("var x=document.getElementById(\"myHeader\");");
          client.println("var y=document.getElementById(\"myHeader2\");");
          client.println("strX=x.innerHTML");
          client.println("strY=y.innerHTML");
          client.println("if (strX==\"\")");
          client.println("{");
          client.println("document.getElementById(\"txtHint\").innerHTML=\"\";");
          client.println("return;");
          client.println("} ");
          client.println("if (window.XMLHttpRequest)");
          client.println("{");
          client.println("xmlhttp=new XMLHttpRequest();");
          client.println("}");
          client.println("else");
          client.println("{");
          client.println("xmlhttp=new ActiveXObject(\"Microsoft.XMLHTTP\");");
          client.println("}");
          client.println("xmlhttp.open(\"GET\",\"http://localhost/arduino/inputSensor.php?p=\"+strX+\"&q=\"+strY,true);");
          client.println("xmlhttp.send();");
          client.println("}");
          client.println("</script>");
          client.println("</head>");
          client.println("<body onload=\"showUser()\">");
          
          client.print("<h2> Time : </h2>");
          client.print("<h2 id=\"myHeader\" > ");        
          String time = getDigitalClock();
          client.println(time);
          client.println("</h2>");     

          client.print("<h2> Sensor : </h2>");
          client.println("<h2 id=\"myHeader2\">");
          client.print(sensor); //the error was here
          client.println("</h2>");
  
          client.println("</body>");
          client.println("</html>");
          break;
        }
        if (c == '\n') {
          currentLineIsBlank = true;
        } 
        else if (c != '\r') {
          currentLineIsBlank = false;
        }
      }
    }
    delay(1);

   client.stop();
   Serial.println("client disconnected");
  }
  
}


String getDigitalClock(){
  String data = "";
  data+=year();
  data+="-";
  data+=month();
  data+="-";
  data+=day();
  data+=" ";
  data+=hour();
  data+=printDigits(minute());
  data+=printDigits(second());
  return data;
}

String printDigits(int digits){
  String buff = ":";
  if(digits < 10)
  buff+='0';
  buff+=digits;
  return buff;
}


void printWifiStatus() {
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

but i've got problem in client.print() there just receive data from node 1 per character, not all character.

Because that is the way that you wrote the code. You need to have the sender send some kind of end-of-packet marker, and then read and store all the data until the end of packet marker arrives.

Then, you need to copy the data stored, so that when a client connects, you can supply the last complete packet, not a partial packet that is currently being received.

PaulS:

but i've got problem in client.print() there just receive data from node 1 per character, not all character.

Because that is the way that you wrote the code. You need to have the sender send some kind of end-of-packet marker, and then read and store all the data until the end of packet marker arrives.

Then, you need to copy the data stored, so that when a client connects, you can supply the last complete packet, not a partial packet that is currently being received.

thx for quick reply paul. actually the data that i sending is a real time. the data receive every 5 seconds. the web browser refresh it and then get into database. i have successfully receive data and then get them into database, but the receive data just one character

actually the data that i sending is a real time. the data receive every 5 seconds.

Every 5 seconds is not real-time.

the web browser refresh it and then get into database.

A browser can not store data in a database, unless you have written a custom browser.

but the receive data just one character

Because that is all you read.

Every 5 seconds is not real-time.

the point is i want to send them in every 5 second for sure

A browser can not store data in a database, unless you have written a custom browser.

i mean when im refresh the web browser, the data show up in web browser and that data get into database. i am using xampp, and i have write php file to store data in mySQL.

Because that is all you read.

so how i read all character one by one data? is that not working with mySerial.read()?

big regards

so how i read all character one by one data? is that not working with mySerial.read()?

You should look at the reference page. The read() method returns one character. If you want to read more than one character, you have to do that in a loop. Typically, it's a while loop that ends when there is no more data to read.

But, before you race off to add a while loop to your code, consider that data trickles in slowly from the serial port (hardware or software doesn't matter). The loop() function might be called a million times before a complete packet arrives.

You need to make sure that the sender sends something that defines when a packet is complete, and you need to read and store all data that arrives, until the end of the packet arrives. Only when that happens can you send the packet contents to the client.