Skip to content

Commit 5b36079

Browse files
authored
support tuya-weather demo (#311)
* add tuya_weather component && weather-get demo * support weather_get_demo github-action
1 parent 6439c2c commit 5b36079

12 files changed

Lines changed: 2465 additions & 1 deletion

File tree

.github/workflows/check-build-apps.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,10 @@ jobs:
3838
. ./export.sh
3939
cd ${{ github.workspace }}/apps/tuya.ai/your_otto_robot
4040
tos.py dev bac -d ${{ github.workspace }}/dist
41+
- name: Check [weather_get_demo] Build
42+
run: |
43+
cd ${{ github.workspace }}
44+
. ./export.sh
45+
cd ${{ github.workspace }}/apps/tuya_cloud/weather_get_demo
46+
tos.py dev bac -d ${{ github.workspace }}/dist
4147
- run: echo "💡 This job's status is ${{ job.status }}."
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
##
2+
# @file CMakeLists.txt
3+
# @brief
4+
#/
5+
6+
# APP_PATH
7+
set(APP_PATH ${CMAKE_CURRENT_LIST_DIR})
8+
9+
# APP_NAME
10+
get_filename_component(APP_NAME ${APP_PATH} NAME)
11+
12+
# APP_SRCS
13+
aux_source_directory(${APP_PATH}/src APP_SRCS)
14+
15+
# APP_INC
16+
set(APP_INC
17+
${APP_PATH}/include
18+
)
19+
20+
########################################
21+
# Target Configure
22+
########################################
23+
add_library(${EXAMPLE_LIB})
24+
25+
target_sources(${EXAMPLE_LIB}
26+
PRIVATE
27+
${APP_SRCS}
28+
)
29+
30+
target_include_directories(${EXAMPLE_LIB}
31+
PRIVATE
32+
${APP_INC}
33+
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONFIG_BOARD_CHOICE_T5AI=y
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* @file reset_netcfg.c
3+
* @brief Implements reset network configuration functionality for IoT devices
4+
*
5+
* This source file provides the implementation of the reset network configuration
6+
* functionality required for IoT devices. It includes functionality for managing
7+
* reset counters, handling reset events, and clearing network configurations.
8+
* The implementation supports integration with the Tuya IoT platform and ensures
9+
* proper handling of reset-related operations. This file is essential for developers
10+
* working on IoT applications that require robust network configuration reset mechanisms.
11+
*
12+
* @copyright Copyright (c) 2021-2025 Tuya Inc. All Rights Reserved.
13+
*/
14+
15+
#ifndef __RESET_NETCFG_H__
16+
#define __RESET_NETCFG_H__
17+
18+
#include "tuya_cloud_types.h"
19+
20+
#ifdef __cplusplus
21+
extern "C" {
22+
#endif
23+
24+
/***********************************************************
25+
************************macro define************************
26+
***********************************************************/
27+
28+
/***********************************************************
29+
***********************typedef define***********************
30+
***********************************************************/
31+
32+
/***********************************************************
33+
********************function declaration********************
34+
***********************************************************/
35+
/**
36+
* @brief Starts the network configuration reset process.
37+
*
38+
* This function initiates the process to reset the network configuration
39+
* of the device. It is typically used to clear existing network settings
40+
* and prepare the device for reconfiguration.
41+
*
42+
* @return int Returns 0 on success, or a negative value on failure.
43+
*/
44+
int reset_netconfig_start(void);
45+
46+
/**
47+
* @brief Checks the status of the network configuration reset process.
48+
*
49+
* This function verifies whether the network configuration reset process
50+
* has been completed successfully or is still in progress.
51+
*
52+
* @return int Returns 0 on success, or a negative value on failure.
53+
*/
54+
int reset_netconfig_check(void);
55+
56+
#ifdef __cplusplus
57+
}
58+
#endif
59+
60+
#endif /* __RESET_NETCFG_H__ */
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
* @file tuya_config.h
3+
* @brief Tuya IoT device configuration file for product and network settings.
4+
*
5+
* This file contains the configuration settings for Tuya IoT devices, including
6+
* product identification information, device authentication credentials, and
7+
* network provisioning settings. It provides the necessary configuration
8+
* parameters for device activation, cloud platform communication, and
9+
* network connectivity setup.
10+
*
11+
* The configuration includes product ID, device UUID, authentication key,
12+
* and optional PINCODE for AP provisioning. These parameters are essential
13+
* for device registration with the Tuya cloud platform and establishing
14+
* secure communication channels.
15+
*
16+
* Users must replace the default placeholder values with their actual
17+
* product information obtained from the Tuya IoT platform to ensure
18+
* proper device functionality and cloud connectivity.
19+
*
20+
* @copyright Copyright (c) 2021-2025 Tuya Inc. All Rights Reserved.
21+
*
22+
*/
23+
24+
#ifndef _TUYA_CONFIG_H_
25+
#define _TUYA_CONFIG_H_
26+
27+
/**
28+
* @brief Product and device configuration settings
29+
*
30+
* This section defines the essential product and device identification
31+
* parameters required for Tuya IoT device operation. These values must
32+
* be obtained from the Tuya IoT platform and configured correctly
33+
* for proper device activation and cloud communication.
34+
*
35+
* TUYA_PRODUCT_ID: Product ID (PID) created on the Tuya IoT platform
36+
* TUYA_OPENSDK_UUID: Device UUID for SDK authentication
37+
* TUYA_OPENSDK_AUTHKEY: Authentication key for secure communication
38+
*
39+
* For detailed setup instructions, please refer to:
40+
* 1. Product creation and PID generation:
41+
* https://developer.tuya.com/cn/docs/iot-device-dev/application-creation?id=Kbxw7ket3aujc
42+
* 2. SDK license acquisition:
43+
* https://platform.tuya.com/purchase/index?type=6
44+
*
45+
* WARNING: Replace these placeholder values with your actual product
46+
* information to ensure proper device functionality.
47+
*
48+
*/
49+
// clang-format off
50+
#define TUYA_PRODUCT_ID "wtewb6gaxuowjzhb" // Please change your product id
51+
#define TUYA_OPENSDK_UUID "uuidxxxxxxxxxxxxxxxx" // Please change the correct uuid
52+
#define TUYA_OPENSDK_AUTHKEY "keyxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" // Please change the correct authkey
53+
54+
/**
55+
* @brief Network provisioning configuration
56+
*
57+
* This section defines the PINCODE configuration for AP (Access Point)
58+
* provisioning mode. The PINCODE is a randomly generated code provided
59+
* by the Tuya PMS (Product Management System) for secure device
60+
* network configuration.
61+
*
62+
* TUYA_NETCFG_PINCODE: Random PINCODE for AP provisioning mode
63+
*
64+
* WARNING: PINCODE is mandatory for AP provisioning mode and must
65+
* be obtained from the Tuya PMS system for proper network setup.
66+
*
67+
*/
68+
// #define TUYA_NETCFG_PINCODE "69832860"
69+
70+
// clang-format on
71+
72+
#endif //!_TUYA_CONFIG_H_
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/**
2+
* @file cli_cmd.c
3+
* @brief Command Line Interface (CLI) commands for Tuya IoT applications.
4+
*
5+
* This file implements a set of CLI commands for controlling and managing Tuya
6+
* IoT devices. It includes commands for switching device states, executing
7+
* system commands, managing key-value pairs, resetting and starting/stopping
8+
* the IoT process, and retrieving memory usage information. These commands
9+
* facilitate debugging, testing, and managing Tuya IoT applications directly
10+
* from a command line interface.
11+
*
12+
* Key functionalities provided in this file:
13+
* - Switching device states (on/off).
14+
* - Executing arbitrary system commands.
15+
* - Key-value pair management for device configuration.
16+
* - Resetting, starting, and stopping the IoT process.
17+
* - Retrieving current free heap memory size.
18+
*
19+
* This implementation leverages Tuya's Application Layer (TAL) APIs and IoT SDK
20+
* to provide a rich set of commands for device management and debugging. It is
21+
* designed to enhance the development and testing process of Tuya IoT
22+
* applications.
23+
*
24+
* @copyright Copyright (c) 2021-2024 Tuya Inc. All Rights Reserved.
25+
*
26+
*/
27+
28+
#include "tal_api.h"
29+
#include "tuya_iot.h"
30+
#include <stdlib.h>
31+
32+
extern void tal_kv_cmd(int argc, char *argv[]);
33+
extern void netmgr_cmd(int argc, char *argv[]);
34+
extern void weather_get(int argc, char *argv[]);
35+
36+
/**
37+
* @brief excute system cmd
38+
*
39+
* @param argc
40+
* @param argv
41+
* @return void
42+
*/
43+
static void system_cmd(int argc, char *argv[])
44+
{
45+
char cmd[256];
46+
47+
if (argc < 2) {
48+
PR_INFO("usge: sys <cmd>");
49+
return;
50+
}
51+
52+
size_t offset = 0;
53+
54+
for (int i = 1; i < argc; i++) {
55+
offset += sprintf(cmd + offset, "%s ", argv[i]);
56+
}
57+
58+
PR_DEBUG("system %s", cmd);
59+
system(cmd);
60+
}
61+
62+
/**
63+
* @brief get free heap size cmd
64+
*
65+
* @param argc
66+
* @param argv
67+
*/
68+
static void mem(int argc, char *argv[])
69+
{
70+
int free_heap = 0;
71+
free_heap = tal_system_get_free_heap_size();
72+
PR_NOTICE("cur free heap: %d", free_heap);
73+
}
74+
75+
/**
76+
* @brief reset iot to unactive/unregister
77+
*
78+
* @param argc
79+
* @param argv
80+
*/
81+
static void reset(int argc, char *argv[])
82+
{
83+
tuya_iot_reset(tuya_iot_client_get());
84+
}
85+
86+
/**
87+
* @brief reset iot to unactive/unregister
88+
*
89+
* @param argc
90+
* @param argv
91+
*/
92+
static void start(int argc, char *argv[])
93+
{
94+
tuya_iot_start(tuya_iot_client_get());
95+
}
96+
97+
/**
98+
* @brief stop iot
99+
*
100+
* @param argc
101+
* @param argv
102+
*/
103+
static void stop(int argc, char *argv[])
104+
{
105+
tuya_iot_stop(tuya_iot_client_get());
106+
}
107+
108+
/**
109+
* @brief cli cmd list
110+
*
111+
*/
112+
static cli_cmd_t s_cli_cmd[] = {
113+
{.name = "weather", .func = weather_get, .help = "weather get"},
114+
{.name = "kv", .func = tal_kv_cmd, .help = "kv test"},
115+
{.name = "sys", .func = system_cmd, .help = "system cmd"},
116+
{.name = "reset", .func = reset, .help = "reset iot"},
117+
{.name = "stop", .func = stop, .help = "stop iot"},
118+
{.name = "start", .func = start, .help = "start iot"},
119+
{.name = "mem", .func = mem, .help = "mem size"},
120+
{.name = "netmgr", .func = netmgr_cmd, .help = "netmgr cmd"},
121+
};
122+
123+
/**
124+
* @brief
125+
*
126+
*/
127+
void tuya_app_cli_init(void)
128+
{
129+
tal_cli_cmd_register(s_cli_cmd, sizeof(s_cli_cmd) / sizeof(s_cli_cmd[0]));
130+
}

0 commit comments

Comments
 (0)