communication between 2x ESP8266.

Hi, when you establish the access point can you see it's network from another device and connect on to it (like a smartphone)?

Use char* instead of char as data type (same applies for STA mode)

const char *ssid = "ESP33";
const char *pass = "1234567899";

Nikosant03:
Hi, when you establish the access point can you see it's network from another device and connect on to it (like a smartphone)?

Use char* instead of char as data type (same applies for STA mode)

const char *ssid = "ESP33";

const char *pass = "1234567899";

Hello Nikosant03,
One of the things I have always struggled with in C and C++ is how and when to use pointers. Please can you explain why you are suggesting this, so maybe I can understand better.

Thanks.

PerryBebbington:
AP

char ssid[] = "TestAP";               // SSID of your home WiFi

STA

char ssid[] = "t-TestAP";           // SSID of your home WiFi

I don't know enough about the rest of the code to comment.

Sorry this was a mistake of me when I copied this here and edited one line.

I am able to connect to the AP with my Smartphone.

So any suggestions, how to send continuous data to the STA?

The client (ESP32 set it up in STA mode) is it connected on the AP?

The STA connects to the AP

Nikosant03:
Use char* instead of char as data type (same applies for STA mode)

const char *ssid = "ESP33";

const char *pass = "1234567899";

Bad advice. If the code ever changes the value of the pointer, the string literal will be stranded in memory never to be heard from again. In this case, there's no advantage to using a pointer over a char. But, if you insist, then correct construct would be:

const char * const ssid = "ESP33";
const char * const pass = "1234567899";

Note that this usage is identical to:

const char ssid[] = "ESP33";
const char pass[] = "1234567899";

Thanks,

now the question is. Is there an easy way to send data to the STA from the AP.

like

message = “Test Text”
send.client1(message);
send.client2(message);

and the clients can receive this?
I heard something about websockets. but how does it work?

just out of curiosity- what are you trying to do and why are you married to HTTP client/server?

I use MQTT between nodes in my home IOT. It's easy to set up, scalable, and it just works.

gfvalvo:
Note that this usage is identical to:

OK, a little off topic to chime in here and can't help the OP, but @gfvalvo, thanks for that. I will stop using the "*" in such circumstances again. That last example is a much cleaner and concise visual approach for me.

SteveMann:
I use MQTT between nodes in my home IOT. It's easy to set up, scalable, and it just works.

He does not suggest it is on a network of any type, just communication between two or more ESP8266. Maybe like a walkie-talkie kind of thing, but with text on OLEDs.

I would set up a server on the STA and let your AP make a (get or post) request to that as a client. You set the STA IP address to whatever you want it to be (or assume it will be assigned 192.168.4.2) and don't fiddle with the AP IP address (just leave it as 192.168.4.1) you never call it anyway. The STA should end back a response, but that may as well be nothing more than confirmation of reception.

So how is he doing this?
I think the one esp is just sending a value of the potentiometer to the other esp?
Unfortunately there is no code for this example?

Maybe someone can explain.

Thanks

So I try to explain a bit more detailed what I am looking for.

At the moment I have a ESP8266 that runs a website and a RGB Neopixel LED is connected.
On the website you can control the color of the LED.
The color is stored to EEPROM and reloaded after restart.

I want to control adidtional ESP (LEDs) with one device.
So when I select a color on the website in the browser. I want the color to be changed on ESP#1, ESP#2 and ESP#3.

Here is a picture. The green frame shows what I already have, but I want to control the other LEDs as well.

So I want to send these values from ESP#1 to ESP#2 and ESP#3
PF_R (value for Red)
PF_G (value for Green)
PF_B (value for Blue)

So does anybody have a solution for this?

Thanks

/*
v6: EEPROM wird versucht    https://github.com/esp8266/Arduino/tree/master/libraries/EEPROM/examples
v7: EEPROM funtkioniert
v8: Versuch des sendens der Daten Wireless
*/

#include "index.h"
#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <EEPROM.h>
#include <NeoPixelBus.h>

int redINT;
int greenINT;
int blueINT;
byte PF_R;
byte PF_G;
byte PF_B;

int addr_PF_R = 3;
int addr_PF_G = 4;
int addr_PF_B = 5;

#define PixelCount 4 // Number of leds on stick
#define PixelPin 0 // "NodeMCU pin 2 (RX) connected to Digital In of Pixel Stick"
//PIN 2 ist GPIO3 auf dem ESP-01
NeoPixelBus<NeoGrbFeature, NeoEsp8266Dma800KbpsMethod> strip(PixelCount, PixelPin);

