add working struct
This commit is contained in:
parent
24d90b45bf
commit
cb9a85a9e8
1 changed files with 61 additions and 36 deletions
|
@ -9,65 +9,90 @@
|
|||
#include <FreeRTOSConfig.h>
|
||||
|
||||
struct appldata;
|
||||
/*
|
||||
float getTemp();
|
||||
int getUpTime();
|
||||
void getmac();
|
||||
|
||||
struct appldata{
|
||||
uint8_t mac[6];
|
||||
uint8_t mac;
|
||||
float temp;
|
||||
float battaryVoltage;
|
||||
unsigned long upTime;
|
||||
}
|
||||
*/
|
||||
int app_main() {
|
||||
int upTime;
|
||||
};
|
||||
|
||||
|
||||
// Variable to store the MAC address
|
||||
uint8_t baseMac[6];
|
||||
struct appldata app_main() {
|
||||
//tiem delay
|
||||
vTaskDelay(5000 / portTICK_PERIOD_MS);
|
||||
|
||||
long uptime = (xTaskGetTickCount() * (1000/configTICK_RATE_HZ));
|
||||
|
||||
// Get MAC address of the WiFi station interface
|
||||
esp_read_mac(baseMac, ESP_MAC_WIFI_STA);
|
||||
//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
|
||||
printf("Station MAC: ");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
printf("%02X:", baseMac[i]);
|
||||
}
|
||||
for (int i = 0; i < 5; i++) {
|
||||
printf("%02X:", (baseMac[i]));
|
||||
}
|
||||
printf("%02X\n", baseMac[5]);
|
||||
|
||||
printf( "Uptime = %d\n", (xTaskGetTickCount() * (1000/configTICK_RATE_HZ)));
|
||||
//print uptime
|
||||
int uptime = getUpTime();
|
||||
printf("%d", uptime);
|
||||
|
||||
//print temp
|
||||
float temp = getTemp();
|
||||
printf("Temperature = %.4f\n", temp);
|
||||
|
||||
//end func
|
||||
return send;
|
||||
}
|
||||
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
float temp = 0;
|
||||
printf("hit");
|
||||
for(int i = 0; i < 30; ++i) {
|
||||
// Initalize conversion
|
||||
ds18b20_convert_temp(&sensor);
|
||||
temp = ds18b20_read_temp(&sensor);
|
||||
vTaskDelay(5000 / portTICK_PERIOD_MS);
|
||||
printf("\n");
|
||||
printf( "Temperature = %.4f\n", temp);
|
||||
printf( "Uptime = %d", (xTaskGetTickCount() * (1000/configTICK_RATE_HZ)));
|
||||
};
|
||||
|
||||
// Print temperature with 4 decimal places
|
||||
//Print temperature with 4 decimal places
|
||||
// (12 bit resolution measurement accuracy is 0.0625 Celsius)
|
||||
ESP_LOGI("TAG", "Temperature = %.4f", temp);
|
||||
//ESP_LOGI("TAG", "Temperature = %.4f", temp);
|
||||
// Initalize conversion
|
||||
ds18b20_convert_temp(&sensor);
|
||||
temp = ds18b20_read_temp(&sensor);
|
||||
|
||||
return temp;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue