[Share] TuyaOS Central Control Weather Function Development

Gateway equipment, voice control devices, etc.


Post Reply
pushu
Posts: 13

This topic describes how to get the weather data to display on the screen. The weather service regularly updates the weather data.

Weather data

The SDK supports the following weather data. For more information, see tuya_weather_api.h.

NameIdentifierDescription
TemperatureTY_WEATHER_TEMP_STRUnit: °C
The highest temperatureTY_WEATHER_TEMP_MAX_STRUnit: °C. This variable only applies to countries or regions outside mainland China.
The lowest temperatureTY_WEATHER_TEMP_MIN_STRUnit: °C. This variable only applies to countries or regions outside mainland China.
HumidityTY_WEATHER_HUMIDITY_STRUnit: %
Wind scaleTY_WEATHER_WIND_LEVEL_STRUnit: Wind class. This variable only applies to mainland China.
Fan speedTY_WEATHER_WIND_SPEED_STRUnit: m/s
Wind directionTY_WEATHER_WIND_DIR_STRWind direction
Air quality indexTY_WEATHER_AIR_AQI_STRThis variable only applies to mainland China.
PM2.5 indexTY_WEATHER_AIR_PM25_STRUnit: µg/m³. This variable only applies to mainland China.
Sulfur dioxide indexTY_WEATHER_AIR_SO2_STRUnit: µg/m³. This variable only applies to mainland China.
CityTY_WEATHER_CITY_STRCity
Type of weatherTY_WEATHER_CONDITION_NUM_STRType of weather

Initialize weather service

Function prototypeOPERATE_RET tuya_weather_init(VOID)
Function descriptionInitialize weather service.
Return valueOPERATE_RET, 0: Success. Other values: Failure. See the error code.
Detailed descriptionThis function has been called in home_init_ex, so there is no need to manually call it.

Get the data of all weather variables

Function prototypeOPERATE_RET tuya_weather_all_data_get(OUT TY_WEATHER_DATA_S **data, OUT UINT_T *count)
Function descriptionGet the data of all weather variables.
Parameterdata: The data of all weather variables. <br> count: The number of weather variables.
Return valueOPERATE_RET, 0: Success. Other values: Failure. See the error code.
Detailed descriptiondata is the successfully returned weather data. After the function call, call tuya_weather_data_free to free the allocated resources.

Get the data of the specified weather variable

Function prototypeOPERATE_RET tuya_weather_single_data_get(IN CHAR_T *code, OUT TY_WEATHER_DATA_S **data)
Function descriptionGet the data of the specified weather variable.
Parametercode: The identifier of the requested weather variable.
Parameterdata: The returned weather data.
Return valueOPERATE_RET, 0: Success. Other values: Failure. See the error code.
Detailed descriptiondata is the successfully returned weather data. After the function call, call tuya_weather_data_free to free the allocated resources.

Free the resources for weather data

Function prototypeOPERATE_RET tuya_weather_data_free(IN TY_WEATHER_DATA_S *data, IN CONST UINT_T count)
Function descriptionFree the resources for weather data.
Parameterdata: The weather data.
Parametercount: The number of weather variables.
Return valueOPERATE_RET, 0: Success. Other values: Failure. See the error code.
Detailed descriptionFree the memory

Update the weather data proactively

Function prototypeOPERATE_RET tuya_weather_sync(VOID)
Function descriptionUpdate the weather data.
Return valueOPERATE_RET, 0: Success. Other values: Failure. See the error code.
Detailed descriptionThe weather data is updated 100 milliseconds after this interface is called.
Post Reply