vshymanskyy / TinyGSM

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

Reading modemTemp gives wrong numbers below 0°C (sim7600) #618

Open agteigarnet opened 2 years ago

agteigarnet commented 2 years ago

Hi I am using TinyGSM for sim7600

When I put my IOT device outside for its purpose I got some strange readings on modemTemp. You can see it cooling down in its box: "modemTemp":12 "modemTemp":9 "modemTemp":7 "modemTemp":5 "modemTemp":3 "modemTemp":1 "modemTemp":0 "modemTemp":65535 "modemTemp":65535 "modemTemp":65534

Looking at my code did not explain the issue as I am using float for all temperature variables. But suspecting somewhere on the way there was some unsigned integer (uint) conversion that broke the values. As the data goes via 3 systems in different clouds it was a bit of a trace.

In the end I found the issue in file: TinyGsmClientSIM7600.h: /*

So changing the uint to int will solve the problem (or float as in some other implementations). Yes devices can operate in less than 0°C :-)