The really strange thing is, I have it configured that the client sends all it's IP information in the setup routine to the server for it to display it in the serial monitor, and that works every single time. I also have an AP that's always looking for the devices, and that works every single time. But sending data from the client to the server doesn't work consistently.
Maybe I'm missing something obvious, but the programs are about as simple as they can get, and the data does get there sometimes. Right now I'm just testing it by typing in the Serial monitor, but eventually it'll be pulling data from another device and sending it to the server. I just need to figure out the consistency issues first.
Thanks a lot!
Pertinent Code
Server
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
server.begin();
Serial.println("Connected to wifi");
Serial.print("Status: "); Serial.println(WiFi.status());
Serial.print("IP: "); Serial.println(WiFi.localIP());
Serial.print("Subnet: "); Serial.println(WiFi.subnetMask());
Serial.print("Gateway: "); Serial.println(WiFi.gatewayIP());
Serial.print("SSID: "); Serial.println(WiFi.SSID());
Serial.print("Signal: "); Serial.println(WiFi.RSSI());
Serial.print("Networks: "); Serial.println(WiFi.scanNetworks());
}
void loop () {
WiFiClient client = server.available();
if (client) {
if (client.connected()) {
Serial.println("Client Connected");
String request = client.readString();
Serial.print("From client: ");
Serial.println(request);
client.flush();
}
Serial.println("Client Disconnected");
client.stop();
}
}
Client
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
client.connect(server, 80);
client.println("Connected to wifi");
client.print("Status: "); client.println(WiFi.status());
client.print("IP: "); client.println(WiFi.localIP());
client.print("Subnet: "); client.println(WiFi.subnetMask());
client.print("Gateway: "); client.println(WiFi.gatewayIP());
client.print("SSID: "); client.println(WiFi.SSID());
client.print("Signal: "); client.println(WiFi.RSSI());
client.stop();
}
void loop () {
while(Serial.available()){
client.connect(server, 80);
String Command = Serial.readString();
Serial.println(Command);
client.print(Command);
client.flush();
}
client.stop();
delay(100);
}