const char *ssid = "RGB";
// const char *password = "87654321";

const byte DNS_PORT = 53;
IPAddress apIP(192, 168, 1, 1);
DNSServer dnsServer;
ESP8266WebServer webServer(80);

//////////////////////////////////////////////////////////////////////////////////////////////////

void handleRoot() {
  
  String s = MAIN_page;
webServer.send(200, "text/html", s); //Send web page
Serial.println("handle root..");
String WebServerArgDecission = webServer.arg(0);
Serial.print("WebserverDecission: ");
Serial.println(WebServerArgDecission);
if (WebServerArgDecission == "C") {
  String red = webServer.arg(1); // read RGB arguments
  String green = webServer.arg(2);
  String blue = webServer.arg(3);
  
  redINT = 256-(red.toInt()/4);
  greenINT = 256-(green.toInt()/4);
  blueINT = 256-(blue.toInt()/4);
  byte testbyte = 200;
  Serial.print("R:"); // for TESTING
  Serial.print(redINT); // for TESTING
  Serial.print(", G:"); // for TESTING
  Serial.print(greenINT); // for TESTING
  Serial.print(", B:"); // for TESTING
  Serial.println(blueINT); // for TESTING 
   
  strip.SetPixelColor(0, RgbColor(redINT, greenINT, blueINT));
  strip.Show();
  }

else {}
webServer.send(200, "text/html", s);
  }

//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////

void setup() {
  EEPROM.begin(512);
  EEPROMRead();
//  Serial.println("Startup.....Sucess");
//  Serial.print("Read EEPROMbyte(RGB): "); Serial.print(PF_R); Serial.print(", "); Serial.print(PF_G); Serial.print(", "); Serial.println(PF_B);
  for (int i = 0; i <= PixelCount; i++) {
    strip.SetPixelColor(i, RgbColor(PF_R, PF_G, PF_B));
  }
  strip.Show();
  Serial.begin(9600);

delay(100);
//Serial.begin(9600);
//Serial.println();

WiFi.mode(WIFI_AP);
WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
WiFi.softAP(ssid);

// if DNSServer is started with "*" for domain name, it will reply with provided IP to all DNS request
dnsServer.start(DNS_PORT, "rgb", apIP);

webServer.on("/", handleRoot);

webServer.begin();

strip.Begin();
strip.Show();

}


//////////////////////////////////////////////////////////////////////////////////////////////////

void loop() {

dnsServer.processNextRequest();
webServer.handleClient();

}
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////////////////////////


///////////////////////////////////////////EEPROM READ////////////////////////////////////////////
void EEPROMRead() {
  PF_R = EEPROM.read(addr_PF_R);
  PF_G = EEPROM.read(addr_PF_G);
  PF_B = EEPROM.read(addr_PF_B);
}

haschu87:
So how is he doing this?
I think the one esp is just sending a value of the potentiometer to the other esp?
Unfortunately there is no code for this example?

Esp to esp web socket communication - YouTube

Maybe someone can explain.

Thanks

Here i think he is using websockets, i've never used this, will look into it one day.

in response to #14, first of all about NeoPixelBus

#define PixelPin 0 // "NodeMCU pin 2 (RX) connected to Digital In of Pixel Stick"
//PIN 2 ist GPIO3 auf dem ESP-01
NeoPixelBus<NeoGrbFeature, NeoEsp8266Dma800KbpsMethod> strip(PixelCount, PixelPin);

in DMA mode the pin can not be changed, you may as well leave it out in the object declaration.

