Hey smart guys, whats up. First time that im begging for help here. First of all thank you for all answers, everything is helpfull.
Guys quick cap, im developing a wearble device, with the ESP8266 and OLED LCD, using arduino IDE.
Basically, im using that BasicHttpClient exemple from IDE, that way i can send request for any URL i want.
[Problem]
But in a wearble device, using wifi, sometime i wont have internet connection or wireless connection available, but i have 2 wireless work in a place. If i walk by these places, sometime the range of one of these will be over but probably i will be inside the other range. Using this examples, when the connection loses with that one, i want connect to other one or stay searching for those two networks. I already try a lot by myself in that code.
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266HTTPClient.h>
#define USE_SERIAL Serial
ESP8266WiFiMulti WiFiMulti;
void setup() {
USE_SERIAL.begin(115200);
// USE_SERIAL.setDebugOutput(true);
USE_SERIAL.println();
USE_SERIAL.println();
USE_SERIAL.println();
for(uint8_t t = 4; t > 0; t--) {
USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
USE_SERIAL.flush();
delay(1000);
}
WiFiMulti.addAP("TI MRE", "zxxzxz");
WiFiMulti.addAP("OTHERWIFI", "dsadsa");
}
void loop() {
// wait for WiFi connection
if((WiFiMulti.run() == WL_CONNECTED)) {
HTTPClient http;
USE_SERIAL.print("[HTTP] begin...\n");
// configure traged server and url
//http.begin("https://192.168.1.12/test.html", "7a 9c f4 db 40 d3 62 5a 6e 21 bc 5c cc 66 c8 3e a1 45 59 38"); //HTTPS
http.begin("http://192.168.1.12/test.html"); //HTTP
USE_SERIAL.print("[HTTP] GET...\n");
// start connection and send HTTP header
int httpCode = http.GET();
// httpCode will be negative on error
if(httpCode > 0) {
// HTTP header has been send and Server response header has been handled
USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);
// file found at server
if(httpCode == HTTP_CODE_OK) {
String payload = http.getString();
USE_SERIAL.println(payload);
}
} else {
USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
}
http.end();
}
delay(10000);
}
I already triend, using a variable as trigger to check first, WiFiMulti.run() != WL_CONNECTED too, tried a function with, a else in "if(httpCode > 0) {}".
Some of those changes that i have made, doesnt work, in some situations the ESP stop that "Guided Loop" and start to send only this:
add 0
aid 5
cnt
state: 5 -> 0 (0)
rm 0
f r0, scandone
f r0, scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 5
cnt
If someone knows something, i appreciate so much. Thank you all for comments.