ESP32 CPU Temperature

If you are asking a question, please follow this template:

  1. My goal is: How to know current cpu temperature of ESP32 controller.
  2. My actions are: I am tried finding it in official documentation and googling for the same.
  3. The result I see is: I able to get the cpu frequency from of the function mentioned in official documentation.
  4. My expectation & question is: If it is possible to achieve with mongoose os, please let me know.

Thanks and regards
Lokesh CJ

There was an undocumented function provided by the idf-sdk which seems to be obsolete/unsupported.

I don’t know if works right now:

#ifdef __cplusplus
extern "C" {
#endif
extern uint8_t temprature_sens_read();
#ifdef __cplusplus
}
#endif

To use it

uint8_t temp = temprature_sens_read();
float temp_celsius = (temp - 32.0) / 1.8;

And yes, it is temprature, not temperature;

I seem to get some random output perhaps something I’m doing wrong???

main.c:
extern uint8_t temprature_sens_read();

float esp_temp(void)  {
	float temp_celsius = (temprature_sens_read() - 32.0) / 1.8;
	return temp_celsius;
}

init.js

let esp_Temperature = function() {
	let temp_celsius = ffi('float esp_temp()');
	return temp_celsius;
};
 print('ESP Temperature:', esp_Temperature());

output

ESP Temperature: <???-562948879897648>

any ideas??

Invoke temp_celsius function:

return temp_celsius();
1 Like

doh what was I thinking removed function and just exposed c call
just for future reference for other people

main.c

 extern uint8_t temprature_sens_read();

    float esp_temp(void)  {
    	uint8_t t= temprature_sens_read();
    	//LOG(LL_INFO, ("ESP T d= %d", t));
    	//LOG(LL_INFO, ("ESP T u= %u", t));
    	float temp_celsius = (float)(t - 32.0) / 1.8;
    	return temp_celsius;
    }

init.js

let temp_celsius = ffi('float esp_temp()');

print('ESP Temperature:', temp_celsius());

it works !! thanks