Hey everyone, so i am currently working on a project known as distance lamps, basically you and your significant other each have one, in your house or wherever and they're connected to the internet. When a button is pressed it turns on the opposing lamps light, letting that person know you're thinking of them. My issue is, i have no problem getting the lights to work, its the sending of data over the internet. all i'm really sending is a 1 or a 0 to turn on the lamp. ive followed tutorials that supposedly send data over the internet but they don't work as it should, most of them were local hosts, and the ones that were said to work anywhere in the world, i couldn't get working... does anyone have any idea where i should start? I'm new to these esp8266 modules, but i didn't think it would be this complicated to send some 1's and 0's.
By the way, sorry i didn't upload any code to show what i've done, i packed up about an hour ago and just remembered about this forum...most of the tutorials were along the lines of this or slightly different: https://www.geekstips.com/two-esp8266-communication-talk-each-other/
I will try to send some code tomorrow, thanks in advance everyone!
Okay so im currently trying to implement this, but i cant even get my current code running, i have no idea what im doing wrong...ive been deleting sections and redoing other parts, i think i may have messed it up... how would i implement what you suggested into my current code? or would i have to do something completely different.
CLIENT
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
const char *ssid = "banana";
const char *password = "00000000";
ESP8266WebServer server(80);
void handleSentVar() {
if (server.hasArg("activate")) { // this is the variable sent from the client
int readingInt = server.arg("activate").toInt();
char readingToPrint[5];
server.send(200, "text/html", "Data received");
}
}
void setup() {
delay(1000);
WiFi.softAP(ssid, password);
IPAddress myIP = WiFi.softAPIP();
server.on("/data/", HTTP_GET, handleSentVar); // when the server receives a request with /data/ in the string then run the handleSentVar function
server.begin();
}
void loop() {
server.handleClient();
}
SERVER
#include <ESP8266WiFi.h>
const char *ssid = "banana";
const char *password = "00000000";
void setup() {
Serial.begin(115200);
delay(10);
// Explicitly set the ESP8266 to be a WiFi-client
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
}
void loop() {
char intToPrint[5];
// Use WiFiClient class to create TCP connections
WiFiClient client;
const char * host = "192.168.4.1";
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}
// We now create a URI for the request. Something like /data/?sensor_reading=123
String url = "/data/";
url += "?activate=";
url += intToPrint;
// 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");
unsigned long timeout = millis();
while (client.available() == 0) {
if (millis() - timeout > 5000) {
Serial.println(">>> Client Timeout !");
client.stop();
return;
}
}
delay(500);
}
"ive followed tutorials that supposedly send data over the internet but they don't work as it should, most of them were local hosts, and the ones that were said to work anywhere in the world, i couldn't get working... does anyone have any idea where i should start?"
Well, the "anywhere in the world" would probably take a lot of work and may be a bit of fantasy thinking. The wifi boards can probably run both client and server code t the same time, but they either be connected to an established common network or connected as APs. Beyond that each board would have to connect to an internet connected open wifi system, then establish where each is on the internet, possibly using a dynamic IP service. Just sending a cell phone text might be easier with a vibrate notification. One other option might be to use two cell phones as hot spots and communicate thru them.