Hi everybody
i am working with nodemcu to make a data logger which is working well,:i makes a web page ,which can be reached by its ip address,..but when i put ESP.deepsleep(20e6); the web page is not created....strange! can someone please help me here
heres the code:
#include <Wire.h>
#include <SparkFunTSL2561.h> // library for luminosity sensor
#include <ESP8266WebServer.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <OneWire.h>
#include <DallasTemperature.h> // library for temperature sensor
#define sleepTime 5
//temp related info
int temperature_pin = D3; // often dosent work if pin is otherthan D3 or D4..........
OneWire oneWire(temperature_pin);
DallasTemperature sensors(&oneWire);
double Celcius = 0.00;
//moisture sensor related info
int moisture_pin = A0;
int moisture_reading;
// luminosity related info
//create object LUX
SFE_TSL2561 LUX;
double lux_value;
//following three are parameters for function getTiming
//and have these particular datatypes with few predefined values
//which have their already meant purpose
unsigned char timer = 2;
unsigned int ms;
boolean sensitivity;
//username and password for net connection,which esp shall search for
char *username = "corph", *password = "corph@786";
double moisture_data;
//80=http
ESP8266WebServer server(80);
String page;
void setup() {
// put your setup code here, to run once:
pinMode(moisture_pin, INPUT);
Serial.begin(115200);
WiFi.begin(username, password);
// ds18b20 must be taken in parasitic mode or pull up resistor should be defined
//observed: it works if none of the above is done,...but some narrate it gets hot if not done so
//no proceeding till wifi connection is established
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print("-");
}
Serial.println("Connected to Wifi \nAll info shall be on the website");
Serial.println("connected to");
Serial.println(username);
Serial.println("IP ADDRESS");
//IP should be noted and followed in browser
Serial.println(WiFi.localIP());
//creating an html web page, also sendind data to it.....(gets executed after "server.handleClient();" ststement in loop)
server.on( "/", [] () {
page = "
DATA FROM SENSORS
Moisture sensor
" + String(moisture_reading ) + "
Temperature sensor
" + String(Celcius) + " celcius
LUX sensor
" + String(lux_value) + " LUX
";server.send(200, "text/html", page);
});
server.begin();
}
void loop() {
// put your main code here, to run repeatedly:
// calling functions to collect data
moisture();
temperature();
lux();
server.handleClient();
// taking a nap to save battries
delay(100 );
ESP.deepSleep(20000);
}
//functions for particular sensor
void moisture() {
moisture_reading = analogRead(moisture_pin);
//changing voltage (data) form sensor to percentage
moisture_reading = map(moisture_reading, 1024, 0, 0, 100);
}
void temperature() {
sensors.begin();
sensors.requestTemperatures();
Celcius = sensors.getTempCByIndex(0);
}
void lux() {
LUX.begin();
LUX.setTiming(sensitivity, timer, ms);
LUX.setPowerUp();
unsigned int data1, data2;
LUX.getData(data1, data2);
// data1 and data2 corresponds to data of lingt and infrared rays,
//passing them to following function, unaltered, gives luminosity
LUX.getLux(sensitivity, ms, data1, data2, lux_value); // this function is of boolean type
}