I am working on a project involving bluetooth and wifi communications. Both of them are wired up to the Arduino and communicate to it using two software serial port. The scenario is the one in the picture attached.
What I am doing is:
- retrieve the sensor value
- send it from the BT slave module to the master one (wired up to Arduino)
- take it and send it, using AT commands, through the WIFI channel (the WIFI module is a ESP8266-01) to a web server.
The problem is that if I start listening to the BT serial port (BTSerial.listen()) I am not able to properly send the sensor values through the WIFI connection. But if I comment out the lines related to the BT sotware serial, and try to send fixed value to the web server, the sending terminates succesfully.
In my opinion there are some problems with the BTSerial.listen() and WIFISerial.listen() calls, since they are not able to switch from one the the other correctly.
I saw the TwoSerialPort example provided into the Arduino IDE and I tried to apply it into my code but it still not works to me.
Does anyone have a idea which would be the problem? Does anyone already faced with this problem or a similar one?
Hoping to be as much clear as possible, thanks in advance to anyone would help me.
Filippo
[EDIT] Added two code snippets
// This method prepares the AT commands will be send to the ESP8266-01 module in order to upload the values on the web server
void send2server(String ip, int port, String file, int t, int h, int p) {
String queryString = "temp=";
queryString.concat(t);
queryString.concat("&hum=");
queryString.concat(h);
queryString.concat("&press=");
queryString.concat(p);
Serial.println(queryString);
// Prepare and exec the AT+CIPSTART command provideing the TCP connection init
String CIPSTART_cmd = "AT+CIPSTART=\"TCP\",\"" + ip + "\"," + port + "";
exec_cmd(CIPSTART_cmd, 1000);
// Prepare the POST request
String httpPOST_cmd = "POST /";
httpPOST_cmd.concat(file);
httpPOST_cmd.concat(" HTTP/1.1\r\n");
httpPOST_cmd.concat("Host: ");
httpPOST_cmd.concat(ip);
httpPOST_cmd.concat("\r\n");
//httpPOST_cmd.concat("Accept: */*\r\n");
httpPOST_cmd.concat("Content-Length: ");
httpPOST_cmd.concat(queryString.length());
httpPOST_cmd.concat("\r\n\r\n");
//httpPOST_cmd.concat("Content-Type: text/html\r\n\r\n");
httpPOST_cmd.concat(queryString);
// Calculate the POST request length
unsigned int len = httpPOST_cmd.length();
// Prepare and exec the AT+CIPSEND statement with the POST request length just calculated
String CIPSEND_cmd = "AT+CIPSEND=";
CIPSEND_cmd.concat(len);
exec_cmd(CIPSEND_cmd, 1000);
// Exec the HTTP POST request
exec_cmd(httpPOST_cmd, 1000);
// Close the connection
exec_cmd("AT+CIPCLOSE", 1000);
}
// This method execute each AT command in the previuous method
void exec_cmd(String cmd, int delayTime) {
byte i = 0;
while(1) {
Serial.println("invio comando");
WIFISerial.println(cmd);
while(WIFISerial.available()) {
if(WIFISerial.find("OK")) {
i = 8;
}
}
delay(delayTime);
if(i > 5)
break;
i++;
}
if(i == 8) {
Serial.println("OK");
//return true;
} else {
Serial.println("ERRORE");
//return false;
}
}
The problem is the code goes properly till the AT+CIPSEND command, then the POST request is sent but no good feedback arrives, ending with the "ERRORE" error message.
[EDIT 2] Attached serial monitor output
This is the serial monitor output when I execute the skecth. It seems to work properly but it does not upload any value.