123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- /**
- * @Author: 李建
- * @Date: 2025/5/22 14:40
- * Description: 接入 wifi 后,实现请求天气接口并显示到 UI界面
- * Copyright: Copyright (©) 2025 永续绿建. All rights reserved.
- */
- #include <cJSON.h>
- #include <esp_log.h>
- #include "weather.h"
- #include "system/net_http.h"
- #include "system/miscellaneous_interface.h"
- #include "lvgl_port.h"
- #include "main.h"
- static const char * TAG = "weather";
- static void http_register_callback(char *response, void *user_data) {
- ESP_LOGD(TAG, "http_register_callback");
- if (response != NULL) {
- ESP_LOGD(TAG, "http_register_callback1:%s", response);
- cJSON * root = cJSON_Parse(response);
- cJSON *code = cJSON_GetObjectItemCaseSensitive(root, "code");
- if(code != NULL && code->valueint == 0) {
- ESP_LOGD(TAG, "http_register_callback2");
- cJSON *data = cJSON_GetObjectItem(root, "data");
- cJSON *text = cJSON_GetObjectItemCaseSensitive(data, "text");
- cJSON *temperature = cJSON_GetObjectItemCaseSensitive(data, "temperature");
- cJSON *humidity = cJSON_GetObjectItemCaseSensitive(data, "humidity");
- ESP_LOGD(TAG, "%s", text->valuestring);
- if(guider_ui.screen)
- {
- // lvgl_port_lock(-1);
- // lv_obj_remove_flag(guider_ui.screen_lab_weather_temp, LV_OBJ_FLAG_HIDDEN);
- // lv_obj_remove_flag(guider_ui.screen_labe_weather_name, LV_OBJ_FLAG_HIDDEN);
- // lv_obj_remove_flag(guider_ui.screen_lab_weather_hum, LV_OBJ_FLAG_HIDDEN);
- // lv_label_set_text_static(guider_ui.screen_labe_weather_name, text->valuestring);
- // lv_label_set_text_fmt(guider_ui.screen_lab_weather_temp, "%s°C", temperature->valuestring);
- // lv_label_set_text_fmt(guider_ui.screen_lab_weather_hum, "%s%%", humidity->valuestring);
- // lvgl_port_unlock();
- }
- }
- }
- }
- void request_weather() {
- char device_serial[16];
- get_device_serial(device_serial);
- char url[128] = "";
- sprintf(url, "%s/%s", API_URL, device_serial);
- net_http_config_t config = {
- .callback = http_register_callback,
- .url = url,
- };
- net_http_get(config);
- }
|