How to Build Direct Connected Devices

The wifi module is part of the BSP, so why couldn’t we just skip over the SoftAP part of the wifi_init process and simply store the current ethernet connection info wherever you require it (seems to be in files called WifiProvStatus, IotAPSSID, IotAPBSSID, IotAPPass, etc), and let the code continue to the Cloud provisioning?

You may be shocked to know I’ve been debugging through your code :wink: in trying to find a way for this to work and I’m making some progress, however I think part of the challenge is to get all the right stdkconfig flags set for this “hybrid” environment without really understanding them all.

Right now I’m running into a problem with es_mbedtls_task looking for a device certificate(??) during st_conn_start. I suspect I have a config flag setting wrong, because it should be using the generated keys stored in the device_info.json (I am guessing!).

Thanks for your interest.
Direct connected device on-boarding is designed for 3-way method between device, mobile app, cloud for secure manner. So it wouldn’t be easy to make standalone device on-boarding without communication between device and mobile app.
But unfortunately mobile app detect direct connected device by scanning and connecting to device’s Soft AP.

BTW, regarding es_mbedtls_task you should disable STDK_IOT_CORE_EASYSETUP_X509 feature.

1 Like

Ohhhh I see now why Soft AP is required. Thank you for helping me understand that! So we really do need to have the whole SoftAP / station mode capability running.

Well, I’m not against some additional setup if there is a way to make it work. It sounds like you have at least been thinking about a solution, and I very much appreciate that. If there is anything I can help with or be an alpha or beta tester, I’m at your service as I have a keen interest in a solution here.

I will try your suggestion to comment out the x509 flag, but I think I tried that already :thinking:

3 Likes

and what if I’m adding a duplicate function like 2 buttons instead of one what do I do then how do i asdress it to another components

is that thes section

static void capability_init()

{

cap_switch_data = caps_switch_initialize(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);

I think you don’t need to add secondary health check. if leave new switch at main2 component.
And you need to your device application to handle switch capability of main2 component.

Here is an example code which adds dust sensor capability to monitor component.

You can simply try to initialize like this

    cap_secondary_switch_data = caps_switch_initialize(ctx, "main2", NULL, NULL);
    if (cap_secondary_switch_data) {
        const char *switch_init_value = caps_helper_switch.attr_switch.value_on;

        cap_secondary_switch_data->cmd_on_usr_cb = cap_switch_cmd_cb;
        cap_secondary_switch_data->cmd_off_usr_cb = cap_switch_cmd_cb;

        cap_secondary_switch_data->set_switch_value(cap_secondary_switch_data, switch_init_value);
    }
1 Like

For all those interested in the topic of direct-connected devices, see my post regarding beta announce of Raspberry Pi-based device apps:

Hi all - I have some questions:

  1. Does the direct-connected API support the use of custom capabilities in the device app, or is it limited to just the standard ST-defined capabilities?
  2. Can custom capabilities be selected for a direct-connected device in the Developer Workspace device definition?

Maybe out of scope for this topic, but related to the above:
3. Will there be a mechanism to post/share/use community-developed custom capabilities ?(similar to what we used to have with being able to find community-developed custom device handlers in the old app)

1 Like

I’d like to echo the questions regarding custom capabilities above and add a couple more:

  1. I develop on ESP-IDF 3.3 which is not Debian/Ubuntu - is there something about the SDK that won’t work in any other environment?
  2. I connected a few devices to the hub via the IDE and custom capabilities. It’s pretty fast and simple. Any advantage for using the SDK (latency, functionality) over the IDE?

The IDE goes away in about a year… Thats kinda a big reason…

I have a ESP 32 board from Adafruit (Huzzah32) that I use with SmartThings. It runs a rest API and the hub issues requests to it using the soon to be deprecated groovy DTH.

All the examples seem to be centered around using the SmartThings provided utilities to flash the chip. Is it possible to just consume the API and use Arduino IDE to build and program the chip?

Yes you can use an http client of your own design and work directly with the API, this is a custom firmware solution that does that and much more. For device provisioning you will need to create a schema or endpoint connection if you want to roll your own

Was the intention of the direct connected API to be the sole orchestrator on the device (i.e. only for devices that only work with SmartThings)? It appears connecting the Wifi is baked into st_conn_init and a lot of other system setup as well. I had expected the API to be less coupled to the platform but it’s nice that you guys did handled a lot of the low level work.

I’m used to working with my ESP32 with Arduino which is a fancy wrapper around the edp-idf. It provides quite of bit of simplification over esp-idf. However, I understand that arduino-esp is probably not suitable for manufactures but for DIY hobbyists and probably most of the people reading this it makes it quite easy to get devices working. A lot of my devices I developed for my SmartThings eco-system are using arduido-esp and libraries that were intended for aruindo-esp. Most notably Fast-LED. With this change I’m going to have to rewrite all of my devices, which I’m still not certain will be possible if I have to change to esp-idf =(.

You may consider using arduino as a component of ESP-IDF. arduino-esp32/esp-idf_component.md at master · espressif/arduino-esp32 · GitHub
It gives you the flexibility of ESP-IDF and the simplicity of arduino. You can still use mqtt and freeRTOS . It will also allow you to easily change the setup with menuconfig . for ex. creating another task for the second core - something that you can’t do with Arduino IDE since the ESP32 is limited to a single core in the setup.

Hey there - I didn’t see anyone answer your question, so thought I’d comment. I’ve got the direct connect stuff operating on Raspberry Pi so have learned quite a lot about how it works. I may not be getting your question quite right, but here’s what I’d say: I think you could have other things controlling or changing the device, and then use the ST API to keep ST updated on it’s state. So I don’t think using the API excludes you from doing other things, but once you decide you will use it, you ARE forced to go through the one-time provisioning via wifi (st-conn_start). But after that, it’s up to you whether you want to always be connected to it.

Jody - can you please comment on the questions above regarding custom capability support?

It’s my understanding that some time this year they are going to shut down the IDE and all groovy-related capabilities. So you will no longer be able to use that method to connect devices. The SDK gives you a path to live in the new world once that happens.

Until ST announces a way to use shared custom capabilities, you have to re-create them under your own ID in order to use them in the direct connect schema. At least that’s my understanding at the moment. I’m about to test if you can really do that.

I’ve spent a few more days with the direct-connect API and really like it. It’s very nice how much it handles. I was able to find a esp-idf port of FastLED and converted an example to c++. Everything was working today just fine. At least till I tried to update a custom capability to add another enum value.

It apparently broke that capability on the app. when I select it and try to change a value I get a network error, but the capability with the new value still working through the CLI (So I know MQTT is working) and the console uart cli also confirms it works in the other direction (changing the value on the device and seeing it reflect in the app). I’ve re added the capability and even created new ones, and even reconfigured a new project, the same problem still exists. I don’t know what to do at this point. Ever experienced that? Know what to do?

I can’t be of much there yet; I’m just starting to try to use custom capabilities. What a nightmare this cli is right now…
I didn’t think the SDK supports C++, so are you sure that is not causing the problem?

That’s strange that you would get a network error for something like that. Are you able to see all the terminal output messages from the core SDK on your esp?

The change you made - did it require a new onboarding_config.json? If so, you rebuilt your app with the new one?

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

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