Testing the charactter '\0' after a client.read(); ESP8266

Hi there,
After hours of trials, I am still not able to know how to test my characters obtained from a client.read() function.

In the code below, I have proposed to test the if loop I am using later:

if (thisString[i]!= '\0')
             {DO SOMETHING;}
        else
             {STOP;}

So here is the code. It works perfectly well:

void setup() {
   Serial.begin(115200);
  Serial.println(" ");
}

void loop() {
  // put your main code here, to run repeatedly:
    String thisString = "Hello World!\0";
    Serial.print("this is a \0 string:    "); Serial.print("\0"); Serial.print("     this is a \0 char:    ");Serial.print('\0');
    Serial.println("Did you check ?");

  Serial.print(thisString);Serial.print("length:");Serial.println(thisString.length());
  delay(1000);
  
  for(int i=0;thisString.length()+1;i++){
            if (thisString[i]!= '\0'){
              Serial.print("Character:");Serial.print(i);Serial.print("-->");Serial.print(thisString[i]);Serial.println("    Continue");
            }
            else{
             Serial.print("Character:");Serial.print(i);Serial.print("-->");Serial.print(thisString[i]);Serial.println("STOP!") ;
             break;
            }
  }

}

if you test the code, the string "\0" or char '\0' are not printed.
The char by char reading works pefectly fine: it extract from the string "Hello World!" H, then e, etc. till it reach the \0.

Now a bit more complexe: I am using a station ESP8266, named STATION [1] and a softAP ESP8266 named SERVER.

My STATION is writting messages with the following format:

SOM
STATION [1] : : random(1000) : random(1000)
STATION [1] : : random(1000) : random(1000)
...
STATION [1] : : random(1000) : random(1000)
EOM\0

note I put the \0 for the "End Of Message". here is the code:

 if(client.connected()){
    unsigned long startMillis = millis();
    timeout_send_message = 0;
    client.println("***SOM***");
    while (client.connected() &&  (timeout_send_message < 50) ) {
          unsigned long currentMillis = millis();
          timeout_send_message  = currentMillis - startMillis;
           float A = random(1000);float B=random(1000);
          client.print("STATION [1]  :");client.print(" : ");client.print(A);client.print(" : ");client.println(B);//client.print("\n");
          Serial.print("STATION [1]  :");Serial.print(" : ");Serial.print(A);Serial.print(" : ");Serial.println(B);
    }
    client.println("***EOM***\0");
    Serial.println(">>> Message Timeout !");
  }

in the SERVER void LOOP. I create the connexion with the client, if it is available, I wait a bit so that client.available()>0, then i do a char c = client.read(); and do the comparison test with the '\0'

here is the code:

    if (client) {
      delay(100); //allow time to populate the client with data
      if (client.available() ){
               while (client.available()>0 || stop_condition !=0){
                         char c = client.read();  
                         if (c!='\0'){//if (c!='E'){
                              stop_condition = 1;
                              Serial.print(c);
                             // TRACE();
                             // Serial.println("CONTINUE");
                          }
                          else{
                              stop_condition = 0;
                              Serial.println("STOP !!!");
                              break;
                              delay(5000);
                          }
                    }
        }          
  }

The code is running till it reads the "EOM" but then keep printing the NULL character: [][][][][][]. The "else" is not executed, so the stop_condition do not change to "1".

As you may see, I also tried to compare with the character 'E'. The code works with 'E', but not with the '\0'.

I suspect the code is comparing '' with '\0'. am I right ?

I am looking for a clean way to force the right operating . I would like later to remove the EOM

the problem is, that the \0 terminates a c-string. it is not send, it is not printed, because it is interpreted as "stop printing/sending here", if you use function which expect a C string (zero terminated char array).
String class manages a C string internally too.

if you use 'buffer' functions they take length/size as an additional parameter and use that to determine the end of the data.

and if you work character by character then it is on you how do you handle the \0

I am note sure if I fully get your explainations. Do you mean there is an issue because I am sending data from my station with client.println() function? Should I switch to client.write() ?

I generated the code bellow wher I have a EOMBuffer string.

#include <ESP8266WiFi.h>
#include <WiFiClient.h>

#ifndef APSSID
#define APSSID "ssid_LOGIN"
#define APPSK  "password_password"
#endif

