("AT+CIPSTART="TCP","xxx.xxx.xxx.xx","5100/invic?Configs"", 5, "CONNECT OK");
The first connection (1) works no problem.
However the second connection (2) fails.
I need to create the same syntax that I use for HTTP for the UDP connection in 2 above.
I have tried various variations but no joy.
Could someone point out what I am doing incorrectly.
there is no URL at UDP (or TCP) level. 5000 is the port number. the message will be send to specific port on the device with the specified IP address. any other differentiation has to be on the application level protocol (like HTTP, FTP, NTP, ... or your own)
Many Thanks, makes sense - also makes my server side easier.
I have seen many examples of sending a UDP packet to a server and waiting for a response.
But, unfortunately, all these examples use either an ethernet or WIFI shield.
I can send the UDP packet to the server without any problems, my server side app then sends a response.
How do I now wait for the response from the server?
This is the code that sends the UDP data packet from my Arduino:
sendATcmd("AT+CGATT?", 3, "+CGATT: 1");
sendATcmd("AT+CIPSHUT", 3, "SHUT OK");
sendATcmd("AT+CIPSTATUS", 3, "STATE: IP INITIAL");
sendATcmd("AT+CIPMUX=0", 3, "OK");
sendATcmd("AT+CSTT=\"flickswitch\",\"\",\"\"", 2, "OK");
sendATcmd("AT+CIICR", 5, "OK");
sendATcmd("AT+CIFSR", 5, "OK");
sendATcmd("AT+CIPSTART=\"TCP\",\"XXX.XXX.XXX.XX\",\"5000\"", 2, "CONNECT OK");
sendATcmd("AT+CIFSR", 5, "OK");
sendATcmd("AT+CIPSEND", 5, ">");
Serial1.print("01854EBC#S#01ACE343#E#40#83#90#IS001#15#000");
Serial1.write(0x1a);
// NOW I MUST WAIT AND READ THE RESSPONSE FROM THE SERVER
sendATcmd("AT+CIPSHUT", 5, "SHUT OK");
It seems that you use an Arduino-Uno and an ESP8266 / or ESP32 connected via a serial interface with the arduino.
Things will become 10 times easier if you use the ESP8266 as your new arduino.
You can write code for the ESP8266 / ESP32 the same way as for an arduino using the Arduino-IDE.
This means in a WiFi-project the arduinos become obslote because the ESP32 can do all the stuff the arduino is doing too.
Communicating with an ESP over AT-command is a big hassle compared to writing code that directly runs on the ESP
receiving an UDP-message will look similar to this
WiFiUDP myUDP;
const int UDP_Rcv_Buffer_Size = 256;
char myUDP_Rcv_Buffer[UDP_Rcv_Buffer_Size]; // buffer for incoming packets
int packetSize, len;
for (int i = 0; i < UDP_Rcv_Buffer_Size; i++) {
myUDP_Rcv_Buffer[i] = 0;
}
packetSize = myUDP.parsePacket();
and sending will look similar like this
WiFiUDP myUDP;
const int UDP_Rcv_Buffer_Size = 256;
char myUDP_Rcv_Buffer[UDP_Rcv_Buffer_Size]; // buffer for incoming packets
Udp.beginPacket(remoteIP, remotePort);
Udp.write(UDP_Msg_uint8_Buffer, UDP_Msg_PS.length() );
Udp.endPacket();
So if you describe what your overall project is and what your code is doing in summary. The effort how much / or few work it will be to transform your project from Arcuino---ESP to a pure ESP32-project.
Thanks all,
My processor is a ATMEGA328PB on a bareboard layout.
I cannot change this.
I am changing the connection to the server from a HTTP connection to TCP-UDP connection as the HTTP connection was not reliable.