2024-10-11 21:15:04 +02:00
|
|
|
|
2024-10-11 18:01:48 +02:00
|
|
|
#include "esp_log.h"
|
2024-10-11 14:21:57 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <onewire.h>
|
|
|
|
#include <ds18b20.h> // Die Header-Datei mit DS18B20-Funktionen
|
2024-10-11 18:01:48 +02:00
|
|
|
#include <task.h>
|
2024-10-11 21:15:04 +02:00
|
|
|
#include <esp_wifi.h>
|
2024-10-13 14:51:02 +02:00
|
|
|
#include <FreeRTOSConfig.h>
|
2024-10-11 21:15:04 +02:00
|
|
|
|
|
|
|
struct appldata;
|
2024-10-13 20:15:56 +02:00
|
|
|
float getTemp();
|
|
|
|
int getUpTime();
|
|
|
|
void getmac();
|
|
|
|
|
2024-10-13 14:48:06 +02:00
|
|
|
struct appldata{
|
2024-10-13 20:15:56 +02:00
|
|
|
uint8_t mac;
|
2024-10-13 14:48:06 +02:00
|
|
|
float temp;
|
|
|
|
float battaryVoltage;
|
2024-10-13 20:15:56 +02:00
|
|
|
int upTime;
|
|
|
|
};
|
2024-10-11 21:15:04 +02:00
|
|
|
|
|
|
|
|
2024-10-13 20:15:56 +02:00
|
|
|
struct appldata app_main() {
|
|
|
|
//tiem delay
|
|
|
|
vTaskDelay(5000 / portTICK_PERIOD_MS);
|
2024-10-13 14:51:02 +02:00
|
|
|
|
2024-10-13 20:15:56 +02:00
|
|
|
//creat var vor mac addres
|
|
|
|
uint8_t baseMac[6] = {0};
|
|
|
|
getmac(baseMac,6);
|
|
|
|
|
|
|
|
|
|
|
|
//fill struct
|
|
|
|
struct appldata send;
|
|
|
|
send.mac = baseMac ;
|
|
|
|
send.upTime = getUpTime();
|
|
|
|
send.temp = getTemp();
|
|
|
|
send.battaryVoltage = 3.3;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//print mac
|
2024-10-11 21:15:04 +02:00
|
|
|
printf("Station MAC: ");
|
2024-10-13 20:15:56 +02:00
|
|
|
for (int i = 0; i < 5; i++) {
|
|
|
|
printf("%02X:", (baseMac[i]));
|
|
|
|
}
|
2024-10-11 21:15:04 +02:00
|
|
|
printf("%02X\n", baseMac[5]);
|
|
|
|
|
2024-10-13 20:15:56 +02:00
|
|
|
//print uptime
|
|
|
|
int uptime = getUpTime();
|
|
|
|
printf("%d", uptime);
|
|
|
|
|
|
|
|
//print temp
|
|
|
|
float temp = getTemp();
|
|
|
|
printf("Temperature = %.4f\n", temp);
|
|
|
|
|
|
|
|
//end func
|
|
|
|
return send;
|
|
|
|
}
|
2024-10-13 14:51:02 +02:00
|
|
|
|
2024-10-11 21:15:04 +02:00
|
|
|
|
|
|
|
|
2024-10-13 20:15:56 +02:00
|
|
|
void getmac(uint8_t *buf, int count){
|
|
|
|
for(int i = 0; i < count; ++i)
|
|
|
|
buf[i] = i;
|
|
|
|
// Get MAC address of the WiFi station interface
|
|
|
|
esp_read_mac(buf, ESP_MAC_WIFI_STA);
|
|
|
|
}
|
2024-10-13 14:48:06 +02:00
|
|
|
|
2024-10-13 20:15:56 +02:00
|
|
|
int getUpTime(){
|
|
|
|
int uptime = (xTaskGetTickCount() * (1000/configTICK_RATE_HZ));
|
|
|
|
|
|
|
|
return uptime;
|
|
|
|
}
|
|
|
|
|
|
|
|
float getTemp() {
|
|
|
|
float temp = 0;
|
2024-10-11 18:01:48 +02:00
|
|
|
// Create variable for handler
|
|
|
|
ds18b20_handler_t sensor;
|
2024-10-13 20:15:56 +02:00
|
|
|
|
2024-10-11 18:01:48 +02:00
|
|
|
// 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
|
|
|
|
}
|
2024-10-13 20:15:56 +02:00
|
|
|
//Print temperature with 4 decimal places
|
2024-10-11 18:01:48 +02:00
|
|
|
// (12 bit resolution measurement accuracy is 0.0625 Celsius)
|
2024-10-13 20:15:56 +02:00
|
|
|
//ESP_LOGI("TAG", "Temperature = %.4f", temp);
|
|
|
|
// Initalize conversion
|
|
|
|
ds18b20_convert_temp(&sensor);
|
|
|
|
temp = ds18b20_read_temp(&sensor);
|
2024-10-11 18:01:48 +02:00
|
|
|
|
2024-10-13 20:15:56 +02:00
|
|
|
return temp;
|
2024-10-11 14:21:57 +02:00
|
|
|
|
|
|
|
}
|
2024-10-11 21:15:04 +02:00
|
|
|
|
2024-10-13 20:15:56 +02:00
|
|
|
|