Arduino to ESP8266 (SoftwareSerial) communication, does not receive full data

Hi, i know that this is Arduino forum, but i hope that many of you have ESP8266, so i would like to ask you. I know that someone can help me. Thank you so much for your help.

Here is the problem:

I have an Arduino Uno and an ESP8266, connected over serial through ESP8266 pin GPIO_2 (which is set as RX over espsoftwareserial) and 11 on Uno (which is set as TX over SoftwareSerial). I am trying to send data in this format:

<0.000000:0.000000:0.000000:0.000000:0.000000:0.000000:24.50:24.50:1.49>

It is < char then number with six floats, separator :, and again… 9 times

I am using:

espsoftwareserial library

Original SoftwareSerial library

Arduino UNO code:

SoftwareSerial ARD_ESP(10, 11); // RX, TX

totalVolume[0] = 0.000000;
totalVolume[1] = 0.000000;
totalVolume[2] = 0.000000;
flowRate[0] = 0.000000;
flowRate[1] = 0.000000;
flowRate[2] = 0.000000;
float temperature_cold_value = 24.50;
float temperature_hot_value = 24.50;
float propane_gas_value = 1.49;

void setup() 
{
   ARD_ESP.begin(57600);
   Serial.begin(9600);
}
void loop()
{
if (millis() - previousMillis_esp_post > 5000 && run_state_metering == 1)
     {          
          ARD_ESP.print("<");
          ARD_ESP.print(totalVolume[0],6);
          ARD_ESP.print(":");
          ARD_ESP.print(totalVolume[1],6);
          ARD_ESP.print(":");
          ARD_ESP.print(totalVolume[2],6);
          ARD_ESP.print(":");
          ARD_ESP.print(flowRate[0],6);
          ARD_ESP.print(":");
          ARD_ESP.print(flowRate[1],6);
          ARD_ESP.print(":");
          ARD_ESP.print(flowRate[2],6);
          ARD_ESP.print(":");
          ARD_ESP.print(temperature_cold_value,2);
          ARD_ESP.print(":");
          ARD_ESP.print(temperature_hot_value,2);
          ARD_ESP.print(":");
          ARD_ESP.print(propane_gas_value,2);       
          ARD_ESP.print(">");

          Serial.print("<");
          Serial.print(totalVolume[0],6);
          Serial.print(":");
          Serial.print(totalVolume[1],6);
          Serial.print(":");
          Serial.print(totalVolume[2],6);
          Serial.print(":");
          Serial.print(flowRate[0],6);
          Serial.print(":");
          Serial.print(flowRate[1],6);
          Serial.print(":");
          Serial.print(flowRate[2],6);
          Serial.print(":");
          Serial.print(temperature_cold_value,2);
          Serial.print(":");
          Serial.print(temperature_hot_value,2); 
          Serial.print(":");
          Serial.print(propane_gas_value,2);     
          Serial.print(">");
          Serial.print("");

          previousMillis_esp_post = millis();
     }

ESP8266 code: (it’s programmed with Arduino IDE)

#include <ESP8266WiFi.h>
#include <SoftwareSerial.h>
#include <string.h>

SoftwareSerial ARD_ESP(2, SW_SERIAL_UNUSED_PIN); 

const byte numChars = 32;
char receivedChars[numChars];
boolean newData = false;

String sensor_1_total_volume;
String sensor_2_total_volume;
String sensor_1_flow_rate;
String sensor_2_flow_rate;
String temperature_cold_value;
String temperature_hot_value;
String propane_butane_gas_value;
String mereni_token = "xxxxx";

void setup() {

  Serial.begin(115200);
  ARD_ESP.begin(57600);
  delay(10);
}

void loop() {

  recvWithStartEndMarkers();
  showNewData();

  sensor_1_total_volume = getValue(receivedChars, ':', 0);
  sensor_2_total_volume = getValue(receivedChars, ':', 1);
  sensor_1_flow_rate = getValue(receivedChars, ':', 2);
  sensor_2_flow_rate = getValue(receivedChars, ':', 3);
  temperature_cold_value = getValue(receivedChars, ':', 4);
  temperature_hot_value = getValue(receivedChars, ':', 5);
  propane_butane_gas_value = getValue(receivedChars, ':', 6);

}

void recvWithStartEndMarkers() {
    static boolean recvInProgress = false;
    static byte ndx = 0;
    char startMarker = '<';
    char endMarker = '>';
    char rc;

    while (ARD_ESP.available() > 0 && newData == false) {
        rc = ARD_ESP.read();

        if (recvInProgress == true) {
            if (rc != endMarker) {
                receivedChars[ndx] = rc;
                ndx++;
                if (ndx >= numChars) {
                    ndx = numChars - 1;
                }
            }
            else {
                receivedChars[ndx] = '\0'; // terminate the string
                recvInProgress = false;
                ndx = 0;
                newData = true;
            }
        }

        else if (rc == startMarker) {
            recvInProgress = true;
        }
    }
}

void showNewData() {
    if (newData == true) {
        Serial.print("This arrived: (unparsed)");
        Serial.println(receivedChars);
        Serial.println("DATA sensors: (parsed)");
        Serial.println(sensor_1_total_volume);
        Serial.println(sensor_2_total_volume);
        Serial.println(sensor_1_flow_rate);
        Serial.println(sensor_2_flow_rate);
        Serial.println(temperature_cold_value);
        Serial.println(temperature_hot_value);
        Serial.println(propane_butane_gas_value);
        Serial.println(mereni_token);
        newData = false;
    }
}

String getValue(String data, char separator, int index)
{
    int found = 0;
    int strIndex[] = { 0, -1 };
    int maxIndex = data.length() - 1;

    for (int i = 0; i <= maxIndex && found <= index; i++) {
        if (data.charAt(i) == separator || i == maxIndex) {
            found++;
            strIndex[0] = strIndex[1] + 1;
            strIndex[1] = (i == maxIndex) ? i+1 : i;
        }
    }
    return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
}

It works fine, but ESP receive only three values, another 6 does not. I have tried to change bitrate to 57600, but thats not help. I think that there is a problem with speed or waiting for full data.

Can you help me ? Many Thanks.

Here is the output from ESP:

This arrived: (unparsed)0.000000:0.000000:0.000000:0.00
DATA sensors: (parsed)
0.000000
0.000000
0.000000
0.004



xxxx

Hi,

If you want to take a look on my code, you can jump to http://forum.arduino.cc/index.php?topic=451710.0
The serial works !
But on my side, I've got some problem to get wifi working when I call software serial library.
Even with the one of Plurep :
http://github.com/plerup/espsoftwareserial

It seems it is linked to interrupts problem on this Rx pin 2

Did you managed to get both serial and wifi working ?