Battery is working fine for me. Here is my test script.
Hardware is just a basic lipo battery attached and two buttons connected to gpio 2/3 and gnd
#include "WiFi.h"
#include <PubSubClient.h>
#define DEBUG_ENABLED 0
const char* ssid = "DronesAreWatching";
const char* password = "";
const char* mqtt_server = "blue.home";
const char* mqttUser = "internal";
const char* mqttPassword = "";
void debug(String msg){
if (DEBUG_ENABLED){
Serial.println(msg);
}
}
WiFiClient espClient;
PubSubClient client(espClient);
void setup_wifi() {
delay(10);
// We start by connecting to a WiFi network
debug("Connecting to ");
debug(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
debug(".");
}
debug("WiFi connected");
debug("IP address: ");
// debug(WiFi.localIP());
}
void setup() {
if (DEBUG_ENABLED){
Serial.begin(115200);
delay(100);
}
pinMode(D0, INPUT_PULLUP);
debug("Startup...send message");
setup_wifi();
client.setServer(mqtt_server, 1883);
client.connect("ESP8266Client", mqttUser, mqttPassword);
uint64_t gpio_reason = esp_sleep_get_gpio_wakeup_status();
debug(String(gpio_reason));
int GPIO = 0;
if (gpio_reason > 0){
GPIO = log(gpio_reason)/log(2);
}
debug(String(GPIO));
String GPIOString = String(GPIO);
int str_len = GPIOString.length() + 1;
char char_array[str_len];
GPIOString.toCharArray(char_array, str_len);
client.publish("mouse/trigger", char_array);
esp_deep_sleep_enable_gpio_wakeup((1ULL << 2), ESP_GPIO_WAKEUP_GPIO_LOW); //GPIO2
esp_deep_sleep_enable_gpio_wakeup((1ULL << 3), ESP_GPIO_WAKEUP_GPIO_LOW); //GPIO3
debug("Going to sleep in 5 seconds"); //time to send message
delay(5000);
if (DEBUG_ENABLED){
Serial.flush();
}
esp_deep_sleep_start();
}
void loop() {
}