Go Down

Topic: How to send HTTP request from one ESP8266 (master) to another (slave) (Read 65 times) previous topic - next topic

bb328

Hi all,

I have a working Wemos/Lolin D1 Mini running WiFiTerm (discussed here https://forum.arduino.cc/index.php?topic=672384.15 ).
I can send commands to it from any browser and control different local actions via a command line interface :

Code: [Select]

#include <ESP8266WiFi.h>
const char* ssid = "";
const char* password = "";

#include "WiFiTerm.h"

ESP8266WebServer server(80);

void setup()
{
  pinMode(D1, OUTPUT);
  Serial.begin(115200);
  Serial.print("\nConnecting to WIFI");
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print('.');
  }
  Serial.println("connected");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  server.begin();
  Serial.println("webServer started");

  term.begin(server);
  Serial.println("term started");
}

void loop()
{
  server.handleClient();
  term.handleClient();

  if (term.available()) {
    incoming = term.readString();
    incoming.toUpperCase();
    term.println(incoming);
    uint8_t i = incoming.indexOf(' ');
    uint8_t j = incoming.indexOf(' ', i + 1);

    cmd = incoming.substring(0, i);
    p1 = incoming.substring(i + 1, j).toInt();
    p2 = incoming.substring(j + 1).toInt();
    //term.println(cmd);
    //term.println(p1);
    //term.println(p2);


    if (cmd == "TEST")
    {
      digitalWrite(D1, 1);
    }

    if (cmd == "ON")   // Turn on lamp
    {
      // send HTML request to Sonoff S20 slave esp8266
    }
  }
}


What I could need som help with is how to execute a HTML request from this sketch to another ESP (which has a static IP address on my LAN).  That would be a wifi controlled power outlet like this https://randomnerdtutorials.com/reprogram-sonoff-smart-switch-with-web-server/.

I can see in the sonoff sketch that a web page like this will be provided :
"<h1>SONOFF Web Server</h1><p><a href=\"on\"><button>ON</button></a>&nbsp;<a href=\"off\"><button>OFF</button></a></p>";

How can I send a HTTP "on" (or "off") command from the master to the slave ? I only need one way communication, the master can just throw away any web page element reply updates from the slave.

Thanks.



Deva_Rishi

check out the BasicHttpClient example from ESP8266HttpClient
To 'Correct' you have to be Correct. (and not be condescending..)

bb328


Go Up