Electron having problems with HTU21D when using SLEEP_NETWORK_STANDBY

I have an Electron and connected the HTU21D temp and humidity sensor to it directly on the D0 and D1 pins.

When I run the sample sketch from https://build.particle.io/libs/53edeb4ccf314539c90003a4/tab/HTU21D.ino then it all works fine, but as soon as I use SLEEP_NETWORK_STANDBY to put the Electron to sleep, then the HTU21D reports 998 values - which is the equivalent of I2C connection errors.
If I use normal sleep (which restarts), then it works.

See code below.

  1. The sample sketch of HTU21D with normal sleep - which sleeps restarts and reconnects to the cloud at each iteration works, at each iteration it reads the correct values from the HTU21D:
    #include "HTU21D/HTU21D.h"
    
    HTU21D htu = HTU21D();
    
    void setup()
    {
    	Serial.begin(9600);
    
    	Serial.println("HTU21D test");
    
    	while(! htu.begin()){
    	    Serial.println("HTU21D not found");
    	    delay(1000);
    	}
    
    	Serial.println("HTU21D OK");
    }
    
    void loop()
    {
    	Serial.println("===================");
    	Serial.print("Hum:"); Serial.println(htu.readHumidity());
    	Serial.print("Temp:"); Serial.println(htu.readTemperature());
    	Serial.println();
    
    	delay(1000);
    
        Particle.publish("L", String::format("2.1,2.22,2.22,%2.2f,%2.2f,1", htu.readHumidity(),htu.readTemperature()));
    	System.sleep(D1, RISING, 10);
    }
  1. But when using the SLEEP_NETWORK_STANDBY then only the first reading of HTU21D shows the right values, then it shows 998 for each reading
   #include "HTU21D/HTU21D.h"
    
    HTU21D htu = HTU21D();
    
    void setup()
    {
    	Serial.begin(9600);
    
    	Serial.println("HTU21D test");
    
    	while(! htu.begin()){
    	    Serial.println("HTU21D not found");
    	    delay(1000);
    	}
    
    	Serial.println("HTU21D OK");
    }
    
    void loop()
    {
    	Serial.println("===================");
    	Serial.print("Hum:"); Serial.println(htu.readHumidity());
    	Serial.print("Temp:"); Serial.println(htu.readTemperature());
    	Serial.println();
    
    	delay(1000);
    
        Particle.publish("L", String::format("2.1,2.22,2.22,%2.2f,%2.2f,1", htu.readHumidity(),htu.readTemperature()));
    	System.sleep(D1, RISING, 10, SLEEP_NETWORK_STANDBY);
    }

Hmm… What happens if you do another round of

while(! htu.begin()){
    	    Serial.println("HTU21D not found");
    	    delay(1000);
    	}

after sleeping? Just an idea. Not sure if it will work.

Thanks for the suggestion, I have just tried this.
The first round is fine - temp and humidity collected, but after sleep when it comes back it never finds the HTU21D, just keep printing the "HTU21D not found" forever.

This is now the new code:

#include "HTU21D/HTU21D.h"

HTU21D htu = HTU21D();

void setup()
{
	Serial.begin(9600);

	Serial.println("HTU21D test");

	while(! htu.begin()){
	    Serial.println("HTU21D not found");
	    delay(1000);
	}

	Serial.println("HTU21D OK");
}

void loop()
{
	Serial.println("===================");
	Serial.print("Hum:"); Serial.println(htu.readHumidity());
	Serial.print("Temp:"); Serial.println(htu.readTemperature());
	Serial.println();

	delay(1000);
    Particle.publish("L", String::format("2.1,2.22,2.22,%2.2f,%2.2f,1", htu.readHumidity(),htu.readTemperature()));
	
	System.sleep(D1, RISING, 10, SLEEP_NETWORK_STANDBY);
	
	while(! htu.begin()){ Serial.println("HTU21D not found"); delay(1000); }
}

Results on serial:

Opening serial monitor for com port: "/dev/ttyACM0"
HTU21D test
HTU21D OK
===================
Hum:31.09
Temp:26.15

il@laptop ~/firmware/modules $ particle serial monitor
Opening serial monitor for com port: "/dev/ttyACM0"
HTU21D not found
HTU21D not found
HTU21D not found
HTU21D not found
HTU21D not found
HTU21D not found
HTU21D not found
HTU21D not found
HTU21D not found
HTU21D not found
HTU21D not found
HTU21D not found
HTU21D not found

Have you solved this issue? Im having the same problem, when the electron returns from sleeping, all my sensors and sd card won't be found.