Go Down

Topic: wifi and deepsleep in esp8266 not working together  (Read 747 times) previous topic - next topic

sabishaw

Ya?
please do gimme some resources to go for it and please gimme advice related to it,if any?...Thanks

PaulRB

What kind of resources? Have a look at my code here if you like. But I think you have most of the code you need in the sketch you posted earlier (posted incorrectly, by the way). You just need to use it in the correct way, with an understanding of how severs, clients and low power sensor nodes should work.

Advice: don't waste your time, it's not a very useful idea as far as I can see. Use another device as your web server.

Deva_Rishi

You could also send a request to the ESP, "requesting it goes to sleep" at some point you will have to wake it up though.
To 'Correct' you have to be Correct. (and not be condescending..)

sabishaw

Thank you Deva_Rishi...but could you please tell me how exactly can i do that

Deva_Rishi

Code: [Select]
server.on( "/", [] () {

    page = "<h1>DATA FROM SENSORS</h1><h3>Moisture sensor  </h3><h5>" + String(moisture_reading ) + "</h5><h3>Temperature sensor  </h3><h5>" + String(Celcius) + " celcius</h5><h3>LUX sensor  </h3><h5>" + String(lux_value) + " LUX</h5>";

    server.send(200, "text/html", page);

  });
this is the code that gets executed if a request is made.
you could just add the
Code: [Select]
delay(100 );
  ESP.deepSleep(20000);   
after the server.send()
On the other hand it would probably be better to make that conditional, by adding a button to the page using a form and test if the 'button on the page' has been pressed using server.hasArg() & server.arg() I do have to inform you that your page is not properly formatted. There is no header no html open and closing tags etc.. this will cause trouble for most webbrowsers, more so when submitting a form. Also using a String to put the page in is fine, but you should declare it as a local variable. server.on() can also just call a function so it doesn't need to be all within your setup()  this will improve the readability.
Code: [Select]
server.on("/", handleRoot); and define
Code: [Select]
void handleRoot() {
  String page;
}
elsewhere in your code.
To 'Correct' you have to be Correct. (and not be condescending..)

Deva_Rishi

Also i think it might be wise to add a
Code: [Select]
yield(); to your code before telling it to enter deepsleep() as to make sure that at least all wifi handling has been completed.
To 'Correct' you have to be Correct. (and not be condescending..)

sabishaw

Deva_Rishi you are real cool!!!
it really helped and too me miles near to my goal...
now,here is a question:  What this program does is only after client has requested to see data,esp8266 will only  then go to sleep.Say sleep is of 70 mins, after that esp will keep waiting for client,so that it will  go to sleep i.e.  it will keep sucking power!!!.....what to do hereforth ? Also i checked all 3 modes of sleep ,wifi is off in all the 3 cases, is is possible that client can find data whenever he wants to, and by all other times  esp sleeps to save power.....or....can we store data somewhere after intervals of 1 hr and esp goes to sleep,during which if client wishes to log data, he gets to see the last stored data....i think that makes sense!!!:D
Thanks everybody

PaulRB

You have been told the answers to those questions already.

And you are wrong about the 3 power saving modes. In one mode, Light Sleep, the WiFi is on. In normal mode, my Wemos Mini use about 80mA. In Light sleep, they consume 20~25mA. In Modem Sleep, they consume 20mA. In Deep Sleep they consume about 150~200uA.

Deva_Rishi

is it possible that client can find data whenever he wants to, and by all other times  esp sleeps to save power.....
Eh... no !!!!! (i've added the exclamationmarks for clarity, you seem to keep asking the same question over and over..) what you can do is us a request to set the sleep-time up front, but once it's asleep it's asleep until it wakes up.
can we store data somewhere after intervals of 1 hr and esp goes to sleep,during which if client wishes to log data, he gets to see the last stored data....
Yes, ......but on a different device that is awake !!! (again you've asked this before) you can make the ESP log onto a website hosted either on a local device such as a computer or another ESP or on the web using a webserver-service. and query the info from there at any given time. Another ESP, would be the easiest for your plan it can be mains-powered full standalone, locally operated and all, doesn't depend on anyone but yourself. Your can just let the battery powered ESP post it's data and take a nap afterwards.
To 'Correct' you have to be Correct. (and not be condescending..)

sabishaw

Yay...problem solved
heres what I did
i send data to api.thingspeak.com and go to a deep deep ,very deep  sleep,now when client needs data, he gets his data from thingsleep.com via his app.....thanks everybody for your help.....now heres what i learned from you all......i dont know anything>>>.like Deva_Rishi suggested using yield(); ,i have never seen anything like it before....could you please suggest me a place where i can know about syntax and libraries of arduino in detail....for the examples in ide of arduino dont have comments to understand functions.......now google it you may say: i googled server.on  but found nothing relevant, why is () and []  used in server.on......found it nowhere...please gimme some link to resources where i can learn all this in its entirety
Thanks again everyone

Deva_Rishi

I wish i could help you with your quest for info, unfortunately tutorials on the ESP are several but hardly any are good and i struggled as much as you did, mind you not on the forum.. about the server.on("/",[] () {  }); it is a 'declaration of callback function'  .. i think.. i got all the stuff from Tut's as well and once i got a handle on what  server.on("/",functionName); was doing i learned to work with it. One of the things about the ESP is that there are so many ways to approach the issue (via AT commands fi) how to use HTML etc I do recommend a book on HTML and you have a lot of the basics of the ESP already. I found out about the yield() via googling some reset issues i was having and that fixed my code !! I had already passed a hurdle before when i could work out a reset occurring until i came to the conclusion that an accidental division by 0 on an ESP causes a reset, it probably should on an Arduino as well but it doesn't. That the EEPROM needs the .begin() .commit() and .end() functions called to function on an ESP and sorts, good luck you managed congrats !
To 'Correct' you have to be Correct. (and not be condescending..)

Go Up