Pushing data from Xbee to Arduino to ESP8266

Hello, guys! Since i got my ESP8266-Arduino running, what i need to do now is to send the incoming data from xbee to the internet via this wifi module. can someone help me? I tried reading the data from the xbee and put it as input to be sent by ESP8266. Here’s my code:

#include <SoftwareSerial.h>
String ssid = “Qtpi”;
String password = “chocomallowpie”;

SoftwareSerial esp(10, 11);// RX, TX
SoftwareSerial XBee(17, 16);//RX, TX

String data;
String server = “34.211.192.31”; // www.example.com
String uri = “test.php”;// our example is /esppost.php
String sens1 , sens2;
String datasens1;

void setup() {

XBee.begin(9600);
esp.begin(9600);
Serial.begin(9600);
reset();
connectWifi();

}

//reset the esp8266 module

void reset() {

esp.println(“AT+RST”);
delay(1000);
if (esp.find(“OK”) ) Serial.println(“Module Reset”);

}

//connect to your wifi network

void connectWifi() {

String cmd = “AT+CWJAP=”" + ssid + “”,"" + password + “”";
esp.println(cmd);
delay(4000);
if (esp.find(“OK”)) {
Serial.println(“Connected!”);

}

else {

connectWifi();

Serial.println(“Cannot connect to wifi”);
}

}

void loop () {

// convert the bit data to string form
if (XBee.available()) {
Serial.write(XBee.read());
}
datasens1 = XBee.read();
sens1 = datasens1 ;

data = “waterlvl=” + sens1;// data sent must be under this form //name1=value1&name2=value2.

httppost();

delay(1000);

}

void httppost () {

esp.println(“AT+CIPSTART=“TCP”,”" + server + “”,80");//start a TCP connection.

if ( esp.find(“OK”)) {

Serial.println(“TCP connection ready”);

} delay(1000);

String postRequest =

“POST " + uri + " HTTP/1.0\r\n” +

"Host: " + server + “\r\n” +

“Accept: " + “/” + "\r\n” +

"Content-Length: " + data.length() + “\r\n” +

“Content-Type: application/x-www-form-urlencoded\r\n” +

“\r\n” + data;

String sendCmd = “AT+CIPSEND=”;//determine the number of caracters to be sent.

esp.print(sendCmd);

esp.println(postRequest.length() );

delay(500);

if (esp.find(">")) {
Serial.println(“Sending…”); esp.print(postRequest);

if ( esp.find(“SEND OK”)) {
Serial.println(“Packet sent”);

while (esp.available()) {

String sensdata1 = esp.readString();

Serial.println(sensdata1);
}

// close the connection

esp.println(“AT+CIPCLOSE”);

}

}
}

I tried reading the data from the xbee and put it as input to be sent by ESP8266.

And what happens when you run the code? Does the Arduino receive the data? Does the ESP connect?

What is the role of the Arduino? And which Arduino?

groundFungus:
And what happens when you run the code? Does the Arduino receive the data? Does the ESP connect?

What is the role of the Arduino? And which Arduino?

this is the result:

TCP connection ready
Sending…
Packet sent

+IPD,485:HTTP/1.1 400 Bad Request
Date: Tue, 18 Jul 2017 16:42:08 GMT
Server: Apache/2.4.7 (Ubuntu)
Content-Length: 304
Connection: close
Content-Type: text/html; charset=iso-8859-1

400 Bad Request

Bad Request

Your browser sent a request that this server could not understand.


Apache/2.4.7 (Ubuntu) Server at 34.211.192.31 Port 80 CLOSED

it says bad request. maybe im wrong with the code. Can anyone help me?