This is the code:
#include <ESP8266WiFi.h>
const char* ssid = "MyAccessPoint";
const char* password = "MyPassword";
const char* host = "192.168.1.116"; //The server IP
const int httpPort = 1280; // The port of Server
void setup() {
Serial.begin(115200);
delay(10);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.print("connecting to ");
Serial.println(host);
WiFiClient client;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}
// This is the HEX data to send 50 00 00 FF FF 03 00 0E 00 10 00 01 14 00 00 00 00 00 A8 01 00 21 00
byte manda[]={0x50,0x00,0x00,0xff,0xff,0x03,0x00,0x0E,0x00,0x10,0x00,0x01,0x14,0x00,0x00,0x00,0x00,0x00,0xA8,0x01,0x00,0x21,0x00};
Serial.println("Send data");
for (int i =0; i<sizeof(manda);i++){
client.write (manda[i]);
// Serial.print(manda[i],HEX);
// Serial.print(" ");
// miorit();
}
Serial.println("Data has been sent");
client.stop();
}
void loop() {
//do nothing
}
It sent the first 0x50 HEX data in one TCP packet and all other in another packet !!
The PLC do not recognize the command.
I copied this string from a windows software there the whole data arrives in one shot and it works.
Is a library bug or there is other way to do it ?
Many thanks
Rino