We're trying to use an ESP8266/Arduino Uno as a TCP server, which connects to a wireless AP and then receives commands from other devices on the same network. Currently we got the "connect to AP" part working, but when we try to send data to the ESP/Arduino/TCP server, it doesn't work, refusing all connections to it.
Here's the (relevant parts of the) code we currently use:
#include <SoftwareSerial.h>
SoftwareSerial ESPSerial(2, 3);
void setup() {
Serial.begin(9600);
ESPSerial.begin(115200);
sendToWifi("AT", 10, true);
sendToWifi("AT+CWMODE=1", 10, true);
sendToWifi("AT+CWJAP=\""+myAp+"\",\""+myApPassword+"\"", 10, true);
sendToWifi("AT+CIPMUX=1", 10, true);
sendToWifi("AT+CIPSERVER=1,80", 10, true);
}
void loop() {
// The code that would receive data from connecting devices are here
}
String sendToWifi(String command, const int timeout, boolean debug) {
String response = "";
ESPSerial.println(command);
long int time = millis();
while((time+timeout) > millis) {
while(ESPSerial.available()) {
char c = ESPSerial.read();
response+=c;
}
}
if(debug) {
Serial.println(response);
}
return response;
}
I also have code that's supposed to receive/print data received from the other devices on the network but because no other device can even connect to this TCP server, I felt it was irrelevant for the question. If however you think it's important to include said code, let me know and I'll update my question.
All the solutions we've found online either configures the ESP as the AP, uses the WifiClient library, which we can't seem to get working (even if we could though, we'd rather do it through AT commands) or uses the ESP8266 as a stand-alone module.