How to Build Direct Connected Devices

The SmartThings IoT SDK is C, but you can you extern the main_app function as C and extern the iot-core includes as C and you’re good to go. The rest of your app can use c++. All the other capabilities still work just fine, and my custom one did work with C++ earlier before I changed it.

I see nothing in the terminal output of my esp32. It’s as if the app just fails before even attempting to send a message (keep in mind the CLI works, and the request makes it to my devices and works fine) and the other way works still too (i.e. if I trigger the capability state change on my device it updates the app).

Yes, I updated the onboarding_config.json when I created a whole new project (new devices keys and everything). Didn’t fix anything.

Edit: I figured out what was wrong. When I updated the capability I didn’t have the setter property set thus it got deleted. I was thinking PUT would work like PATCH.

How to Build Direct Connected Devices - #29 by Edward_shamosh

at this point, I’m looking to hire someone to write the code for me because I have to focus on manufacturing my product is there a forum topic here for hiring a developer I looked on fiver but no one wanted to work on this for me

I have compiled the switch_example and flashed it to an NodeMCU v0.9 (ESP8266) but I’m wondering how the device will be able to connect to my WiFi. Can you elaborate on that?

I think you can refer https://github.com/SmartThingsCommunity/st-device-sdk-c-ref/blob/master/doc/getting_started.md#test

if I’m not mistaken it should be now in pairing mode now you need to add it to the smarthings app just like in the instructions posted in the previous reply if you got to this point now this is the easy part lol

Thank you for your response. I have read the getting_started and my problem is that I have trouble adding the NodeMCU with the compiled code. It all comes down to that it’s not clear to me, how the device can be discovered from the app as it’s not yet connected to my WiFi.
A. Will the SmartThings app try to onboard the device by connecting directly to it and through this connection pass on SSID and password or
B. Should the device be connected to the WiFi before it’s added in the SmartThings app.

If A: There’s three buttons on the device. Two onboard (Flash and User) and the button connected to GPIO5. I have tried to hold down these buttons in turn while adding the device but without luck. Onboarding keeps failing.

If B: How do I do that?

Hope this helps to understand my problem.

Best regards
Joachim

It works like A.
If you have trouble with dealing button event. how about to try with Just works type?
You can just select Just works instead of Button confirm at Confirm section(4th section) of onboarding screen.

1 Like

I use Arduino IDE to develop and flash my ESP8266. Now I am trying to make my device a Direct Connected device also using Arduino IDE. It sounds like that is possible, but can you tell me how you integrate the onboarding_config.json with the Arduino code?

I ended up just following the directions from SmartThings, which is actually just the directions the esp-idf provides. I would recommend learning about the esp-idf to use the SmartThings direct connect API.

Thanks for that recommendation. That does mean I will need to rewrite my arduino code as c code, correct? I was hoping there was a way to avoid that.

As @bban mentioned, This SDK runs on ESP-IDF.
I think it requires more effort to work it on Arduino-IDE than port your application code on ESP-IDF - it’s still C code.

@kwanghui Thank you for your reply. This is the impression that I am getting now, too. So, ESP-IDF it is. I will likely be back with a question or two.

I am trying to flash my ESP8266 and run into the following problem:

python3 build.py apps/esp8266/switch_example flash gives:

/Users/bartborghuis/st-device-sdk-c-ref/bsp/esp8266/components/mbedtls/mbedtls/library/x509_crt.c:1676:44 error: ‘x509_crt_verify_strings’ defined but not used [-Werror=unused-const-variable=]
static const struct x509_crt_verify_string x509_crt_verify_strings = {
^~~~~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
make[1]: *** [mbedtls/library/x509_crt.o] Error 1
make: *** [component-mbedtls-build] Error 2

Any help would be great! Thank you.

Has anyone noticed memory leaks with the core SDK? My long-running apps seem to be slowing increasing the amount of memory used, and it has me concerned.

Are there any gotcha’s in terms of memory management regarding the API? I dutifully do a st_cap_free_attr after every call to st_cap_send_attr.

Anything else I need to pay attention to?

Hi again

I have come a bit further since late december :-). I found out that my problem regarding onboarding were due to faulty wiring. I missed that I should connect GPIO13 to GND and when that was resolved I got a bit further.
During onboarding my switch device is now discoved when I hold the button 5 seconds. The onboarding continues until it reached 39% and then it fails with error code 38-003. I can see that my test device now exposes a wifi accesspoint called something like ‘Switch_Exampl_E4fSr…’ and I suspect that onboarding fails when trying to connect to this but I’m not entirely sure.
Can anyone help me solve this problem? I feel that after spending countless hours on this project I’m very close to succeding.
By the way - I have tried to disable ‘switch to mobile data’ as the help in the app suggests but onboarding still fails.

