Example files for st_things.
--- /dev/null
+#
+# For a description of the syntax of this configuration file,
+# see kconfig-language at https://www.kernel.org/doc/Documentation/kbuild/kconfig-language.txt
+#
+
+config EXAMPLES_ST_THINGS
+ bool "SmartThings Things example"
+ default n
+ ---help---
+ Enable the SmartThings Things example
+
+if EXAMPLES_ST_THINGS
+
+config EXAMPLES_THINGSEASYSETUP_PROGNAME
+ string "Program name"
+ default "st_things_sample"
+ depends on BUILD_KERNEL
+ ---help---
+ This is the name of the program that will be use when the NSH ELF
+ program is installed.
+
+config RESET_BUTTON
+ bool "Reset_Button"
+ default y
+ depends on EXAMPLES_ST_THINGS
+ ---help---
+ Decide whether to use the button to reset the connection on your board.
+
+config RESET_BUTTON_PIN_NUMBER
+ int "Pin Number"
+ default 44
+ depends on RESET_BUTTON
+ ---help---
+ The default is the reset button pin number 44 for the ARTIK 053.
+ If you use another board, you can set the pin number for the board.
+
+endif
+
+config USER_ENTRYPOINT
+ string
+ default "st_things_sample_main" if EXAMPLES_ST_THINGS
--- /dev/null
+###########################################################################
+#
+# Copyright 2017 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.
+#
+###########################################################################
+
+ifeq ($(CONFIG_EXAMPLES_ST_THINGS),y)
+CONFIGURED_APPS += examples/st_things
+endif
--- /dev/null
+###########################################################################
+#
+# Copyright 2017 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 $(TOPDIR)/.config
+-include $(TOPDIR)/Make.defs
+include $(APPDIR)/Make.defs
+
+# built-in application info
+
+APPNAME = st_things_sample
+FUNCNAME = st_things_sample_main
+THREADEXEC = TASH_EXECMD_SYNC
+
+# SmartThings Things example
+
+ASRCS =
+CSRCS = sample_light_user.c sample_light_things.c
+MAINSRC = st_things_sample_main.c
+
+AOBJS = $(ASRCS:.S=$(OBJEXT))
+COBJS = $(CSRCS:.c=$(OBJEXT))
+MAINOBJ = $(MAINSRC:.c=$(OBJEXT))
+
+SRCS = $(ASRCS) $(CSRCS) $(MAINSRC)
+OBJS = $(AOBJS) $(COBJS)
+
+ifneq ($(CONFIG_BUILD_KERNEL),y)
+ OBJS += $(MAINOBJ)
+endif
+
+ifeq ($(CONFIG_WINDOWS_NATIVE),y)
+ BIN = ..\..\libapps$(LIBEXT)
+else
+ifeq ($(WINTOOL),y)
+ BIN = ..\\..\\libapps$(LIBEXT)
+else
+ BIN = ../../libapps$(LIBEXT)
+endif
+endif
+
+ifeq ($(WINTOOL),y)
+ INSTALL_DIR = "${shell cygpath -w $(BIN_DIR)}"
+else
+ INSTALL_DIR = $(BIN_DIR)
+endif
+
+CONFIG_EXAMPLES_ST_THINGS_PROGNAME ?= st_things$(EXEEXT)
+PROGNAME = $(CONFIG_EXAMPLES_ST_THINGS_PROGNAME)
+
+ROOTDEPPATH = --dep-path .
+
+# Common build
+
+all: .built
+.PHONY: clean depend distclean
+
+$(AOBJS): %$(OBJEXT): %.S
+ $(call ASSEMBLE, $<, $@)
+
+$(COBJS) $(MAINOBJ): %$(OBJEXT): %.c
+ $(call COMPILE, $<, $@)
+
+.built: $(OBJS)
+ $(call ARCHIVE, $(BIN), $(OBJS))
+ @touch .built
+
+ifeq ($(CONFIG_BUILD_KERNEL),y)
+$(BIN_DIR)$(DELIM)$(PROGNAME): $(OBJS) $(MAINOBJ)
+ @echo "LD: $(PROGNAME)"
+ $(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $(INSTALL_DIR)$(DELIM)$(PROGNAME) $(ARCHCRT0OBJ) $(MAINOBJ) $(LDLIBS)
+ $(Q) $(NM) -u $(INSTALL_DIR)$(DELIM)$(PROGNAME)
+
+install: $(BIN_DIR)$(DELIM)$(PROGNAME)
+
+else
+install:
+
+endif
+
+ifeq ($(CONFIG_BUILTIN_APPS)$(CONFIG_EXAMPLES_ST_THINGS),yy)
+$(BUILTIN_REGISTRY)$(DELIM)$(FUNCNAME).bdat: $(DEPCONFIG) Makefile
+ $(call REGISTER,$(APPNAME),$(FUNCNAME),$(THREADEXEC))
+
+context: $(BUILTIN_REGISTRY)$(DELIM)$(FUNCNAME).bdat
+
+else
+context:
+
+endif
+
+.depend: Makefile $(SRCS)
+ @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
+ @touch $@
+
+depend: .depend
+
+clean:
+ $(call DELFILE, .built)
+ $(call CLEAN)
+
+distclean: clean
+ $(call DELFILE, Make.dep)
+ $(call DELFILE, .depend)
+
+-include Make.dep
+.PHONY: preconfig
+preconfig:
--- /dev/null
+# st_things sample
+
+This is an example for a st_things.
+
+## How to build
+Configure the build from $TIZENRT_BASEDIR/os/tools directory.
+```bash
+./configure.sh artik053/st_things
+cd ..
+make
+```
+
+## Download
+Add 'privatekey', 'certificate', and json file(ex. sampleDevice.json) to $TIZENRT_BASEDIR/tools/fs/contents.
+```bash
+TIZENRT_BASEDIR/os$ make download ALL
+```
--- /dev/null
+{
+ "device": [
+ {
+ "specification": {
+ "device": {
+ "deviceType": "oic.d.light",
+ "deviceName": "Samsung Lamp",
+ "specVersion": "core.1.1.0",
+ "dataModelVersion": "res.1.1.0"
+ },
+ "platform": {
+ "manufacturerName": "Samsung Electronics",
+ "manufacturerUrl": "http://www.samsung.com/sec/",
+ "manufacturingDate": "2017-08-31",
+ "modelNumber": "NWSP-01",
+ "platformVersion": "1.0",
+ "osVersion": "1.0",
+ "hardwareVersion": "1.0",
+ "firmwareVersion": "1.0",
+ "vendorId": "SWC-LIGHT-2017"
+ }
+ },
+
+ "resources": {
+ "single": [
+ {
+ "uri": "/switch",
+ "types": [
+ "oic.r.switch.binary"
+ ],
+ "interfaces": [
+ "oic.if.a",
+ "oic.if.baseline"
+ ],
+ "policy": 3
+ }
+ ]
+ }
+ }
+ ],
+
+ "resourceTypes": [
+ {
+ "type": "oic.r.switch.binary",
+ "properties": [
+ {
+ "key": "value",
+ "type": 0,
+ "mandatory": true,
+ "rw": 3
+ }
+ ]
+ } ],
+ "configuration": {
+ "easySetup": {
+ "connectivity": {
+ "type": 1,
+ "softAP": {
+ "manufacturerId": "AAA1",
+ "setupId": "001",
+ "artik": false
+ }
+ },
+ "ownershipTransferMethod": 2
+ },
+ "wifi": {
+ "interfaces": 15,
+ "frequency": 1
+ },
+ "filePath":{
+ "svrdb": "/mnt/artikserversecured.dat",
+ "provisioning": "/mnt/provisioning.dat",
+ "certificate": "/rom/certificate",
+ "privateKey": "/rom/privatekey"
+ }
+ }
+}
+
--- /dev/null
+/* ****************************************************************
+ *
+ * Copyright 2017 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 <stdio.h>
+#include <string.h>
+#include <stdbool.h>
+#include <signal.h>
+#include <st_things/st_things.h>
+#include <iotbus/iotbus_gpio.h>
+
+#define TAG "LIGHT_THINGS"
+
+static const char *g_res_switch = "/switch";
+
+extern bool handle_get_request_on_switch(st_things_get_request_message_s * req_msg, st_things_representation_s * resp_rep);
+extern bool handle_set_request_on_switch(st_things_set_request_message_s * req_msg, st_things_representation_s * resp_rep);
+
+#ifdef CONFIG_RESET_BUTTON
+static bool check_reset_button_pin_number(void)
+{
+ printf("Current pin number : %d\n", CONFIG_RESET_BUTTON_PIN_NUMBER);
+ return CONFIG_RESET_BUTTON_PIN_NUMBER >= 0 ? true : false;
+}
+
+static void gpio_callback_event(void *user_data)
+{
+ printf("gpio_callback_event!!\n");
+ printf("reset :: %d\n", st_things_reset());
+}
+#endif
+
+static void handle_reset_result(bool result)
+{
+ printf("[%s]Reset %s.\n", result ? "succeeded" : "failed", TAG);
+}
+
+static void handle_things_status_change(st_things_status_e things_status)
+{
+ printf("[%s]Things status is changed: %d\n", TAG, things_status);
+}
+
+static bool handle_reset_request(void)
+{
+ printf("[%s]Received a request for RESET.\n", TAG);
+ return true;
+}
+
+static bool handle_ownership_transfer_request(void)
+{
+ printf("[%s]Received a request for Ownership-transfer. \n", TAG);
+ return true;
+}
+
+static bool handle_get_request(st_things_get_request_message_s * req_msg, st_things_representation_s * resp_rep)
+{
+ bool ret = false;
+
+ printf("Received a GET request on %s\n", req_msg->resource_uri);
+
+ if (0 == strncmp(req_msg->resource_uri, g_res_switch, strlen(g_res_switch))) {
+ ret = handle_get_request_on_switch(req_msg, resp_rep);
+ } else {
+ printf("Not supported uri.\n");
+ }
+
+ return ret;
+}
+
+static bool handle_set_request(st_things_set_request_message_s * req_msg, st_things_representation_s * resp_rep)
+{
+ printf("Received a SET request on %s\n", req_msg->resource_uri);
+
+ if (0 == strncmp(req_msg->resource_uri, g_res_switch, strlen(g_res_switch))) {
+ handle_set_request_on_switch(req_msg, resp_rep);
+ return true;
+ } else {
+ return false;
+ }
+
+ return true;
+}
+
+int ess_process(void)
+{
+#ifdef CONFIG_RESET_BUTTON
+ if (!check_reset_button_pin_number()) {
+ printf("Error : Invalid pin number.\n");
+ return 0;
+ }
+
+ iotbus_gpio_context_h m_gpio = iotbus_gpio_open(CONFIG_RESET_BUTTON_PIN_NUMBER);
+ iotbus_gpio_register_cb(m_gpio, IOTBUS_GPIO_EDGE_RISING, gpio_callback_event, (void *)m_gpio);
+#endif
+
+ bool easysetup_complete = false;
+ st_things_initialize("/rom/sampleDevice.json", &easysetup_complete);
+ iotapi_initialize();
+
+ st_things_register_request_cb(handle_get_request, handle_set_request);
+ st_things_register_reset_cb(handle_reset_request, handle_reset_result);
+ st_things_register_user_confirm_cb(handle_ownership_transfer_request);
+ st_things_register_things_status_change_cb(handle_things_status_change);
+
+ st_things_start();
+
+ printf("[%s]=====================================================\n", TAG);
+ printf("[%s] Stack Started \n", TAG);
+ printf("[%s]=====================================================\n", TAG);
+
+ return 0;
+}
--- /dev/null
+/* ****************************************************************
+*
+* Copyright 2017 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 <stdio.h>
+#include <string.h>
+#include <stdbool.h>
+#include <signal.h>
+#include <st_things/st_things.h>
+
+#define TAG "LIGHT_USER"
+
+static const char *PROPERTY_VALUE = "value";
+
+static bool g_switch_value = true;
+
+bool handle_get_request_on_switch(st_things_get_request_message_s *req_msg, st_things_representation_s *resp_rep)
+{
+ printf("[%s]IN-handle_get_request_on_switch() called..\n", TAG);
+
+ if (req_msg->has_property_key(req_msg, PROPERTY_VALUE)) {
+ printf("[%s]current switch value: %d\n", TAG, g_switch_value);
+ resp_rep->set_bool_value(resp_rep, PROPERTY_VALUE, g_switch_value);
+ }
+
+ printf("[%s]OUT-handle_get_request_on_switch() called..\n", TAG);
+ return true;
+}
+
+bool handle_set_request_on_switch(st_things_set_request_message_s *req_msg, st_things_representation_s *resp_rep)
+{
+ printf("[%s]IN-handle_set_request_on_switch() called..\n", TAG);
+
+ bool is_value_changed = false;
+
+ bool desired_value = false;
+ if (req_msg->rep->get_bool_value(req_msg->rep, PROPERTY_VALUE, &desired_value)) {
+ printf("[%s]current switch value: %d\n", TAG, g_switch_value);
+ printf("[%s]desired switch value: %d\n", TAG, desired_value);
+
+ if (g_switch_value != desired_value) {
+ g_switch_value = desired_value;
+ printf("[%s]changed switch value: %d\n", TAG, g_switch_value);
+ is_value_changed = true;
+ }
+
+ resp_rep->set_bool_value(resp_rep, PROPERTY_VALUE, g_switch_value);
+ }
+
+ if (is_value_changed) {
+ st_things_notify_observers(req_msg->resource_uri);
+ }
+
+ printf("[%s]OUT-handle_set_request_on_switch() called..\n", TAG);
+ return true;
+}
--- /dev/null
+/* ****************************************************************
+*
+* Copyright 2017 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.
+*
+******************************************************************/
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+int ess_process(void);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
--- /dev/null
+/* ****************************************************************
+*
+* Copyright 2017 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 <tinyara/config.h>
+
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <time.h>
+#include "st_things_sample.h"
+
+int time_set(unsigned int second, unsigned int microsecond)
+{
+ struct timespec current_time;
+
+ current_time.tv_sec = second;
+ current_time.tv_nsec = (long int)microsecond * 1000;
+
+ if (clock_settime(CLOCK_REALTIME, ¤t_time) != 0) {
+ return 0;
+ }
+
+ return 1;
+}
+
+#ifdef CONFIG_BUILD_KERNEL
+int main(int argc, FAR char *argv[])
+#else
+int st_things_sample_main(int argc, char *argv[])
+#endif
+{
+ printf("st_things_sample!!\n");
+
+ // set system default time (2017/01/01 0:0:0)
+ time_set(1495089694, 0);
+
+ ess_process();
+
+ return 0;
+}