mirror of
https://github.com/KevinMidboe/TinyGSM.git
synced 2025-10-29 18:00:18 +00:00
Added battery and temperature functions
This commit is contained in:
@@ -503,7 +503,7 @@ TINY_GSM_MODEM_GET_GPRS_IP_CONNECTED()
|
||||
}
|
||||
|
||||
/*
|
||||
* Battery functions
|
||||
* Battery & temperature functions
|
||||
*/
|
||||
|
||||
// Use: float vBatt = modem.getBattVoltage() / 1000.0;
|
||||
@@ -512,10 +512,11 @@ TINY_GSM_MODEM_GET_GPRS_IP_CONNECTED()
|
||||
if (waitResponse(GF(GSM_NL "+CBC:")) != 1) {
|
||||
return 0;
|
||||
}
|
||||
streamSkipUntil(','); // Skip
|
||||
streamSkipUntil(','); // Skip
|
||||
|
||||
streamSkipUntil(','); // Skip battery charge status
|
||||
streamSkipUntil(','); // Skip battery charge level
|
||||
// return voltage in mV
|
||||
uint16_t res = stream.readStringUntil(',').toInt();
|
||||
// Wait for final OK
|
||||
waitResponse();
|
||||
return res;
|
||||
}
|
||||
@@ -525,12 +526,41 @@ TINY_GSM_MODEM_GET_GPRS_IP_CONNECTED()
|
||||
if (waitResponse(GF(GSM_NL "+CBC:")) != 1) {
|
||||
return false;
|
||||
}
|
||||
stream.readStringUntil(',');
|
||||
streamSkipUntil(','); // Skip battery charge status
|
||||
// Read battery charge level
|
||||
int res = stream.readStringUntil(',').toInt();
|
||||
// Wait for final OK
|
||||
waitResponse();
|
||||
return res;
|
||||
}
|
||||
|
||||
uint8_t getBattChargeState()
|
||||
sendAT(GF("+CBC?"));
|
||||
if (waitResponse(GF(GSM_NL "+CBC:")) != 1) {
|
||||
return false;
|
||||
}
|
||||
// Read battery charge status
|
||||
int res = stream.readStringUntil(',').toInt();
|
||||
// Wait for final OK
|
||||
waitResponse();
|
||||
return res;
|
||||
}
|
||||
|
||||
bool getBattStats(uint8_t &chargeState, int8_t &percent, uint16_t &milliVolts) {
|
||||
sendAT(GF("+CBC?"));
|
||||
if (waitResponse(GF(GSM_NL "+CBC:")) != 1) {
|
||||
return false;
|
||||
}
|
||||
chargeState = stream.readStringUntil(',').toInt();
|
||||
percent = stream.readStringUntil(',').toInt();
|
||||
milliVolts = stream.readStringUntil('\n').toInt();
|
||||
// Wait for final OK
|
||||
waitResponse();
|
||||
return true;
|
||||
}
|
||||
|
||||
float getTemperature() TINY_GSM_ATTR_NOT_AVAILABLE;
|
||||
|
||||
/*
|
||||
* Client related functions
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user