Any suggestions is very much appreciated.

Best regards
Joachim Hoffmann

Hi Joachim -

I’ve done quite a number of device onboarding and find that the process is fairly error prone. It fails maybe a third of the time for various reasons - none having to do with the device app itself, but with the core SDK, mobile app, and SmartThings MQTT server.

Because I’m working on a Raspberry Pi I can see all the log messages and this helps see when/where things are failing or hanging. Are you able to see any log messages? There are parameters you can set in the make configuration that allows you to set the level of errors displayed. There is also some kind of facility to log messages to storage, but I haven’t played with that.

It’s good progress that your device is going into SoftAP mode since you see it turning on it’s access point. Is the mobile app asking you to connect to it? What you should see on the mobile app within about 20 seconds after that is a list of available wireless SSIDs for your device to connect to after initial provisioning is done. If you get that far and select your SSID and enter its password, it can then take up to 40 seconds or so for your device to wait to hear back from the SmartThings MQTT server with a device registration confirmation.

Hi @TAustin

First, thank you for your interest in my post. I do appreciate it. Unfortunately, I am totally in the blind when it comes to log messages. I started out trying to build the IoT toolchain on Windows but ran into a lot of problems and decided to install Ubuntu on a Hyper-V instance and build the toolchain there instead. After a lot of time spend on this – mostly because I am total Linux newbie – I succeeded compiling the switch example and ended up with the four binaries that I could not flash to the ESP8266. I could not connect to the serial port on the host from my virtual machine. I figured to move the binaries to Windows and flashed them by using a program called NodeMCU Flasher. I used the addresses from the output text file that were part of the output from the compilation. But because of this I have no way to gain any insights from any log messages from the device. Not at all sustainable but that is where I am right now. I am trying to get a WSL subsystem with toolchain and all the other necessary tools up and running and hope to get more log insights as I expect to be able to flash the ESP directly from Ubuntu on WSL in this setup.

Well – back to your other question. My mobile app is not asking to connect to the SoftAP but I can see that my phone disconnects from my normal WiFi and tries to connect the SoftAP. I see that by initiating the onboarding procedure and right after that jump into WiFi settings on my phone.
I can see that the device responds to onboarding as the LEDs starts to flash after I hold the button on the device as part of the onboarding. I have tried like 10 times and onboarding always stops at 39% with error code 38-003 that not even Google knows anything about.

Any clues or hints are very welcome.

@kwanghui I have a device I’m creating that has a lot of components. The max to be exact at 20. When my device connects, it tries to initialize all the capabilities at once and causes the rate limit to be hit. Is there a way I can introduce a delay or slow it down?

@kwanghui I’ve solved the rate limit issue by adding a delay in the capability init callback.

The new issue (and maybe @nayelyz can answer to) I have is I’m implementing the button capability. When the button is ‘pressed’ I update the value with ‘pushed’ and send it. The problem I’m having is the automations don’t get triggered till I ‘double’ press the button (updating the capability value to ‘double’) then press it again. I assume this is because the state of the capability gets set to ‘pressed’ and pressing the button again doesn’t change the state and the automation isn’t triggered.

Is the button device responsible for clearing the button state after a press/double/held event? I don’t see a way to do that from the button capability.

I don’t know anything about direct connected devices, but I do know about the Button capability and the button attribute does not accept the ‘pressed’ value. It is pushed.

1 Like