vshymanskyy / TinyGSM

A small Arduino library for GSM modules, that just works
GNU Lesser General Public License v3.0
1.96k stars 728 forks source link

getBattVoltage returning wrong value - SIM808 and others #369

Closed Alan2git closed 4 years ago

Alan2git commented 4 years ago
Done ## What type of issues is this? [ ] Request to support a new module

[ ] Bug or problem compiling the library [ x] Bug or issue with library functionality (ie, sending data over TCP/IP)

What are you working with?

Main processor board: ESP32 Modem: SIM808 TinyGSM version: 0.10.1 Code: volt=modem.getBattVoltage(); // -> returns garbage value in volt variable

The problem lies in TinyGsmBattery.tpp module, procedure getBatVoltageImpl() uint16_t getBattVoltageImpl() { thisModem().sendAT(GF("+CBC")); if (thisModem().waitResponse(GF("+CBC:")) != 1) { return 0; } thisModem().streamSkipUntil(','); // Skip battery charge status thisModem().streamSkipUntil(','); // Skip battery charge level // return voltage in mV //***** Here is the Problem **** uint16_t res = thisModem().streamGetIntBefore(',');

//**** Should be changed by : **** uint16_t res = thisModem().streamGetIntBefore('\n');
// At least for SIM800 and 900 series, dunno for other modems

// Wait for final OK
thisModem().waitResponse();
return res;

}

Scenario, steps to reproduce

With proposed change I get it. However, the change must be checked with other modems ### Expected result

Correct value of VBat

Actual result

Incorrect value, like 55537 ### AT command log

AT+CBC AT+CBC:0,40,3974

SRGDamia1 commented 4 years ago

Oops, yup, that's definitely a problem and probably the correct fix.