Skip to content

Commit 60ca8cc

Browse files
authored
Merge pull request #96 from SmartThingsCommunity/master_rel_1_7_0
Master rel 1 7 0
2 parents b02bd3e + c23be32 commit 60ca8cc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+7020
-5
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@
2828
[submodule "bsp/emw3080/mico-os"]
2929
path = bsp/emw3080/mico-os
3030
url = https://github.com/MXCHIP/mico-os
31+
[submodule "bsp/esp32c3"]
32+
path = bsp/esp32c3
33+
url = https://github.com/espressif/esp-idf.git

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ Basically, this release builds on the environments of chipset vendor's SDKs.
7575
ex) python setup.py esp8266
7676
ex) python setup.py esp32
7777
ex) python setup.py esp32s2
78+
ex) python setup.py esp32c3
7879
```
7980

8081
2. Check the build configuration of a sample device application. If you want to use specific build options, you can directly modify the build configuration file(e.g. sdkconfig, sdkconfig.h) at the root directory of a sample device application. On the Espressif chipset, you can additionally use the `menuconfig` option to configure them.

apps/capability_sample/caps_mode.c

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
/* ***************************************************************************
2+
*
3+
* Copyright 2019-2021 Samsung Electronics All Rights Reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing,
12+
* software distributed under the License is distributed on an
13+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
14+
* either express or implied. See the License for the specific
15+
* language governing permissions and limitations under the License.
16+
*
17+
****************************************************************************/
18+
19+
#include <string.h>
20+
#include <stdio.h>
21+
#include <stdlib.h>
22+
23+
#include "st_dev.h"
24+
#include "caps_mode.h"
25+
26+
static const char **caps_mode_get_supportedModes_value(caps_mode_data_t *caps_data)
27+
{
28+
if (!caps_data) {
29+
printf("caps_data is NULL\n");
30+
return NULL;
31+
}
32+
return (const char **)caps_data->supportedModes_value;
33+
}
34+
35+
static void caps_mode_set_supportedModes_value(caps_mode_data_t *caps_data, const char **value, int arraySize)
36+
{
37+
int i;
38+
if (!caps_data) {
39+
printf("caps_data is NULL\n");
40+
return;
41+
}
42+
if (caps_data->supportedModes_value) {
43+
for (i = 0; i < caps_data->supportedModes_arraySize; i++) {
44+
free(caps_data->supportedModes_value[i]);
45+
}
46+
free(caps_data->supportedModes_value);
47+
}
48+
caps_data->supportedModes_value = malloc(sizeof(char *) * arraySize);
49+
if (!caps_data->supportedModes_value) {
50+
printf("fail to malloc for supportedModes_value\n");
51+
caps_data->supportedModes_arraySize = 0;
52+
return;
53+
}
54+
for (i = 0; i < arraySize; i++) {
55+
caps_data->supportedModes_value[i] = strdup(value[i]);
56+
}
57+
58+
caps_data->supportedModes_arraySize = arraySize;
59+
}
60+
61+
static void caps_mode_attr_supportedModes_send(caps_mode_data_t *caps_data)
62+
{
63+
int sequence_no = -1;
64+
65+
if (!caps_data || !caps_data->handle) {
66+
printf("fail to get handle\n");
67+
return;
68+
}
69+
if (!caps_data->supportedModes_value) {
70+
printf("value is NULL\n");
71+
return;
72+
}
73+
74+
ST_CAP_SEND_ATTR_STRINGS_ARRAY(caps_data->handle,
75+
(char *)caps_helper_mode.attr_supportedModes.name,
76+
caps_data->supportedModes_value,
77+
caps_data->supportedModes_arraySize,
78+
NULL,
79+
NULL,
80+
sequence_no);
81+
82+
if (sequence_no < 0)
83+
printf("fail to send supportedModes value\n");
84+
else
85+
printf("Sequence number return : %d\n", sequence_no);
86+
}
87+
88+
89+
static const char *caps_mode_get_mode_value(caps_mode_data_t *caps_data)
90+
{
91+
if (!caps_data) {
92+
printf("caps_data is NULL\n");
93+
return NULL;
94+
}
95+
return caps_data->mode_value;
96+
}
97+
98+
static void caps_mode_set_mode_value(caps_mode_data_t *caps_data, const char *value)
99+
{
100+
if (!caps_data) {
101+
printf("caps_data is NULL\n");
102+
return;
103+
}
104+
if (caps_data->mode_value) {
105+
free(caps_data->mode_value);
106+
}
107+
caps_data->mode_value = strdup(value);
108+
}
109+
110+
static void caps_mode_attr_mode_send(caps_mode_data_t *caps_data)
111+
{
112+
int sequence_no = -1;
113+
114+
if (!caps_data || !caps_data->handle) {
115+
printf("fail to get handle\n");
116+
return;
117+
}
118+
if (!caps_data->mode_value) {
119+
printf("value is NULL\n");
120+
return;
121+
}
122+
123+
ST_CAP_SEND_ATTR_STRING(caps_data->handle,
124+
(char *)caps_helper_mode.attr_mode.name,
125+
caps_data->mode_value,
126+
NULL,
127+
NULL,
128+
sequence_no);
129+
130+
if (sequence_no < 0)
131+
printf("fail to send mode value\n");
132+
else
133+
printf("Sequence number return : %d\n", sequence_no);
134+
}
135+
136+
137+
static void caps_mode_cmd_setMode_cb(IOT_CAP_HANDLE *handle, iot_cap_cmd_data_t *cmd_data, void *usr_data)
138+
{
139+
caps_mode_data_t *caps_data = (caps_mode_data_t *)usr_data;
140+
char *value;
141+
142+
printf("called [%s] func with num_args:%u\n", __func__, cmd_data->num_args);
143+
144+
value = cmd_data->cmd_data[0].string;
145+
146+
caps_mode_set_mode_value(caps_data, value);
147+
if (caps_data && caps_data->cmd_setMode_usr_cb)
148+
caps_data->cmd_setMode_usr_cb(caps_data);
149+
caps_mode_attr_mode_send(caps_data);
150+
}
151+
152+
static void caps_mode_init_cb(IOT_CAP_HANDLE *handle, void *usr_data)
153+
{
154+
caps_mode_data_t *caps_data = usr_data;
155+
if (caps_data && caps_data->init_usr_cb)
156+
caps_data->init_usr_cb(caps_data);
157+
caps_mode_attr_supportedModes_send(caps_data);
158+
caps_mode_attr_mode_send(caps_data);
159+
}
160+
161+
caps_mode_data_t *caps_mode_initialize(IOT_CTX *ctx, const char *component, void *init_usr_cb, void *usr_data)
162+
{
163+
caps_mode_data_t *caps_data = NULL;
164+
int err;
165+
166+
caps_data = malloc(sizeof(caps_mode_data_t));
167+
if (!caps_data) {
168+
printf("fail to malloc for caps_mode_data\n");
169+
return NULL;
170+
}
171+
172+
memset(caps_data, 0, sizeof(caps_mode_data_t));
173+
174+
caps_data->init_usr_cb = init_usr_cb;
175+
caps_data->usr_data = usr_data;
176+
177+
caps_data->get_supportedModes_value = caps_mode_get_supportedModes_value;
178+
caps_data->set_supportedModes_value = caps_mode_set_supportedModes_value;
179+
caps_data->attr_supportedModes_send = caps_mode_attr_supportedModes_send;
180+
caps_data->get_mode_value = caps_mode_get_mode_value;
181+
caps_data->set_mode_value = caps_mode_set_mode_value;
182+
caps_data->attr_mode_send = caps_mode_attr_mode_send;
183+
if (ctx) {
184+
caps_data->handle = st_cap_handle_init(ctx, component, caps_helper_mode.id, caps_mode_init_cb, caps_data);
185+
}
186+
if (caps_data->handle) {
187+
err = st_cap_cmd_set_cb(caps_data->handle, caps_helper_mode.cmd_setMode.name, caps_mode_cmd_setMode_cb, caps_data);
188+
if (err) {
189+
printf("fail to set cmd_cb for setMode of mode\n");
190+
}
191+
} else {
192+
printf("fail to init mode handle\n");
193+
}
194+
195+
return caps_data;
196+
}

apps/capability_sample/caps_mode.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* ***************************************************************************
2+
*
3+
* Copyright 2019-2021 Samsung Electronics All Rights Reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing,
12+
* software distributed under the License is distributed on an
13+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
14+
* either express or implied. See the License for the specific
15+
* language governing permissions and limitations under the License.
16+
*
17+
****************************************************************************/
18+
19+
#include "caps/iot_caps_helper_mode.h"
20+
#include "external/JSON.h"
21+
22+
#ifdef __cplusplus
23+
extern "C" {
24+
#endif
25+
26+
typedef struct caps_mode_data {
27+
IOT_CAP_HANDLE* handle;
28+
void *usr_data;
29+
void *cmd_data;
30+
31+
char **supportedModes_value;
32+
int supportedModes_arraySize;
33+
char *mode_value;
34+
35+
const char **(*get_supportedModes_value)(struct caps_mode_data *caps_data);
36+
void (*set_supportedModes_value)(struct caps_mode_data *caps_data, const char **value, int arraySize);
37+
void (*attr_supportedModes_send)(struct caps_mode_data *caps_data);
38+
const char *(*get_mode_value)(struct caps_mode_data *caps_data);
39+
void (*set_mode_value)(struct caps_mode_data *caps_data, const char *value);
40+
void (*attr_mode_send)(struct caps_mode_data *caps_data);
41+
42+
void (*init_usr_cb)(struct caps_mode_data *caps_data);
43+
44+
void (*cmd_setMode_usr_cb)(struct caps_mode_data *caps_data);
45+
} caps_mode_data_t;
46+
47+
caps_mode_data_t *caps_mode_initialize(IOT_CTX *ctx, const char *component, void *init_usr_cb, void *usr_data);
48+
#ifdef __cplusplus
49+
}
50+
#endif
51+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# The following lines of boilerplate have to be in your project's
2+
# CMakeLists in this exact order for cmake to work correctly
3+
cmake_minimum_required(VERSION 3.5)
4+
5+
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
6+
7+
project(light_example)
8+

apps/esp32c3/light_example/Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#
2+
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
3+
# project subdirectory.
4+
#
5+
6+
PROJECT_NAME := light_example
7+
8+
EXTRA_COMPONENT_DIRS := ${IDF_PATH}/../../iot-core
9+
10+
include $(IDF_PATH)/make/project.mk
11+

apps/esp32c3/light_example/README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# SmartThings SDK for Direct Connected Devices for C - Light Example
2+
3+
## Introduction
4+
5+
SmartThings direct-connected device is Wi-Fi enabled device that uses the SmartThings cloud as its primary cloud infrastructure. And this device will use the MQTT protocol for communication.
6+
7+
## Getting started
8+
9+
For information on detailed workflow, please refer to the [Getting Started](../../../doc/getting_started.md)
10+
11+
## Components and Capabilities
12+
13+
SmartThings Device is defined using components and capabilities. Capabilities define the features of the device, and capabilities are grouped into components.
14+
Components and Capabilities are contained in device profile. You can create a device profile in Developer Workspace and associate it with an integration.
15+
16+
This example assumes the following components and capabilities are used. :
17+
18+
`main` component
19+
- `healthCheck` capability
20+
- `switch` capability
21+
- `switchLevel` capability
22+
- `colorTemperature` capability
23+
- `activityLightingMode` capability
24+
25+
`monitor` component
26+
- `dustSensor` capability
27+
28+
(`healthCheck` capability is automatically added by Developer Workspace. It doesn't need handler at device side)
29+
30+
## SmartThings SDK for Direct Connected Devices - Config
31+
If you want to use specific SmartThings Device SDK build options, you can directly modify the build configuration file. For this example, SmartThings Device SDK config is saved in 'sdkconfig' file. If you want to change this, please execute the following :
32+
```sh
33+
# python build.py {app_path} {option}
34+
$ cd ~/st-device-sdk-c-ref/
35+
$ python build.py apps/esp32c3/light_example menuconfig
36+
```
37+
38+
## Test device schematics
39+
This example uses ESP32C3 GPIO like below.
40+
Please refer below picture for __ESP32C3-DevKitC-02__.
41+
> Note: If your device's schematics doesn't match with belows.
42+
> Please modify GPIO defines for your device at [device_control.h](main/device_control.h)
43+
> ```c
44+
> #define GPIO_INPUT_BUTTON 9
45+
>
46+
> #define GPIO_OUTPUT_COLORLED_R 3
47+
> #define GPIO_OUTPUT_COLORLED_G 2
48+
> #define GPIO_OUTPUT_COLORLED_B 1
49+
> #define GPIO_OUTPUT_COLORLED_0 0
50+
> ```
51+
52+
### ESP32-C3-DevKitC-02
53+
| ESP32-C3-DevKitC-02 |
54+
|-----------------------------------------------------------------------------|
55+
|![ESP32C3_DEVKITC_02](../../../doc/res/Light_Example_ESP32C3_DEVKITC_02.png) |
56+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#
2+
# Log output
3+
#
4+
CONFIG_LOG_DEFAULT_LEVEL_NONE=
5+
CONFIG_LOG_DEFAULT_LEVEL_ERROR=
6+
CONFIG_LOG_DEFAULT_LEVEL_WARN=
7+
CONFIG_LOG_DEFAULT_LEVEL_INFO=y
8+
CONFIG_LOG_DEFAULT_LEVEL_DEBUG=
9+
CONFIG_LOG_DEFAULT_LEVEL_VERBOSE=
10+
CONFIG_LOG_DEFAULT_LEVEL=3
11+
CONFIG_LOG_COLORS=y
12+
CONFIG_LOG_SET_LEVEL=
13+
14+
CONFIG_STDK_DEBUG_MEMORY_CHECK=y
15+
16+
CONFIG_STDK_IOT_CORE_LOG_LEVEL_ERROR=y
17+
CONFIG_STDK_IOT_CORE_LOG_LEVEL_WARN=y
18+
CONFIG_STDK_IOT_CORE_LOG_LEVEL_INFO=y
19+
CONFIG_STDK_IOT_CORE_LOG_LEVEL_DEBUG=
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
idf_component_register(SRCS "main.c"
2+
"device_control.c"
3+
"iot_cli_cmd.c"
4+
"iot_uart_cli.c"
5+
"caps_activityLightingMode.c"
6+
"caps_colorTemperature.c"
7+
"caps_dustSensor.c"
8+
"caps_switch.c"
9+
"caps_switchLevel.c"
10+
EMBED_FILES "device_info.json"
11+
"onboarding_config.json"
12+
)
13+
14+
set(STDK_IOT_CORE_USE_DEFINED_CONFIG "y")
15+
16+
set(STDK_LINK_LIBRARY
17+
__idf_libsodium
18+
__idf_json
19+
)
20+
21+
set(STDK_INCLUDE_PATH
22+
"$ENV{IDF_PATH}/components/freertos/include/freertos"
23+
"$ENV{IDF_PATH}/components/nvs_flash/include"
24+
"$ENV{IDF_PATH}/components/spi_flash/include"
25+
"$ENV{IDF_PATH}/components/bootloader_support/include"
26+
)
27+
28+
add_subdirectory($ENV{STDK_CORE_PATH} iotcore)
29+
target_link_libraries(${COMPONENT_LIB} PUBLIC iotcore)

0 commit comments

Comments
 (0)