Added battery and temperature functions

This commit is contained in:
Sara Damiano
2019-05-22 12:03:09 -04:00
parent 96bbf381ad
commit 880c4614e4
14 changed files with 331 additions and 37 deletions

View File

@@ -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
*/