Troubleshoot - Firebeetle wifi wont run on battery
![userHead](https://dfimg.dfrobot.com/dfPortrait2.png)
Hi all,
I've been trying to create a smart garden sensor for some time now, that runs off solar and a battery. The code runs in 3 seconds, and I only need to take data every 10-30 minutes. I can't for the life of me figure out why I can't get an esp32 to run off a battery with wifi connectivity. 3.7V Lipo is connected to TP4056, connected to 5V booster and then via usb into the ESP32. When I do this, the firebeetle LED just blinks rapidly and nothing happens.
I dont think code error is the problem - when connected to USB wall power, the device works as intended and data comes through to the database.
From previous reading - some people have had issues with ESP modules and wifi causing brownouts.. I'm wondering if this is where the problem lies. However it also seems some people have identical setups that just work...
- When changing the code to a simple blink - the device runs on battery fine
Attempted other fixes:
- Initially I thought the problem was my cheap chinese ESP32 using too much power, so I changed to a more reliable Firebeetle but the same problem persists.
- Tried increasing the lipo battery size from 2000mAh (which I thought would be enough) to 3500mAh.
- Tried a number of code changes to disable brownouts
- Direct battery connection to ESP32 using plug - same result
SKU - DFR0478 Firebeetle ESP32
IDE - Arduino 1.8.8
Intended function as described
Libraries - see code
For context, I have a rudimentary understanding of electronics and code. I've managed to get a whole bunch of prototype devices working including house data sensors and a fridge controller that feed information like temp and humidity through MQTT, influxdb and openHab. I'm usually pretty good at problem solving but now I'm stumped.
I've been trying to create a smart garden sensor for some time now, that runs off solar and a battery. The code runs in 3 seconds, and I only need to take data every 10-30 minutes. I can't for the life of me figure out why I can't get an esp32 to run off a battery with wifi connectivity. 3.7V Lipo is connected to TP4056, connected to 5V booster and then via usb into the ESP32. When I do this, the firebeetle LED just blinks rapidly and nothing happens.
I dont think code error is the problem - when connected to USB wall power, the device works as intended and data comes through to the database.
From previous reading - some people have had issues with ESP modules and wifi causing brownouts.. I'm wondering if this is where the problem lies. However it also seems some people have identical setups that just work...
- When changing the code to a simple blink - the device runs on battery fine
Attempted other fixes:
- Initially I thought the problem was my cheap chinese ESP32 using too much power, so I changed to a more reliable Firebeetle but the same problem persists.
- Tried increasing the lipo battery size from 2000mAh (which I thought would be enough) to 3500mAh.
- Tried a number of code changes to disable brownouts
- Direct battery connection to ESP32 using plug - same result
SKU - DFR0478 Firebeetle ESP32
IDE - Arduino 1.8.8
Intended function as described
Libraries - see code
For context, I have a rudimentary understanding of electronics and code. I've managed to get a whole bunch of prototype devices working including house data sensors and a fridge controller that feed information like temp and humidity through MQTT, influxdb and openHab. I'm usually pretty good at problem solving but now I'm stumped.
Code: Select all
Any ideas?!
#include <ArduinoJson.h>
#include <WiFi.h>
#include <Wire.h>
#include <Adafruit_BMP085.h>
#include <PubSubClient.h>
#define uS_TO_S_FACTOR 1000000 /* Conversion factor for micro seconds to seconds */
#define sleepTime 10 /* Time ESP32 will go to sleep (in seconds) */
#include "soc/soc.h"
#include "soc/rtc_cntl_reg.h"
Adafruit_BMP085 bmp;
const char* ssid = "mywifi";
const char* password = "mypw";
const char* mqtt_server = "192.blahblah";
WiFiClient Garden;
PubSubClient client(Garden);
//int readTime = 0;
//int sampleLength = 10000;
float tempAir;
float tempAirPrev;
int pressure;
int soilPercent;
int lightPercent;
int lightLevel;
int soilMoisture;
int uvLevel;
void setup_wifi()
{
delay(10);
// We start by connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
if (!bmp.begin()) {
Serial.println("Could not find a valid BMP085/BMP180 sensor, check wiring!");
}
}
void reconnect() {
// Loop until we're reconnected
while (!client.connected()) {
Serial.print("Attempting MQTT connection...");
// Create a random client ID
String clientId = "ESP8266Client-";
clientId += String(random(0xffff), HEX);
// Attempt to connect
if (client.connect(clientId.c_str())) {
Serial.println("connected");
//client.subscribe("garden");
} else {
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
// Wait 5 seconds before retrying
delay(5000);
}
}
}
void setup() {
WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); //disable brownout detector
if (Serial) {
Serial.begin(9600);
}
setup_wifi();
client.setServer(mqtt_server, 1883);
if (!client.connected()) {
reconnect(); //this returns to the void reconnect loop
}
bmp_read();
soil_read();
light_read();
uv_read();
package_json();
Serial.println("Sleeping.......");
esp_sleep_enable_timer_wakeup(sleepTime * uS_TO_S_FACTOR);
esp_deep_sleep_start();
}
void loop()
{
}
void bmp_read() {
tempAir = bmp.readTemperature();
Serial.print("Temperature = ");
Serial.print(tempAir);
Serial.print(" *C");
Serial.print("\n\r");
pressure = bmp.readPressure();
Serial.print("Pressure = ");
Serial.print(pressure);
Serial.println(" Pa");
Serial.print("Pressure at sealevel (calculated) = ");
Serial.print(bmp.readSealevelPressure());
Serial.println(" Pa");
delay(500);
}
void soil_read() {
soilMoisture = analogRead(A0);
soilPercent = 100 - ((soilMoisture - 1400) / 26.95);
Serial.print("Soil moisture at ");
Serial.println(soilMoisture);
Serial.print("Estimated ");
Serial.print(soilPercent);
Serial.println("%");
}
void light_read() {
lightLevel = analogRead(A7);
lightPercent = map(lightLevel, 0, 4095, 0, 100);
Serial.print("Light level at ");
Serial.println(lightLevel);
Serial.print("Estimated ");
Serial.print(lightPercent);
Serial.println("%");
}
void uv_read() {
uvLevel = analogRead(A4);
Serial.print("UV level at ");
Serial.println(uvLevel);
}
void package_json() {
const int capacity = JSON_OBJECT_SIZE(200);
StaticJsonDocument<200> doc;
doc["device"] = "sensorr";
doc["Temp"] = tempAir;
//doc["Humidity"] = 0;
doc["Pressure"] = (pressure / 100);
doc["Light"] = lightLevel;
doc["LightPercent"] = lightPercent;
doc["UV"] = uvLevel;
doc["SoilMoisture"] = soilMoisture;
char output[200];
serializeJson(doc, output);
Serial.println("Sending message to MQTT topic..");
Serial.println(output);
if (client.publish("garden/data", output) == true) {
Serial.println("Success sending message");
} else {
Serial.println("Error sending message");
}
Serial.println("-------------");
}
2019-04-08 07:13:49 Regarding some power values:
Here's the desired setup
![Image](https://imgur.com/zWRq2Wj)
https://imgur.com/zWRq2Wj
When ESP not connected - power to boost converter = 1.9mA
When connected - power = 162mA
When battery is connected directly to Firebeetle plug - average 180mA - fluctuates between 80mA and 330mA
- note this does NOT correlate with the 10sec sleep cycle
lucian.quach
Here's the desired setup
https://imgur.com/zWRq2Wj
When ESP not connected - power to boost converter = 1.9mA
When connected - power = 162mA
When battery is connected directly to Firebeetle plug - average 180mA - fluctuates between 80mA and 330mA
- note this does NOT correlate with the 10sec sleep cycle
![userHeadPic](https://dfimg.dfrobot.com/dfPortrait2.png)