BoskoopBase/embadet/main/apple.c
2024-10-13 23:51:32 +02:00

53 lines
1 KiB
C

#include "apple.h"
int app_main() {
//fill struct
struct appledata send;
getmac(send.mac) ;
send.upTime = getUpTime();
send.temp = getTemp();
send.battaryVoltage = 3.3;
printf("%.4f",send.temp);
//end func
return 0;
}
void getmac(uint8_t *buf){
// Get MAC address of the WiFi station interface
esp_read_mac(buf, ESP_MAC_WIFI_STA);
}
int getUpTime(){
int uptime = (xTaskGetTickCount() * (1000/configTICK_RATE_HZ));
return uptime;
}
float getTemp() {
float temp = 0;
// Create variable for handler
ds18b20_handler_t sensor;
// Check for any initialization failures
if (!ds18b20_init(&sensor, GPIO_NUM_2, TEMP_RES_12_BIT))
{
ESP_LOGE("TAG", "Failed to initalize DS18B20!");
return 0; // Exit
}
//Print temperature with 4 decimal places
// (12 bit resolution measurement accuracy is 0.0625 Celsius)
//ESP_LOGI("TAG", "Temperature = %.4f", temp);
// Initalize conversion
ds18b20_convert_temp(&sensor);
temp = ds18b20_read_temp(&sensor);
return temp;
}