1

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.

  • and the prints in Serial Monitor indicate the the server started? can you ping the esp8266? – Juraj Jul 27 '18 at 15:23
  • 1
    in general, these things are 10x easier to code/debug when you program the ESP directly in ardunio instead of using AT commands. you can then use the uno as the "slave", which makes sense anyway because it's a lot weaker than the ESP. – dandavis Jul 27 '18 at 20:43
  • Did you get any solution? I am facing the same issue… – memento Oct 30 '18 at 6:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.