#include "apple.h" int app_main() { // Fill struct struct appledata send; getmac(send.mac); send.upTime = getUpTime(); send.temp = getTemp(); send.batteryVoltage = 3.3; printf("Hello \n"); printf("%d\n", send.upTime); printf("%.4f\n", send.temp); // End function 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() { // Get system uptime in milliseconds int uptime = (xTaskGetTickCount() * (1000 / configTICK_RATE_HZ)); return uptime; } float getTemp() { float temp = 0.0; ds18b20_handler_t sensor; // Initialize DS18B20 sensor if (!ds18b20_init(&sensor, GPIO_NUM_2, TEMP_RES_12_BIT)) { ESP_LOGE("DS18B20", "Failed to initialize DS18B20 sensor!"); return -1.0; // Indicate an error with a negative value } // Convert temperature ds18b20_convert_temp(&sensor); // Read the temperature temp = ds18b20_read_temp(&sensor); // Check if the temperature is within a reasonable range for DS18B20 if (temp < -55.0 || temp > 125.0) { ESP_LOGE("DS18B20", "Temperature reading out of range: %.2f", temp); return -1.0; // Indicate invalid reading } return temp; }