2024-10-13 21:43:41 +02:00
|
|
|
#include "apple.h"
|
2024-10-11 21:15:04 +02:00
|
|
|
|
2024-10-13 21:43:41 +02:00
|
|
|
int app_main() {
|
2024-10-14 00:12:05 +02:00
|
|
|
// 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;
|
2024-10-13 20:15:56 +02:00
|
|
|
}
|
2024-10-13 14:51:02 +02:00
|
|
|
|
2024-10-14 00:12:05 +02:00
|
|
|
void getmac(uint8_t *buf) {
|
|
|
|
// Get MAC address of the WiFi station interface
|
|
|
|
esp_read_mac(buf, ESP_MAC_WIFI_STA);
|
2024-10-13 20:15:56 +02:00
|
|
|
}
|
2024-10-13 14:48:06 +02:00
|
|
|
|
2024-10-14 00:12:05 +02:00
|
|
|
int getUpTime() {
|
|
|
|
// Get system uptime in milliseconds
|
|
|
|
uint32_t uptime = (xTaskGetTickCount() * (1000 / configTICK_RATE_HZ));
|
2024-10-13 20:15:56 +02:00
|
|
|
return uptime;
|
|
|
|
}
|
|
|
|
|
|
|
|
float getTemp() {
|
2024-10-14 00:12:05 +02:00
|
|
|
float temp = 0.0;
|
2024-10-11 18:01:48 +02:00
|
|
|
ds18b20_handler_t sensor;
|
2024-10-13 20:15:56 +02:00
|
|
|
|
2024-10-14 00:12:05 +02:00
|
|
|
// 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
|
2024-10-13 20:15:56 +02:00
|
|
|
ds18b20_convert_temp(&sensor);
|
2024-10-14 00:12:05 +02:00
|
|
|
|
|
|
|
// Read the temperature
|
2024-10-13 20:15:56 +02:00
|
|
|
temp = ds18b20_read_temp(&sensor);
|
2024-10-11 14:21:57 +02:00
|
|
|
|
2024-10-14 00:12:05 +02:00
|
|
|
// 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
|
|
|
|
}
|
2024-10-11 21:15:04 +02:00
|
|
|
|
2024-10-14 00:12:05 +02:00
|
|
|
return temp;
|
|
|
|
}
|
2024-10-13 20:15:56 +02:00
|
|
|
|