Issue with httpclient when using WiFi.off or Spark.sleep

Hi,

Im having fun with my new spark core but Im stuck on this issue for 2 days now:

I have a simple code that use a http post request. This works fine but in order to conserve battery, I would like to use the Sleep modus. When using Sleep (in different modes) or WiFi.off(), the httpclient connection always failes and the sleep mode doesnt work as described in the documentation. Any suggestions? Thanks !!

   // This #include statement was automatically added by the Spark IDE.
#include "HttpClient/HttpClient.h"
#include "application.h"


HttpClient http;

http_header_t headers[] = {
     
    { NULL, NULL } // NOTE: Always terminate headers will NULL
};
http_request_t request;
http_response_t response;

void setup() {
    
    RGB.control(true);  // Turn down for what? The status light is crazy bright = wasted mAh battery.
    RGB.brightness(10); // This sets the RGB LED brightness : 0-256
    RGB.control(false); // release the LED to the system
    
    request.hostname = "dweet.io";
    request.port = 80;
    Serial.begin(9600);

}

void loop() {
    
    delay(10000);  
    request.path = "/dweet/for/atest?Temperature=25";
    request.body = "";
    http.post(request, response, headers);
    //Serial.println(response.body);
    
    
    

    WiFi.off();
    Serial.println("putting core into sleep");
    delay(10000);
    Serial.println("and back on ....");
    WiFi.on();
    
    
   // Spark.sleep(10);
  // Spark.sleep(SLEEP_MODE_DEEP, 10);

}

@K_Tem, what are you expecting sleep to do in your app?

The idea is to reduce battery consumption (core consumes a 380MAh battery in c. 2 hours)

Thanks !

@K_Tem, I'd repeat and try to reword @peekay123 's question.

What exactly do you mean with this, what do the docs state what sleep doesn't do?
What do you expect either of your commented sleep calls to do and what do they do and what not?

from the doc, I’m assuming that sleep (or WiFi.off() and on()) will shut down the CC3000 for X seconds, without affecting the rest of the code (I’m aware that sleep isnt blocking the code)

thank you for time!

The issues I have are:
(i) when adding these statements, connection to a httpclient fails (even when adding a delay)
(ii) the led doesnt change when using wifi.off/on or Spark.sleep, while I’m assuming that reconnecting to the wifi should result in a green flashing led?
(iii) I cant flash the core anymore from the web IDE when using wifi.on/off or sleep in the code, and I need to go back to factory settings each time.

So, I’m not sure that sleep (or wifi.off/on) is doing what I think it should do. Maybe you can point me towards a method to test whether sleep and wifi commands are working?

One thing I’d suggest when thinking of disabling WiFi is to go for SYSTEM_MODE(SEMI_AUTOMATIC) rather than default AUTOMATIC
And just turning WiFi back on, does not automatically reconnect WiFi and even less to the cloud - hence your problem with OTA flashing.

If you want to reconnect to WiFi only, you’d need to WiFi.connect(), or if you want the cloud features (e.g. OTA flashing) you’d need Spark.connect()

The official docs are a good place to look :wink:
http://docs.spark.io/firmware/#wifi-connect
http://docs.spark.io/firmware/#spark-connect


It’s not sleep that’s causing the problem, but your use of WiFi.on() without the required next steps.

The issues with different sleep modes and WiFi.on/off were solved after doing a full firmware upgrade:
http://support.spark.io/hc/en-us/articles/203108844-Perform-a-Full-Firmware-Upgrade

not easy to find for a beginner! maybe a link to this upgrade could be usefull in the getting started/firmware sections?