diff options
| author | Sadeep Madurange <sadeep@asciimx.com> | 2023-06-21 10:47:31 +0800 |
|---|---|---|
| committer | Sadeep Madurange <sadeep@asciimx.com> | 2023-06-21 10:47:31 +0800 |
| commit | 24d9a11a326dc8e805b177c45bfe23e4675a2e05 (patch) | |
| tree | 57dcbe8367b5dc9556cbdd8de174a143d1d64f65 /main/main.c | |
| parent | 1692d13b27ec91e52269ba33b94ea47840880e4f (diff) | |
| download | esp8266-dht22-weather-station-24d9a11a326dc8e805b177c45bfe23e4675a2e05.tar.gz | |
Copied from sourcehut.
Diffstat (limited to 'main/main.c')
| -rw-r--r-- | main/main.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/main/main.c b/main/main.c new file mode 100644 index 0000000..86e6256 --- /dev/null +++ b/main/main.c @@ -0,0 +1,36 @@ +#include <freertos/FreeRTOS.h> +#include <freertos/task.h> + +#include <esp_event.h> +#include <esp_netif.h> +#include <esp_log.h> + +#include "dht.h" +#include "net.h" + +static const char *tag = "app"; +static const char *topic = "weather-data"; + +void app_main() +{ + char data[5]; + uint16_t rh, tc; + esp_mqtt_client_handle_t client; + + esp_netif_init(); + esp_event_loop_create_default(); + + dht_init(); + wifi_connect(); + client = mqtt_connect(); + + for (;;) { + if (dht_get_data((uint8_t *)data)) { + rh = dht_decode_data(data[0], data[1]); + tc = dht_decode_data(data[2], data[3]); + esp_mqtt_client_publish(client, topic, data, 4, 0, 0); + ESP_LOGI(tag, "temperature: %dC, humidity: %d%%", tc, rh); + } + vTaskDelay(2000 / portTICK_PERIOD_MS); + } +} |
