Hi,
To get the temperature, a critical point to properly account for constraints. Maybe this link help
https://manual.gromacs.org/current/reference-manual/algorithms/molecular-dynamics.html)
Also the following discussions, may be useful to cross check your approach.
\Alessandra