Search code examples
arduinoiotesp8266nodemcuarduino-esp8266

NodeMCU 1.0 (ESP-12E Module) as a TCP server


#include <ESP8266WiFi.h>
#include <WiFiClient.h>

const char *ssid = "ESPap";
const char *password = "thereisnospoon";
WiFiServer server(8080);

void setup() {
  delay(1000);
  Serial.begin(115200);
  Serial.println();
  Serial.print("Configuring access point...");
  WiFi.softAP(ssid, password);
  IPAddress myIP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(myIP);
  server.begin(); 
}

void loop() {
  WiFiClient clie = server.available();
  if(clie) {
    while(clie.connected()) {
      if(clie.available()) {
        Serial.println(clie.read());
      }
    }
    clie.stop();
  }
}

I'm new to IoT. My goal is to start a TCP server using NodeMCU 1.0 to listen to the string sent by an Android app. The Android app is already implemented and 100% working. (Tested using AT commands with an ESP8266-01 module).

But when I upload this code to the NodeMCU it doesn't print out the strings in the Serial Monitor.

What is wrong? There is no errors showing up either.


Solution

  • Did you try using clie.readString() or clie.readStringUntil() instead of clie.read().