Integrate IoT Devices into the SmartThings Ecosystem
qr code using the device qr code could be helpful while device onboarding qr code should have format like below refer here for more details urlhttps //qr samsungiots com/?m={your mnid}&s={device onboardingid}&r={device serialnumber} {your mnid} 4-digit alphanumeric mnid of your account {device onboardingid} 3-digit number onboarding id, you can find it from your developer workspace project device onboarding > other info page {device serialnumber} device serial number which is registered at your developer workspace project you can simply generate qr code with using below python script import qrcode mnid = 'ffff' # "ffff" is an example you should replace it with yours onboardingid = '111' # "111" is an example you should replace it with yours serialnumber = 'stdktest0001' # "stdktest0001" is an exmaple you should replace it with yours qrurl = 'https //qr samsungiots com/?m=' + mnid + '&s=' + onboardingid + '&r=' + serialnumber img = qrcode make qrurl img save serialnumber + ' png' qrcode qrcode box_size=10, border=4 write device application open and edit sample device app currently, you are doing the code lab example, which is located at apps/esp32/code_lab_example directory in the github repository download onboarding_profile json from the overview of your device in developer workspace copy onboarding_profile json file into your application directory, apps/esp32/code_lab_example/main $ cd ~/workspace/st-device-sdk-c-ref/apps/esp32/code_lab_example/main/ $ cp ~/downloads/onboarding_config json copy device_info json from tools/keygen/linux/output_{serialnumber} which contains your device specific information to application directory, apps/esp32/code_lab_example/main $ cd ~/workspace/st-device-sdk-c-ref/iot-core/tools/keygen/ $ cp output_{serialnumber}/device_info json ~/workspace/st-device-sdk-c-ref/apps/esp32/code_lab_example/main/ firmwareversion version string privatekey base64 encoded ed25519 private key this value should be paired with what you registered to developer workspace publickey base64 encoded ed25519 public key this value should be same with what you registered to developer workspace serialnumber this value should be same with what you registered to developer workspace { "deviceinfo" { "firmwareversion" "switch_example_001", "privatekey" "dh**jkmrd5x****bav+fgoxa3qzfnw3v****jhxomd0=", "publickey" "nfn5x***uqusq****zhobsfaaop9***kndlnjdjrew=", "serialnumber" "stdk**e90w***ucx" } } open sample application source code browse in apps/esp32/code_lab_example/main/ directory open main c file write your device application code this example already has cloud connection functionality using smartthings sdk apis void app_main void { /** easily integrate your direct connected device using the direct connected devices sdk the sdk manages all mqtt topics and onboarding requirements, freeing you to focus on the capabilities of your device that is, you can simply develop a basic application by just calling the apis provided by st_iot_core layer like below // create a iot context 1 st_conn_init ; // create a handle to process capability 2 st_cap_handle_init ; called in function 'capability_init' // register a callback function to process capability command when it comes from the smartthings server 3 st_cap_cmd_set_cb ; called in function 'capability_init' // process on-boarding procedure there is nothing more to do on the app side than call the api 4 st_conn_start ; */ unsigned char *onboarding_config = unsigned char * onboarding_config_start; unsigned int onboarding_config_len = onboarding_config_end - onboarding_config_start; unsigned char *device_info = unsigned char * device_info_start; unsigned int device_info_len = device_info_end - device_info_start; int err; iot_gpio_init ; xtaskcreate app_main_task, "app_main_task", 4096, null, 10, null ; //create a iot context iot_ctx = st_conn_init onboarding_config, onboarding_config_len, device_info, device_info_len ; if iot_ctx != null { err = st_conn_set_noti_cb iot_ctx, iot_noti_cb, null ; if err printf "fail to set notification callback function\n" ; } else { printf "fail to create the iot_context\n" ; } //create a handle to process capability and initialize capability info capability_init ; //connect to server err = st_conn_start iot_ctx, st_status_cb &iot_status_cb, iot_status_all, null, null ; if err { printf "fail to start connection err %d\n", err ; } } complete your command callback function for each capability the command callback function should contain your device control upon each command such as led on or off control capability example for each capability would be helpful to handle attribute command for each capability you can find it at apps/capability_example/main static void update_switch_state int switch_state { const char* switch_value; if switch_state == switch_on { switch_value = caps_helper_switch attr_switch value_on; } else { switch_value = caps_helper_switch attr_switch value_off; } //todo set switch attribute value and send // // example //=============================================================================== // cap_switch_data->set_switch_value cap_switch_data, switch_value ; // cap_switch_data->attr_switch_send cap_switch_data ; //=============================================================================== } static int get_switch_state void { const char* switch_value; int switch_state = switch_off; //todo get switch attribute value // // example //=============================================================================== // switch_value = cap_switch_data->get_switch_value cap_switch_data ; // // if !strcmp switch_value, caps_helper_switch attr_switch value_on { // switch_state = switch_on; // } else if !strcmp switch_value, caps_helper_switch attr_switch value_off { // switch_state = switch_off; // } //=============================================================================== return switch_state; } static void cap_switch_cmd_cb struct caps_switch_data *caps_data { int switch_state = get_switch_state ; set_led_mode switch_state ; } static void capability_init { //todo initialize switch capability with using capability sample's initializae function // // example // //=============================================================================== // cap_switch_data = caps_switch_initialize iot_ctx, "main", null, null ; // if cap_switch_data { // const char *switch_init_value = caps_helper_switch attr_switch value_on; // // cap_switch_data->cmd_on_usr_cb = cap_switch_cmd_cb; // cap_switch_data->cmd_off_usr_cb = cap_switch_cmd_cb; // // cap_switch_data->set_switch_value cap_switch_data, switch_init_value ; // } //=============================================================================== } build, flash, and monitor you can build, flash, and monitor in the console with the following $ cd ~/workspace/st-device-sdk-c-ref $ python3 build py apps/esp32/code_lab_example $ python3 build py apps/esp32/code_lab_example flash $ python3 build py apps/esp32/code_lab_example monitor or $ cd ~/workspace/st-device-sdk-c-ref $ python3 build py apps/esp32/code_lab_example flash monitor onboard and control the device via smartthings app onboarding a enable developer mode developer mode should be enabled on smartthings mobile application launch the smartthings app, go to dashboard > settings long-press about smartthings for 20 seconds enable the developer mode, then restart the smartthings app you can find out more information here b add a new device go to add device and click my testing devices or scan qr code you can now see and add your self-published devices control by smartthings application a device control from dashboard you can turn your device’s led on or off by clicking the button in the smartthings app b device control from plugin you can control various attributes and get more detailed information from the device plugin user interface you're done! congratulations! you have successfully achieved the goal of this code lab now, you can control your iot devices using the smartthings app all by yourself! if you're having trouble, you may download this file smartthings device sdk complete code 2 49 kb