2nd and this is the main thing, you can connect several Stations (up to 8) to 1 AP, but a Station can only be connected to 1 AP at the time. So if you want to control several ESP’s from 1 then the controller is your AP and the leds are connected to Stations.
Now in connecting those stations to your AP you can either give each STA a static IP, or let the AP assign them a dynamic AP (it should assign them 192.168.4.x where x is 1 for the AP and 2 onwards for every STA connected)
Now on the STA’s you can set up a webserver as you have done in your code, and from your AP you can connect to each individual STA as a client (eg http//:192.168.4.x/?par1=val1&etc…)
You can even set uo a webserver on your AP as well, and create a form to to input the info and extract and forward to all the ‘nodes’

now about you webpage

void handleRoot() {
  
  String s = MAIN_page;
webServer.send(200, "text/html", s); //Send web page
....
webServer.send(200, "text/html", s);
  }

you can only send the page once per request. the best approach is to first extract the data and then send the page. atm you have the page in index.h and then copied into s, but if you create the page within the handleroot() function you can also include the results of the form submission as part of the page simply by adding this to the String before you send it.

Also you seem to be reading from the EEPROM only nothing ever gets written to it, mind you with the ESP being a flash-EEPROM writing to it just to store RGB values for the ledstrip probably isn’t such a god idea.

Deva_Rishi:
2nd and this is the main thing, you can connect several Stations (up to 8) to 1 AP, but a Station can only be connected to 1 AP at the time. So if you want to control several ESP's from 1 then the controller is your AP and the leds are connected to Stations.
Now in connecting those stations to your AP you can either give each STA a static IP, or let the AP assign them a dynamic AP (it should assign them 192.168.4.x where x is 1 for the AP and 2 onwards for every STA connected)
Now on the STA's you can set up a webserver as you have done in your code, and from your AP you can connect to each individual STA as a client (eg http//:192.168.4.x/?par1=val1&etc..)
You can even set uo a webserver on your AP as well, and create a form to to input the info and extract and forward to all the 'nodes'

OK thanks.

Now on the STA's you can set up a webserver as you have done in your code, and from your AP you can connect to each individual STA as a client (eg http//:192.168.4.x/?par1=val1&etc..)
You can even set uo a webserver on your AP as well, and create a form to to input the info and extract and forward to all the 'nodes'

How do I do this?

haschu87:
How do I do this?

How do you normally log onto a webpage programatically ?
Looking at the 'BasicHttpClient' example, (in ESP8266HTTPClient)
Declare the object, do the request, check the return code, and use .getString() to import the data. from there on it is filtering and/or printing etc. There is more ways that lead to Rome but this is one way.

So I modified my code a little bit for the experiments.
Now I can transfer the data from my AP to the STA.
I can print the RGB Values on the STA transmitted from the AP
But the STA crashes at “strip.Show()”
In the Serial Monitor RGB Values, DONE1 and DONE2 is printed. but DONE3 is not printed and also the AP is not able to receive any information from the created website.
I think the STA is blocking something.
When I remove strip.Show() everything works. It continues to print the RGB values on the serial monitor when I change them on the website of the AP.
AP:

#include "index.h"
#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <NeoPixelBus.h>
#include <ESP8266HTTPClient.h>

const String Client1 = "http://192.168.1.101";
const String Client2 = "http://192.168.1.102";
const String Client3 = "http://192.168.1.103";

int redINT;
int greenINT;
int blueINT;

#define PixelCount 4 // Number of leds on stick
#define PixelPin 0 // "NodeMCU pin 2 (RX) connected to Digital In of Pixel Stick"
//PIN 2 ist GPIO3 auf dem ESP-01
NeoPixelBus<NeoGrbFeature, NeoEsp8266Dma800KbpsMethod> strip(PixelCount, PixelPin);

const char *ssid = "RGB";
// const char *password = "87654321";

const byte DNS_PORT = 53;
IPAddress apIP(192, 168, 1, 1);
DNSServer dnsServer;
ESP8266WebServer webServer(80);

//////////////////////////////////////////////////////////////////////////////////////////////////

void handleRoot() {
  
  String s = MAIN_page;
webServer.send(200, "text/html", s); //Send web page
Serial.println("handle root..");
String WebServerArgDecission = webServer.arg(0);
Serial.print("WebserverDecission: ");
Serial.println(WebServerArgDecission);
if (WebServerArgDecission == "C") {
  String red = webServer.arg(1); // read RGB arguments
  String green = webServer.arg(2);
  String blue = webServer.arg(3);
  
  redINT = 256-(red.toInt()/4);
  greenINT = 256-(green.toInt()/4);
  blueINT = 256-(blue.toInt()/4);
  int calcRGB = redINT + greenINT + blueINT;
  
  if (calcRGB == 0) {
    Serial.println("no no");
    }
  else {
      Serial.print("R:"); // for TESTING
      Serial.print(redINT); // for TESTING
      Serial.print(", G:"); // for TESTING
      Serial.print(greenINT); // for TESTING
      Serial.print(", B:"); // for TESTING
      Serial.println(blueINT); // for TESTING 
      getStatus(); //Transmit Data to Clients
    strip.SetPixelColor(0, RgbColor(redINT, greenINT, blueINT));
    strip.Show();
    }
  }
else (WebServerArgDecission == "B") {
  Serial.println("B"); // for TESTING
  for (int a = 0; a <= 5; a++) {
  for (int i = 0; i <= PixelCount; i++) {strip.SetPixelColor(i, RgbColor(0, 0, 0));}strip.Show();
  }
  }
webServer.send(200, "text/html", s);
}

//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////

void setup() {
  Serial.begin(9600);
  delay(100);
  WiFi.mode(WIFI_AP);
  WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
  
  WiFi.softAP(ssid);
  
  // if DNSServer is started with "*" for domain name, it will reply with provided IP to all DNS request
  dnsServer.start(DNS_PORT, "rgb", apIP);
  webServer.on("/", handleRoot);
  
  webServer.begin();
}


//////////////////////////////////////////////////////////////////////////////////////////////////

void loop() {

dnsServer.processNextRequest();
webServer.handleClient();

}
void getStatus() {
  HTTPClient http;
  http.begin(Client1 + "/cx" + redINT + "x" + greenINT + "x" + blueINT + "x\r\n");
  int httpCode = http.POST("\r\n");
  http.end();
}

STA:

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <NeoPixelBus.h>

int redINT;
int greenINT;
int blueINT;

#define PixelCount 4 // Number of leds on stick
#define PixelPin 5
NeoPixelBus<NeoGrbFeature, NeoEsp8266Dma800KbpsMethod> strip(PixelCount, PixelPin);

const char* ssid = "RGB";    //  Your Wi-Fi Name
const char* password = "12345678";   // Wi-Fi Password


//Static IP address configuration
IPAddress staticIP(192, 168, 1, 101); //ESP static ip
IPAddress gateway(192, 168, 1, 1);   //IP Address of your WiFi Router (Gateway)
IPAddress subnet(255, 255, 255, 0);  //Subnet mask
IPAddress dns(8, 8, 8, 8);  //DNS

int LED = 2;   // led connected to GPIO2 (D4)

WiFiServer server(80);
HTTPClient http;

void setup()
{
  delay(2000);
  Serial.begin(9600); //Default Baudrate
  pinMode(LED, OUTPUT);
  digitalWrite(LED, LOW);
  Serial.print("Connecting to the Newtork");
  WiFi.config(staticIP, subnet, gateway);
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid);
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }
  Serial.println("WiFi connected"); 
  server.begin();  // Starts the Server
  Serial.println("Server started");
  Serial.print("IP Address of network: "); // will IP address on Serial Monitor
  Serial.println(WiFi.localIP());
  Serial.print("Copy and paste the following URL: https://"); // Will print IP address in URL format
  Serial.print(WiFi.localIP());
  Serial.println("/");
}
void loop()
{
  WiFiClient client = server.available();
  if (!client)
  {
    return;
  }
//  Serial.println("Waiting for new client");
  while(!client.available())
  {
    delay(1);
  }
  String request = client.readStringUntil('\r');

  String CharRequest = request + "xTEST";

  int value = LOW;
  //This is not needed. Was from the Example   ---->
  if(request.indexOf("/LED=ON") != -1)
  {
    digitalWrite(LED, HIGH); // Turn LED ON
    value = HIGH;
  }
  if(request.indexOf("/LED=OFF") != -1)
  {
    digitalWrite(LED, LOW); // Turn LED OFF
    value = LOW;
    Serial.println("AUS");
  }
  //  <----This is not needed. Was from the Example
  if(request.indexOf("/c") != -1)
  {
    String red = (split(CharRequest, 'x',1));
    String green = (split(CharRequest, 'x',2));
    String blue = (split(CharRequest, 'x',3));
    redINT = red.toInt();
    greenINT = green.toInt();
    blueINT = blue.toInt();
    Serial.println("------------");
    Serial.println(redINT);
    Serial.println(greenINT);
    Serial.println(blueINT);
    Serial.println("------------");
  }
  client.flush();
  Serial.println("DONE1");
  strip.SetPixelColor(0, RgbColor(100, 100, 100));
  Serial.println("DONE2");
  strip.Show();
  Serial.println("DONE3");

}

String split(String s, char parser, int index) {
  String rs="";
  int parserIndex = index;
  int parserCnt=0;
  int rFromIndex=0, rToIndex=-1;
  while (index >= parserCnt) {
    rFromIndex = rToIndex+1;
    rToIndex = s.indexOf(parser,rFromIndex);
    if (index == parserCnt) {
      if (rToIndex == 0 || rToIndex == -1) return "";
      return s.substring(rFromIndex,rToIndex);
    } else parserCnt++;
  }
  return rs;
}

Nikosant03:
Hi, when you establish the access point can you see it's network from another device and connect on to it (like a smartphone)?

Use char* instead of char as data type (same applies for STA mode)

const char *ssid = "ESP33";

const char *pass = "1234567899";

No need to make a pointer for this. Brings no real value.

Romonaga:
No need to make a pointer for this. Brings no real value.

Reply #7.