@ScruffR !
Thanks for reply and providing the solution. But I have an another problem when I attach the SPARK FUN BATTERY Shield.
When i attach the shield the code does not work. It always says that water alarm is On. I read that Sparkfun Battery shield is a problem here.
I need your help !
Here is the picture:

here is my code:
#include "SparkFunMAX17043/SparkFunMAX17043.h"
#include "application.h"
STARTUP(WiFi.selectAntenna(ANT_AUTO));
#define lowBattery 10
#define WATER_SENSOR D0
double voltage = 0;
double soc = 0;
bool alert;
String data = ""; //used for all publish statements
const char evtName[] = "scruffy_test";
void setup()
{
pins_init();
lipo.begin(); // Initialize the MAX17043 LiPo fuel gauge
lipo.quickStart();
lipo.setThreshold(10); // Set alert threshold to 10%.
}
void loop()
{
int water = isExposedToWater();
Particle.publish(evtName, water ? "on" : "off", PRIVATE);
delay(1000);
voltage = lipo.getVoltage();
soc = lipo.getSOC();
alert = lipo.getAlert()
lipo.begin();
lipo.wake();
lipo.quickStart();
lipo.setThreshold(lowBattery);
if (lipo.getAlert()) Particle.publish("Low Battery", NULL, 60, PRIVATE);
Particle.publish("Status", data.format("Battery %1.2fV %2.1f%% Signal: %ddB" , lipo.getVoltage(), lipo.getSOC(), WiFi.RSSI()), 60, PRIVATE);
System.sleep(WATER_SENSOR, FALLING, 30);
}
void pins_init()
{
pinMode(WATER_SENSOR, INPUT_PULLUP);
}
// determine if we're exposed to water or not
boolean isExposedToWater()
{
return !digitalRead(WATER_SENSOR);
}
Thanks,
Satyen