English
English
简体中文
Register
Log In
English
English
简体中文
Register
Log In
Language
English
English
简体中文
Register
Log In

How do IPC devices request weather data?

Last Updated on2024-09-19 02:40:37
QueryAttachmentSupported weather codes
Interface 1
/**** Custom HTTP(S) interaction request
api_name: Interface name agreed with the server
api_version: Version of the interface used, such as 1.0 2.0
message: The data content that needs to be reported from the device to the server in the interface, usually in JSON format string
result: The message returned by the server, which will dynamically allocate space within this function. After processing the result externally, the Free interface needs to be called to release the memory
****/
OPERATE_RET http_gw_ipc_custom_msg(IN CONST CHAR_T *api_name, IN CONST CHAR_T *api_version, IN CONST CHAR_T *message, OUT cJSON **result);
Interface 2
/** * @brief iot_httpc_common_post_simple * * @param[in] api_name * @param[in] api_ver * @param[in] post_data * @param[in] p_head_other * @param[out] pp_result * * @return OPERATE_RET */ OPERATE_RET iot_httpc_common_post_simple(IN CONST CHAR_T *api_name, IN CONST CHAR_T *api_ver, IN CHAR_T *post_data, IN CONST CHAR_T *p_head_other, OUT ty_cJSON **pp_result);
Request Example
#define WEATHER_API "thing.weather.get"
#define API_VERSION "1.0"
#define POST_WEATHER_REAL_TIME "{\"codes\": [\"w.currdate\",\"w.humidity\",\"w.conditionNum\",\"w.pressure\",\"w.uvi\",\"w.windDir\",\"w.windSpeed\",\"w.sunrise\",\"w.sunset\",\"w.temp\",\"c.city\",\"c.area\",\"t.local\"]}"
#define POST_WEATHER_FORECAST "{\"codes\": [\"w.date.2\",\"w.conditionNum\",\"w.pressure\",\"w.uvi\",\"w.windDir\",\"w.windSpeed\",\"w.sunrise\",\"w.sunset\",\"c.city\",\"c.area\",\"t.local\"]}"
#define POST_CONTENT POST_WEATHER_REAL_TIME
/**
* @brief http task
*
* @param[in] param:Task parameters
* @return none
*/
VOID example_iot_http(INT_T argc, CHAR_T *argv[])
{
OPERATE_RET rt = OPRT_OK;
ty_cJSON* result = NULL;
CHAR_T *print_data = NULL;
TUYA_CALL_ERR_LOG(iot_httpc_common_post_simple(WEATHER_API, API_VERSION, POST_CONTENT, NULL, &result));
if (NULL == result) {
TAL_PR_DEBUG("result is NULL");
return;
}
print_data = ty_cJSON_PrintUnformatted(result);
if (NULL != print_data) {
TAL_PR_NOTICE("%s", print_data);
ty_cJSON_FreeBuffer(print_data);
print_data = NULL;
}
ty_cJSON_Delete(result);
result = NULL;
return;
}

Click for services and help

Help Center