Help connecting two ESP8266 without router

Hi there,

For a new project I was toying around with two ESP8266's connected without WiFi, where an input from one ESP leads to a response on another ESP.
In this case I want to have a pushbutton input on one ESP lead to an LED turn on/off on another ESP. I followed a tutorial to connect the two ESP's where one acts as an AP and the other as a client (https://blog.zairza.in/esp8266-to-esp8266-communication-without-a-router-fe9642b93292), which worked fine, but now I want to take the next step: writing HIGH on one of the ESP's which turns on the LED on the other ESP. From there I want to add the pushbutton state to read as an input.

The problem I'm running into is that I can't for the life of me figure out what I can put into the functions that are supplied with the ESP, like these: Client Class — ESP8266 Arduino Core 3.1.1-19-gbe02af05 documentation. It seems to be relying on bytes, chars and other things that I don't really understand well.

What I'm looking for is a sample of what I need to put into the loop's so that the ESP's actually have an input/output connectiong rather than blinking in sync. Or am I better off implementing HTTP GET/POST requests, which seems to be another commonly used way of communicating between ESP's.

Any help is appreciated, thanks!

The client code:

#include <ESP8266WiFi.h>
byte ledPin = 2;
char ssid[] = "Wifiathome";                 // SSID of your AP
char pass[] = "Het#Katten@Huis=0";          // password of your AP
IPAddress server(192,168,4,15);             // IP address of the AP
WiFiClient client;

void setup() {
  Serial.begin(9600);
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, pass);           // connects to the WiFi AP
  Serial.println();
  Serial.println("Connection to the AP");
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
  Serial.println();
  Serial.println("Connected");
  Serial.println("station_bare_01.ino");
  Serial.print("LocalIP:"); Serial.println(WiFi.localIP());
  Serial.println("MAC:" + WiFi.macAddress());
  Serial.print("Gateway:"); Serial.println(WiFi.gatewayIP());
  Serial.print("AP MAC:"); Serial.println(WiFi.BSSIDstr());
  pinMode(ledPin, OUTPUT);
}

void loop() {
  client.connect(server, 80);
  digitalWrite(ledPin, LOW);
//  Serial.println("********************************");
//  Serial.print("Byte sent to the AP: ");
//  Serial.println(client.print("KleinPoepje\r"));
//  String answer = client.readStringUntil('\r');
//  Serial.println("From the AP: " + answer);
  client.flush();
  digitalWrite(ledPin, HIGH);
  client.stop();
  delay(2000);
}

The Access Point code

//for more info go to https://blog.zairza.in/esp8266-to-esp8266-communication-without-a-router-fe9642b93292

#include <ESP8266WiFi.h>
WiFiServer server(80);
IPAddress IP(192,168,4,15);
IPAddress mask = (255, 255, 255, 0);
byte ledPin = 2;

void setup() {
 Serial.begin(9600);
 WiFi.mode(WIFI_AP);
 WiFi.softAP("Wifiathome", "Het#Katten@Huis=0");
 WiFi.softAPConfig(IP, IP, mask);
 server.begin();
 pinMode(ledPin, OUTPUT);
 Serial.println();
 Serial.println("accesspoint_bare_01.ino");
 Serial.println("Server started.");
 Serial.print("IP: "); Serial.println(WiFi.softAPIP());
 Serial.print("vMAC:"); Serial.println(WiFi.softAPmacAddress());
}

void loop() {
 WiFiClient client = server.available();
 if (!client) {
  return;
 }
 digitalWrite(ledPin, LOW);
// String request = client.readStringUntil('\r');
// Serial.println("********************************");
// Serial.println("From the station: " + request);
 client.flush();
// Serial.print("Byte sent to the station: ");
// Serial.println(client.println(request + "ca" + "\r"));
 digitalWrite(ledPin, HIGH);
}

Is the communication expected to be two way or is the client just sending information (key presses, commands etc.) and the server is responding by flashing leds etc.

You can however still use a client/server type architecture even if the server is getting information back to the client. In that case, the client has to poll regularly to see if there is any information waiting for it.

i thought only the router has an ssid and password?

without a router, how are IP addresses assigned?

can you reach the other node using a MAC address? Does WiFiClient have such capabilities.

Robin2's ESP-NOW tutorial may be of interest.

gcjr:
i thought only the router has an ssid and password?

without a router, how are IP addresses assigned?

can you reach the other node using a MAC address? Does WiFiClient have such capabilities.

In this case one of the ESP's acts as a router, setting up its own Wifi network.

groundFungus:
Robin2's ESP-NOW tutorial may be of interest.

I've found the tutorial you mean, and also this one: Getting Started with ESP-NOW (ESP8266 NodeMCU with Arduino IDE) | Random Nerd Tutorials.

I've shortly checked it out, looks like something that might be useful, thanks! I'll update with progress tomorrow.