Pool automation UDP commands

Hello,

I’m new to this forum. I have an Arduino Mega whom I would like to automate my pool. I wrote some code to send via UDP commands to the seriale ports and to send back the answers of the seriale ports.

However, it does not work . the serial device receives no data. I see the LED.

The serial devices I use are the pH and ORP probe probe Atlas Scientific.

Can anyone tell me what I do wrong?

#include <SPI.h>         // needed for Arduino versions later than 0018
#include <Ethernet.h>
#include <EthernetUdp.h>         // UDP library from: bjoern@cs.stanford.edu 12/30/2008


// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {  
  0x90, 0xA2, 0xDA, 0x0F, 0xC2, 0xD7 };
IPAddress ip(192, 168, 0, 200);

unsigned int localPort = 9999;              // local port to listen on

// buffers for receiving and sending data
char  packetBuffer;                    //buffer to hold incoming packet,
char  ReplyBuffer;                     // a string to send back
boolean input_packetBuffer = false;       //have we received all the data from the PC
boolean sensor_ReplyBuffer = false;       //have we received all the data from the Atlas Scientific product

// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;

void setup() {
  // start the Ethernet and UDP:
  Ethernet.begin(mac,ip);
  Udp.begin(localPort);
  Serial.begin(9600);
  Serial3.begin(9600);   //PH Sensor
  //Serial1.begin(9600);   //ORP Sensor
}

void UdpEvent() {   
  Udp.parsePacket();                                       //When the UDP port receives a char              
  char inchar = Udp.read();                               //get the char we just received
  packetBuffer += inchar;                                 //add it to the inputString
  if(inchar == '\r') {
    input_packetBuffer = true;
  }                                                       //if the incoming character is a <CR>, set the flag
}  


void serialEvent3(){                                           //if the hardware serial port_3 receives a char 
  char inchar = Serial3.read();                                //get the char we just received
  ReplyBuffer += inchar;                                       //add it to the inputString
  if(inchar == '\r') {
    sensor_ReplyBuffer = true;
  }                                                            //if the incoming character is a <CR>, set the flag 
}


void loop() {
  
  
  // if there's data available, read a packet
  int packetSize = Udp.parsePacket();
  if(packetSize)
  {
    Serial.print("Received packet of size ");
    Serial.println(packetSize);
    Serial.print("From ");
    IPAddress remote = Udp.remoteIP();
    for (int i =0; i < 4; i++)
    {
      Serial.print(remote[i], DEC);
      if (i < 3)
      {
        Serial.print(".");
      }
    }
    Serial.print(", port ");
    Serial.println(Udp.remotePort());
    Serial.println("Contents:");
    Serial.println(packetBuffer);

    if (input_packetBuffer = true){                                                    //if a string from the PC has been received in its entirety 
      Serial3.print(packetBuffer);                                              //send that string to the Atlas Scientific product
      packetBuffer = ' ';                                                       //clear the string:
      input_packetBuffer = false;                                               //reset the flag used to tell if we have received a completed string from the PC
    }
  
    if (sensor_ReplyBuffer){ 
      Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());  
      Udp.write(ReplyBuffer);
      Udp.endPacket();
                                                                              //if a string from the Atlas Scientific product has been received in its entierty 
                                                                             //send that string to to the PC's serial monitor
      ReplyBuffer = ' ';                                                       //clear the string:
      sensor_ReplyBuffer = false;                                           //reset the flag used to tell if we have received a completed string from the Atlas Scientific product
    }

    // send a reply, to the IP address and port that sent us the packet we received



  }
  delay(10);
}
char  packetBuffer;                    //buffer to hold incoming packet,
char  ReplyBuffer;                     // a string to send back

One character "buffers"?

  packetBuffer += inchar;                                 //add it to the inputString

Adding characters is pointless. What is P + h?

In addition to PaulS, have you tested each of the parts of your code separately? Is it the serial interface to the pool or the UDP part that doesn't work?