/* Set these to your desired credentials. */
const char *ssid = APSSID;
const char *password = APPSK;

IPAddress local_IP(192,168,4,22);
IPAddress gateway(192,168,4,9);
IPAddress subnet(255,255,255,0);
WiFiServer wifiServer(23);
String EOMBuffer = "AB";
bool stop_condition = 1;

void setup() {
  Serial.begin(115200);
  Serial.println("");
  WiFi.persistent(false); 
  Serial.print("Setting Access Point configuration ... ");
  WiFi.mode(WIFI_AP);
  Serial.println(WiFi.softAPConfig(local_IP, gateway, subnet) ? "Ready" : "Failed!");
  Serial.print("Setting soft-AP ... ");
  Serial.println(WiFi.softAP(ssid) ? "Ready":"False"); //WiFi.softAP(ssid,password)
  Serial.print("Access Point IP address = ");//Serial.print("Soft-AP IP address = ");
  Serial.println(WiFi.softAPIP());
  wifiServer.begin(); Serial.println("WiFi server started"); 
  wifiServer.setNoDelay(true);
}
 
void loop() {
 // Unique client
    WiFiClient client = wifiServer.available();
    Serial.print("Client status: "); Serial.print("   Connected?:    ");Serial.print(client.connected()); Serial.print("   Available?:    ");Serial.println(client.available());   
    if (client) {
       // client.println("Hello, client!  Server waiting for data"); 
      delay(100); //allow time to populate the client with data
      Serial.print("Client status: "); Serial.print("   Connected?:    ");Serial.print(client.connected()); Serial.print("   Available?:    ");Serial.println(client.available());       
        if (client.available() ){
               while (client.available()>0 || stop_condition !=0){
                          char c = client.read();                    
                          EOMBuffer[0] = EOMBuffer[1];EOMBuffer[0]=c;
			 //if (c!='\0'){ 
                          //if (c!='E'){
                          if (EOMBuffer!="\0"){
                              stop_condition = 1;
                              Serial.print(c);
                          }
                          else{
                              stop_condition = 0;
                              Serial.println("STOP !!!");
                              break;
                              delay(5000);
                          }
                    }
        }          
  }     
}

Though the I have still the following thing, the test on a String buffer is not working.

18:06:27.521 -> Client status: Connected?: 0 Available?: 0
18:06:27.521 -> Client status: Connected?: 0 Available?: 0
18:06:27.555 -> Client status: Connected?: 0 Available?: 0
18:06:27.555 -> Client status: Connected?: 0 Available?: 0
18:06:27.555 -> Client status: Connected?: 1 Available?: 0
18:06:27.655 -> Client status: Connected?: 1 Available?: 732
18:06:27.655 -> SOM
18:06:27.655 -> STATION [1] : : 937.00 : 793.00
18:06:27.655 -> STATION [1] : : 254.00 : 701.00
18:06:27.655 -> STATION [1] : : 488.00 : 304.00
18:06:27.655 -> STATION [1] : : 608.00 : 803.00
18:06:27.655 -> STATION [1] : : 689.00 : 529.00
18:06:27.655 -> STATION [1] : : 953.00 : 822.00
18:06:27.655 -> STATION [1] : : 252.00 : 468.00
18:06:27.655 -> STATION [1] : : 926.00 : 622.00
18:06:27.689 -> STATION [1] : : 901.00 : 156.00
18:06:27.689 -> STATION [1] : : 453.00 : 921.00
18:06:27.689 -> STATION [1] : : 749.00 : 682.00
18:06:27.689 -> STATION [1] : : 260.00 : 348.00
18:06:27.689 -> STATION [1] : : 901.00 : 967.00
18:06:27.689 -> STATION [1] : : 525.00 : 219.00
18:06:27.689 -> STATION [1] : : 218.00 : 960.00
18:06:27.689 -> STATION [1] : : 663.00 : 311.00
18:06:27.689 -> STATION [1] : : 797.00 : 8.00
18:06:27.689 -> STATION [1] : : 3.00 : 152.00
18:06:27.689 -> STATION [1] : : 976.00 : 245.00
18:06:27.722 -> STATION [1] : : 805.00 : 631.00
18:06:27.722 -> STATION [1] : : 274.00 : 638.00
18:06:27.722 -> EOM
18:06:27.722 -> ⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