Facing a weird issue while reading data from esp8266.
I am trying to read dynamic data from a demo text file on test server on same network in deep sleep mode.
Case1: Joining new network
I am using WifiManager to join network and then followed by http.get() However whenever i try to join the wifi with correct credentials it does not connect sometimes. Post some time ,if i try to wake the device it automatically connects and displays the data.
Case2: Rejoining existing network
Similar issue happens when i stop the test server and update the text file contents and up the server and try to read it on esp8266. It ask me the credentials again which it should have remembered 1st time. Post some time, if i try to wake up device sometimes it automatically connnects and prints updated value.
I am unable to figure out the problem here and its solution. Any suggestion please.
#include <WiFiManager.h>
#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <Arduino.h>
#include <ESP8266httpUpdate.h>
ESP8266WiFiMulti WiFiMulti;
HTTPClient http;
WiFiManager manager;
int publishPin = 0;
int wifiPin = 5;
unsigned int baud = 115200;
const char* url3 = "192.168.43.215";
const int httpsPort = 80;
const String macValue = WiFi.macAddress();
void publishData()
{
String link = "/one.txt";
Serial.print("connecting to ");
Serial.println(url3);
http.begin("http://192.168.43.215/one.txt");
int httpCode = http.GET();
if (httpCode > 0) {
if (httpCode == HTTP_CODE_OK) {
Serial.println("This device is authorized!");
Serial.println(http.getString());
Serial.println(httpCode);
}else {
Serial.println("Failed to connect to API.");
Serial.println(httpCode);
return;
}
http.end();
delay(1000);
}
void restPublish(){
Serial.println("Rest publish");
publishData();
}
void setup()
{
Serial.begin(115200);
Serial.println("setup2");
manager.autoConnect("espdevice");
restPublish();
Serial.println("entering deepsleep now. DND");
ESP.deepSleep(0);
}
void loop()
{
}