Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@
[submodule "bsp/emw3080/mico-os"]
path = bsp/emw3080/mico-os
url = https://github.com/MXCHIP/mico-os
[submodule "bsp/esp32c3"]
path = bsp/esp32c3
url = https://github.com/espressif/esp-idf.git
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ Basically, this release builds on the environments of chipset vendor's SDKs.
ex) python setup.py esp8266
ex) python setup.py esp32
ex) python setup.py esp32s2
ex) python setup.py esp32c3
```

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.
Expand Down
196 changes: 196 additions & 0 deletions apps/capability_sample/caps_mode.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
/* ***************************************************************************
*
* Copyright 2019-2021 Samsung Electronics All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************/

#include <string.h>
#include <stdio.h>
#include <stdlib.h>

#include "st_dev.h"
#include "caps_mode.h"

static const char **caps_mode_get_supportedModes_value(caps_mode_data_t *caps_data)
{
if (!caps_data) {
printf("caps_data is NULL\n");
return NULL;
}
return (const char **)caps_data->supportedModes_value;
}

static void caps_mode_set_supportedModes_value(caps_mode_data_t *caps_data, const char **value, int arraySize)
{
int i;
if (!caps_data) {
printf("caps_data is NULL\n");
return;
}
if (caps_data->supportedModes_value) {
for (i = 0; i < caps_data->supportedModes_arraySize; i++) {
free(caps_data->supportedModes_value[i]);
}
free(caps_data->supportedModes_value);
}
caps_data->supportedModes_value = malloc(sizeof(char *) * arraySize);
if (!caps_data->supportedModes_value) {
printf("fail to malloc for supportedModes_value\n");
caps_data->supportedModes_arraySize = 0;
return;
}
for (i = 0; i < arraySize; i++) {
caps_data->supportedModes_value[i] = strdup(value[i]);
}

caps_data->supportedModes_arraySize = arraySize;
}

static void caps_mode_attr_supportedModes_send(caps_mode_data_t *caps_data)
{
int sequence_no = -1;

if (!caps_data || !caps_data->handle) {
printf("fail to get handle\n");
return;
}
if (!caps_data->supportedModes_value) {
printf("value is NULL\n");
return;
}

ST_CAP_SEND_ATTR_STRINGS_ARRAY(caps_data->handle,
(char *)caps_helper_mode.attr_supportedModes.name,
caps_data->supportedModes_value,
caps_data->supportedModes_arraySize,
NULL,
NULL,
sequence_no);

if (sequence_no < 0)
printf("fail to send supportedModes value\n");
else
printf("Sequence number return : %d\n", sequence_no);
}


static const char *caps_mode_get_mode_value(caps_mode_data_t *caps_data)
{
if (!caps_data) {
printf("caps_data is NULL\n");
return NULL;
}
return caps_data->mode_value;
}

static void caps_mode_set_mode_value(caps_mode_data_t *caps_data, const char *value)
{
if (!caps_data) {
printf("caps_data is NULL\n");
return;
}
if (caps_data->mode_value) {
free(caps_data->mode_value);
}
caps_data->mode_value = strdup(value);
}

static void caps_mode_attr_mode_send(caps_mode_data_t *caps_data)
{
int sequence_no = -1;

if (!caps_data || !caps_data->handle) {
printf("fail to get handle\n");
return;
}
if (!caps_data->mode_value) {
printf("value is NULL\n");
return;
}

ST_CAP_SEND_ATTR_STRING(caps_data->handle,
(char *)caps_helper_mode.attr_mode.name,
caps_data->mode_value,
NULL,
NULL,
sequence_no);

if (sequence_no < 0)
printf("fail to send mode value\n");
else
printf("Sequence number return : %d\n", sequence_no);
}


static void caps_mode_cmd_setMode_cb(IOT_CAP_HANDLE *handle, iot_cap_cmd_data_t *cmd_data, void *usr_data)
{
caps_mode_data_t *caps_data = (caps_mode_data_t *)usr_data;
char *value;

printf("called [%s] func with num_args:%u\n", __func__, cmd_data->num_args);

value = cmd_data->cmd_data[0].string;

caps_mode_set_mode_value(caps_data, value);
if (caps_data && caps_data->cmd_setMode_usr_cb)
caps_data->cmd_setMode_usr_cb(caps_data);
caps_mode_attr_mode_send(caps_data);
}

static void caps_mode_init_cb(IOT_CAP_HANDLE *handle, void *usr_data)
{
caps_mode_data_t *caps_data = usr_data;
if (caps_data && caps_data->init_usr_cb)
caps_data->init_usr_cb(caps_data);
caps_mode_attr_supportedModes_send(caps_data);
caps_mode_attr_mode_send(caps_data);
}

caps_mode_data_t *caps_mode_initialize(IOT_CTX *ctx, const char *component, void *init_usr_cb, void *usr_data)
{
caps_mode_data_t *caps_data = NULL;
int err;

caps_data = malloc(sizeof(caps_mode_data_t));
if (!caps_data) {
printf("fail to malloc for caps_mode_data\n");
return NULL;
}

memset(caps_data, 0, sizeof(caps_mode_data_t));

caps_data->init_usr_cb = init_usr_cb;
caps_data->usr_data = usr_data;

caps_data->get_supportedModes_value = caps_mode_get_supportedModes_value;
caps_data->set_supportedModes_value = caps_mode_set_supportedModes_value;
caps_data->attr_supportedModes_send = caps_mode_attr_supportedModes_send;
caps_data->get_mode_value = caps_mode_get_mode_value;
caps_data->set_mode_value = caps_mode_set_mode_value;
caps_data->attr_mode_send = caps_mode_attr_mode_send;
if (ctx) {
caps_data->handle = st_cap_handle_init(ctx, component, caps_helper_mode.id, caps_mode_init_cb, caps_data);
}
if (caps_data->handle) {
err = st_cap_cmd_set_cb(caps_data->handle, caps_helper_mode.cmd_setMode.name, caps_mode_cmd_setMode_cb, caps_data);
if (err) {
printf("fail to set cmd_cb for setMode of mode\n");
}
} else {
printf("fail to init mode handle\n");
}

return caps_data;
}
51 changes: 51 additions & 0 deletions apps/capability_sample/caps_mode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* ***************************************************************************
*
* Copyright 2019-2021 Samsung Electronics All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*
****************************************************************************/

#include "caps/iot_caps_helper_mode.h"
#include "external/JSON.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef struct caps_mode_data {
IOT_CAP_HANDLE* handle;
void *usr_data;
void *cmd_data;

char **supportedModes_value;
int supportedModes_arraySize;
char *mode_value;

const char **(*get_supportedModes_value)(struct caps_mode_data *caps_data);
void (*set_supportedModes_value)(struct caps_mode_data *caps_data, const char **value, int arraySize);
void (*attr_supportedModes_send)(struct caps_mode_data *caps_data);
const char *(*get_mode_value)(struct caps_mode_data *caps_data);
void (*set_mode_value)(struct caps_mode_data *caps_data, const char *value);
void (*attr_mode_send)(struct caps_mode_data *caps_data);

void (*init_usr_cb)(struct caps_mode_data *caps_data);

void (*cmd_setMode_usr_cb)(struct caps_mode_data *caps_data);
} caps_mode_data_t;

caps_mode_data_t *caps_mode_initialize(IOT_CTX *ctx, const char *component, void *init_usr_cb, void *usr_data);
#ifdef __cplusplus
}
#endif

8 changes: 8 additions & 0 deletions apps/esp32c3/light_example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# The following lines of boilerplate have to be in your project's
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)

include($ENV{IDF_PATH}/tools/cmake/project.cmake)

project(light_example)

11 changes: 11 additions & 0 deletions apps/esp32c3/light_example/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
# project subdirectory.
#

PROJECT_NAME := light_example

EXTRA_COMPONENT_DIRS := ${IDF_PATH}/../../iot-core

include $(IDF_PATH)/make/project.mk

56 changes: 56 additions & 0 deletions apps/esp32c3/light_example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# SmartThings SDK for Direct Connected Devices for C - Light Example

## Introduction

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.

## Getting started

For information on detailed workflow, please refer to the [Getting Started](../../../doc/getting_started.md)

## Components and Capabilities

SmartThings Device is defined using components and capabilities. Capabilities define the features of the device, and capabilities are grouped into components.
Components and Capabilities are contained in device profile. You can create a device profile in Developer Workspace and associate it with an integration.

This example assumes the following components and capabilities are used. :

`main` component
- `healthCheck` capability
- `switch` capability
- `switchLevel` capability
- `colorTemperature` capability
- `activityLightingMode` capability

`monitor` component
- `dustSensor` capability

(`healthCheck` capability is automatically added by Developer Workspace. It doesn't need handler at device side)

## SmartThings SDK for Direct Connected Devices - Config
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 :
```sh
# python build.py {app_path} {option}
$ cd ~/st-device-sdk-c-ref/
$ python build.py apps/esp32c3/light_example menuconfig
```

## Test device schematics
This example uses ESP32C3 GPIO like below.
Please refer below picture for __ESP32C3-DevKitC-02__.
> Note: If your device's schematics doesn't match with belows.
> Please modify GPIO defines for your device at [device_control.h](main/device_control.h)
> ```c
> #define GPIO_INPUT_BUTTON 9
>
> #define GPIO_OUTPUT_COLORLED_R 3
> #define GPIO_OUTPUT_COLORLED_G 2
> #define GPIO_OUTPUT_COLORLED_B 1
> #define GPIO_OUTPUT_COLORLED_0 0
> ```

### ESP32-C3-DevKitC-02
| ESP32-C3-DevKitC-02 |
|-----------------------------------------------------------------------------|
|![ESP32C3_DEVKITC_02](../../../doc/res/Light_Example_ESP32C3_DEVKITC_02.png) |

19 changes: 19 additions & 0 deletions apps/esp32c3/light_example/debug_sdkconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# Log output
#
CONFIG_LOG_DEFAULT_LEVEL_NONE=
CONFIG_LOG_DEFAULT_LEVEL_ERROR=
CONFIG_LOG_DEFAULT_LEVEL_WARN=
CONFIG_LOG_DEFAULT_LEVEL_INFO=y
CONFIG_LOG_DEFAULT_LEVEL_DEBUG=
CONFIG_LOG_DEFAULT_LEVEL_VERBOSE=
CONFIG_LOG_DEFAULT_LEVEL=3
CONFIG_LOG_COLORS=y
CONFIG_LOG_SET_LEVEL=

CONFIG_STDK_DEBUG_MEMORY_CHECK=y

CONFIG_STDK_IOT_CORE_LOG_LEVEL_ERROR=y
CONFIG_STDK_IOT_CORE_LOG_LEVEL_WARN=y
CONFIG_STDK_IOT_CORE_LOG_LEVEL_INFO=y
CONFIG_STDK_IOT_CORE_LOG_LEVEL_DEBUG=
29 changes: 29 additions & 0 deletions apps/esp32c3/light_example/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
idf_component_register(SRCS "main.c"
"device_control.c"
"iot_cli_cmd.c"
"iot_uart_cli.c"
"caps_activityLightingMode.c"
"caps_colorTemperature.c"
"caps_dustSensor.c"
"caps_switch.c"
"caps_switchLevel.c"
EMBED_FILES "device_info.json"
"onboarding_config.json"
)

set(STDK_IOT_CORE_USE_DEFINED_CONFIG "y")

set(STDK_LINK_LIBRARY
__idf_libsodium
__idf_json
)

set(STDK_INCLUDE_PATH
"$ENV{IDF_PATH}/components/freertos/include/freertos"
"$ENV{IDF_PATH}/components/nvs_flash/include"
"$ENV{IDF_PATH}/components/spi_flash/include"
"$ENV{IDF_PATH}/components/bootloader_support/include"
)

add_subdirectory($ENV{STDK_CORE_PATH} iotcore)
target_link_libraries(${COMPONENT_LIB} PUBLIC iotcore)
Loading