- Wed Oct 19, 2016 9:31 am
#56762
Hello, I have been trying to connect two ESP Module for send a character "c" from Module A to Module B but I don't do nothing yet. I tried with OGMrStinky and Stoney code and nothing, the answer is connection failed...
In my project I just want to send one digit from Module A to Module B, if this is possible without TCP/IP or other thing complicated is better for me.
Thank you in advance.
I appreciate so much your help
//=================
server
//=================
#include <WiFiClient.h>
#include <ESP8266mDNS.h>
//================================================
#include <ESP8266WiFi.h>
const char *ssid = "abc";
MDNSResponder mdns; //stoney
WiFiServer server(80);
void setup() {
WiFi.disconnect(); //stoney
delay(1000);
Serial.begin(115200);
Serial.println();
Serial.print("Configuring access point...");
WiFi.mode(WIFI_STA); //stoney
WiFi.softAP(ssid);
while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); }
Serial.println("done");
IPAddress myIP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(myIP);
server.begin();
Serial.println("HTTP server started");
}
void loop() {
mdns.update(); // Check for any mDNS queries and send responses
WiFiClient client = server.available(); // Check if a client has connected
if (!client) {
//return (NOCLIENT);
Serial.println("NOCLIENT");
}
Serial.println("");
Serial.println("New client");
// Wait for data from client to become available
while (client.connected() && !client.available()) {
delay(1);
}
// Read the first line of HTTP request
String req = client.readStringUntil('\r');
}
//==================
client
//==================
#include <WiFiClient.h>
#include <ESP8266mDNS.h>
//================================
#include <ESP8266WiFi.h>
const char* ssid = "abc";
MDNSResponder mdns; //stoney
WiFiServer server(80); //stoney
IPAddress host(192,168,4,1);
void setup() {
WiFi.disconnect(); //stoney
Serial.begin(115200);
delay(100);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.mode(WIFI_STA); //stoney
WiFi.begin(ssid);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
int position = 0;
void loop() {
WiFiClient client;
const char* host = "192.168.4.1";
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}
String url = "/";
url += "?pos=";
url += String(position);
Serial.print("Requesting URL: ");
Serial.println(url);
// This will send the request to the server
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
delay(10);
while (client.available()) {
String line = client.readStringUntil('\r');
// String line = client.readStringUntil("</html>");
Serial.println(line);
int addr_start = line.indexOf("value=\"");
int addr_end = line.indexOf('\"', addr_start + 7);
if (addr_start == -1 || addr_end == -1) {
Serial.print("no data in line");
}
else {
String req = line.substring(addr_start + 7, addr_end);
Serial.print("start: ");
Serial.println(addr_start);
Serial.print("end: ");
Serial.println(addr_end);
Serial.print("Possy: ");
Serial.println(req);
}
}
Serial.println();
Serial.println("closing connection");
}