help please ! communication rs232 of arduino with specific software

Hi to all,
My name is Samuel and I am new to this forum.
Above all thank you for this forum because thanks to you , I learned a lot in programming arduino and I always find the answer in your posts , but this time I'm stuck and I need your help.

So I started programming and I'm trying to interface arduino sensor cloud that interacts with an already existing software.

The communication protocol of this software and free software is explained on the website designer , I give you the link.

rs232 protocol:
http://www.aagware.eu/aag_cloudwatchertechinfo.htm

the software is here:

http://www.aagware.eu/aag_cloudwatcher700.htm

Here is the code I made to react with the software
It aims at the moment to test the communication with the software and the data it returns is static ( no sensor connected ) .
The code works fine in test by the serial monitor, but I have no reaction of the software.
1 - I think it does not understand the character strings that my code returns it.
2 - The software sends serial data before the arduino serial port is ready . ( Seen with a serial port sniffer )

 //DETECTEUR DE NUAGES AAG ARDUINO

void setup(){
  Serial.begin(9600); // Démarrage du port série
  String msg ="";
  char lettre = '0';
  establishContact(); // etablit le contact sur le port série en envoyant un handshaking block
}



void loop(){
  String msg ="";
  char hsb [16]= {'!', 0x11,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','0'}; // Déclaration Handshaking block
  char lettre = '0';
    
  
    if(Serial.available() > 0) // si donnée présente
    {
    while(Serial.available() > 0 ) // tant qu'il y a des données :
       {
     lettre = Serial.read(); // lire et stocker les données dans "lettre"
      
      if (lettre == '!') // teste si '!' présent et arrete la lecture
         {
           msg += lettre; 
           delay(250);
           break; 
         }
      else // si pas de '!' continue la lecture
         {
           msg += lettre;
           delay(250);
         }
                  
       }
      // ici on commence à tester toutes les commandes reçues
      // et on retourne la chaine de caractère correspondante.
      if (msg == "K!")  
      {
        Serial.print("!K1234         "); // Serial number
        Serial.print(hsb);
      }
      else if (msg == "A!")
      {
        Serial.print("!N Cloudwatcher"); // Internal name
        Serial.print(hsb); 
      }
        
      else if (msg == "B!")
      {
         Serial.print("!N         1.10"); // Firmware version
         Serial.print(hsb);
      }
      else if (msg == "C!")
      {
        Serial.print("!6         0990"); // Zener voltage
        Serial.print("!3         1000"); // Ambient Temperature
        Serial.print("!4         1000"); // LDR voltage
        Serial.print("!5         1000"); // Rain sensor Temperature
        Serial.print(hsb);
      }
      else if (msg == "D!")
      {
        Serial.print("!E1       11111"); // 1st address byte errors
        Serial.print("!E2       11111"); // Command byte errors
        Serial.print("!E3       11111"); // 2nd address byte errors
        Serial.print("!E4       11111"); // PEC byte errors
        Serial.print(hsb); 
      }
      else if (msg == "E!")
      {
        Serial.print("!R         1000"); // Rain frequency
        Serial.print(hsb);
      }
      else if (msg == "F!")
      {
        Serial.print("!X             "); // Switch Open
        Serial.print(hsb);
        //Serial.print("!Y             "); // Switch Close
        //Serial.print(hsb); 
      }
      else if (msg == "G!")
      {
        Serial.print("!X             "); // Switch Open
        Serial.print(hsb);
      }
      else if (msg == "H!")
      {
        Serial.print("!Y             "); // Switch Close
        Serial.print(hsb);
      }
      else if (msg == "Ppppp!")
      {
        Serial.print("!Q         1000"); // PWM duty cycle
        Serial.print(hsb);
      }
      else if (msg == "Q!")
      {
        Serial.print("!Q         1000"); // PWM duty cycle
        Serial.print(hsb);
      }
      else if (msg == "S!")
      {
        Serial.print("!1        01200"); // IR sky temperature
        Serial.print(hsb);
      }
      else if (msg == "T!")
      {
        Serial.print("!1        02000"); // IR sensor temperature
        Serial.print(hsb);
      }
      else if (msg == "z!")
      {
        Serial.print(hsb);
      }
      else 
      {
        Serial.print("Commande non reconnue !");
      }
      
    }
  
}

void establishContact() {
  char hsb [16]= {'!', 0x11,' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','0'}; // Déclaration Handshaking block
    
  while (Serial.available() <= 0) {
    Serial.print("!N         1.10"); // Firmware version    
    Serial.print(hsb);   // send a handshaking block
    delay(300);
  }
}

Could you tell me where I 'm wrong in the code and give me some of your tps to help me run my interface with this software ?

thank you

Sam974

sam974:
2 - The software sends serial data before the arduino serial port is ready . ( Seen with a serial port sniffer )

Please put your code in code tags (the # icon) it makes it so much easier to read.

However, regardless of tags, your code is too long for my limited attention span.

Sending data before the Arduino is ready is a very common problem because when the PC opens the serial connection to the Arduino it cause the Arduino to reset and it takes the Arduino a little time to get started (but not as long as a PC). There is a simple solution. As the last thing in setup() have the Arduino send a short message to say it is ready. And have the PC program wait until it has received that message from the Arduino.

...R

Hi,

Thank you for your answer.
Sorry for the code in code tags, it's corrected.

So, the software can't be modified, so it's not possible to tell it to wait for the arduino.

So what do you think, if i try to connect the PC by the pin 0 and pin 1 through a max232 chip and put a power supply to the arduino so that it can be turn on and started before the PC ?

You could try disabling auto reset on serial connection.

  String msg ="";
  char lettre = '0';

Local variables that immediately go out of scope are useless. Delete them.

    if(Serial.available() > 0) // si donnée présente
    {
    while(Serial.available() > 0 ) // tant qu'il y a des données :

The if statement is useless. Get rid of it. The while statement IS a conditional execution statement that loops.

      if (lettre == '!') // teste si '!' présent et arrete la lecture
         {
           msg += lettre; 
           delay(250);

Get rid of ALL delay calls. The idea is to read serial data as fast as possible, not as slow as possible.