"Communication" between Client & Server
Posted: Wed Jan 04, 2017 1:58 pm
Hello,
i'm trying to connect two esp8266 in my WLAN, but i dont get it.
I want, that the first esp8266 open the url (ip) of the other esp and so write a Pin=HIGH.
I read other posts and try the examples, but they didnt work.
Code for the Server:
Part of the Code from the Client
I get for the Get request:
I hope someone can help me, i'm really losing hope.
Sorry for my bad english
i'm trying to connect two esp8266 in my WLAN, but i dont get it.
I want, that the first esp8266 open the url (ip) of the other esp and so write a Pin=HIGH.
I read other posts and try the examples, but they didnt work.
Code for the Server:
Code: Select all
#include <ESP8266WiFi.h>
#include<WiFiClient.h>
#include<ESP8266WebServer.h>`
const char* ssid = "";
const char* password = "";
ESP8266WebServer server(80);
void handle_led1(){
digitalWrite(2, 1);
server.send(200, "text/plain", String("Led Aus "));
}
void handle_led0(){
digitalWrite(2, 0);
server.send(200, "text/plain", String("Led An "));
}
void setup() {
delay(1000);
Serial.begin(115200);
// prepare GPIO2
pinMode(2, OUTPUT);
digitalWrite(2, 0);
/* You can remove the password parameter if you want the AP to be open. */
WiFi.mode(WIFI_STA); // Esp in STA modus
Serial.println();
Serial.println();
Serial.print("Verbinden mit: ");
Serial.println(ssid);
WiFi.begin(ssid, password);
server.begin();
Serial.println("HTTP server started");
server.on("/led1",handle_led1);
server.on("/led0",handle_led0);
}
void loop() {
server.handleClient();
}
Part of the Code from the Client
Code: Select all
HTTPClient http;
Serial.print("[HTTP] begin...\n");
// configure traged server and url
http.begin("192.168.178.45", 80, "/led0"); //HTTp
int httpCode1 = http.GET();
Serial.print("Get An: ");
Serial.println(httpCode1);
delay(1000);
http.begin("192.168.178.45", 80, "/led1"); //HTTP
int httpCode2 = http.GET();
Serial.print("Get Aus: ");
Serial.println(httpCode2);
delay(1000);
Serial.println();
Serial.println("closing connection");
I get for the Get request:
Code: Select all
[HTTP] begin...
Get An: -1
Get Aus: -1
closing connection
I hope someone can help me, i'm really losing hope.
Sorry for my bad english