32#ifdef ARDUINO_ARCH_ESP32
48const char *udpAddress =
"Your_UDP_IP";
49const int udpPort = 3333;
50const char *ssid =
"Your_SSID";
51const char *password =
"Your_PASSWORD";
62 WiFi.begin(ssid, password);
63 while (WiFi.status() != WL_CONNECTED) {
65 Serial.println(
"Connecting to WiFi...");
67 Serial.println(
"Connected to WiFi!");
68 Serial.print(
"IP Address: ");
69 Serial.println(WiFi.localIP());
71 udp.begin(WiFi.localIP(), udpPort);
72 Serial.println(
"UDP started");
75 Serial.println(
"Failed to AXP2602 - check your wiring!");
80 Serial.println(
"Init AXP2602 Sensor success!");
144 uint32_t startMeasTime = millis();
148 uint32_t endMesTime = millis();
150 udp.beginPacket(udpAddress, udpPort);
152 udp.print(
"Polling time: "); udp.print(endMesTime - startMeasTime); udp.println(
" ms");
155 udp.print(
"\t- BatteryVoltage:"); udp.print(
gauge.
getVoltage()); udp.println(
" mV");
156 udp.print(
"\t- InstantaneousCurrent:"); udp.print(
gauge.
getCurrent()); udp.println(
" mAh");
157 udp.print(
"\t- InstantaneousCurrentRaw:"); udp.print(
gauge.
getCurrentRaw()); udp.println(
" RAW");
163 udp.print(
"\t- isCharging:"); udp.print(
gauge.
isCharging() ?
"Yes" :
"No"); udp.println();
164 udp.print(
"\t- isDischarging:"); udp.print(
gauge.
isDischarging() ?
"Yes" :
"No"); udp.println();
166 udp.print(
"\t- TimeToFull:"); udp.print(
gauge.
getTimeToFull()); udp.println(
" minutes");
171 Serial.print(
"Polling time: "); Serial.print(endMesTime - startMeasTime); Serial.println(
" ms");
172 Serial.print(
"\t- Sleep: "); Serial.print(
gauge.
isSleepModeEnabled() ?
"Enabled" :
"Disabled"); Serial.println();
173 Serial.print(
"\t- Temperature:"); Serial.print(
gauge.
getTemperature()); Serial.println(
" ℃");
174 Serial.print(
"\t- BatteryVoltage:"); Serial.print(
gauge.
getVoltage()); Serial.println(
" mV");
175 Serial.print(
"\t- InstantaneousCurrent:"); Serial.print(
gauge.
getCurrent()); Serial.println(
" mAh");
176 Serial.print(
"\t- InstantaneousCurrentRaw:"); Serial.print(
gauge.
getCurrentRaw()); Serial.println(
" RAW");
182 Serial.print(
"\t- isCharging:"); Serial.print(
gauge.
isCharging() ?
"Yes" :
"No"); Serial.println();
183 Serial.print(
"\t- isDischarging:"); Serial.print(
gauge.
isDischarging() ?
"Yes" :
"No"); Serial.println();
184 Serial.print(
"\t- TimeToEmpty:"); Serial.print(
gauge.
getTimeToEmpty()); Serial.println(
" minutes");
185 Serial.print(
"\t- TimeToFull:"); Serial.print(
gauge.
getTimeToFull()); Serial.println(
" minutes");
194 Serial.println(
"Low battery detected!");
195 udp.println(
"Low battery detected!");
198 Serial.println(
"Watchdog timer timeout!");
199 udp.println(
"Watchdog timer timeout!");
202 Serial.println(
"Over temperature detected!");
203 udp.println(
"Over temperature detected!");
206 Serial.println(
"State of Charge updated!");
207 udp.println(
"State of Charge updated!");
219 Serial.println(
"===============================================");
227 Serial.begin(115200);
232 Serial.println(
"This example only supports ESP32 platform.");
uint16_t getStateOfCharge() override
Get the battery percentage.
bool begin(SensorCommCustom::CustomCallback callback, SensorCommCustomHal::CustomHalCallback hal_callback)
Begin with custom callback functions.
uint16_t getTimeToFull() override
Get the battery time to full.
bool isSleepModeEnabled()
Check if the AXP2602 chip is in sleep mode.
uint16_t getTimeToEmpty() override
Get the battery time to empty.
bool isDischarging() override
Checks if the battery is discharging.
float getTemperature() override
Get the temperature.
uint16_t getVoltage() override
Get the battery voltage.
float getCurrent() override
Get the actual current value (considering the sampling resistor)
uint8_t getBatteryStatus()
Get the battery health status.
float getThermalDieTemperature()
Get the actual die temperature.
@ IRQ_STATUS_OVER_TEMPERATURE
uint16_t getThermalDieTemperatureRaw()
Get the thermal die temperature.
float getChargingPower()
Get charging power (positive or 0)
int16_t getCurrentRaw()
Get the battery current.
float getDischargingPower()
Get discharging power (positive or 0)
bool refresh() override
Refresh the AXP2602 chip data.
float getAbsolutePower()
Get the absolute power (always positive)
IRQStatus getIRQStatus()
Get the IRQ status.
void clearIRQStatus()
Clear the IRQ status.
bool isCharging() override
Checks if the battery is charging.