This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Zigbee Smart Home demo

Hello,
I came across this twitter clip by Marjeris showing a Thingy 52 relaying temp info to Alexa.
How was this done? by mqtt? or as gadget?
thank-you,

Parents
  • Hi Simon,

    Sorry for the late reply. We used the BLE Thingy and Zigbee Color Light Bulb example as the starting point and modified it by adding Zigbee Temperature sensor cluster and in this case, updated the temperature attribute of the cluster everytime we got a new temperature reading from the Thingy temperature characteristic. I have tried to write down some steps you can follow if you want to try to add temperature readings to the BLE thingy and Zigbee Color Light bulb example:

    Declare a new endpoint with Zigbee temperature sensor cluster (you can use the Zigbee Multisensor example as a guideline).

    In ble_thingy_master.c we updated some structures to include updates of the temperature characteristic from the Thingy:

    /* Thingy device events passed to the main application. */
    typedef enum
    {
        THINGY_BUTTON_PRESSED,
        THINGY_BUTTON_RELEASED,
        THINGY_CONNECTED,
        THINGY_DISCONNECTED,
        THINGY_TEMPERATURE_UPDATE,
    } thingy_evt_t;
    
    /* Structure to contain characteristic for discovery purpose */
    typedef struct
    {
        uint8_t                     name[20];
        uint16_t                    handle;
    } characteristic_t;
    
    /* Structure for storing used Thingy's characteristic's */
    typedef struct
    {
        characteristic_t            battery_level;
        characteristic_t            led;
        characteristic_t            button;
        characteristic_t            button_cccd;
        characteristic_t            temp;
        characteristic_t            temp_cccd;
        uint16_t                    conn_handle;
        bool                        frame_lock;
    } thingy_device_t;
    
    /**@brief Callback definition for intercepting thingy device events. */
    typedef void (*thingy_evt_handler_t)(thingy_device_t * p_thingy, thingy_evt_t evt, ble_evt_t const * p_ble_evt);

    And we added a new case for THINGY_TEMPERATURE_UPDATE inside the thingy_event_handler() in main.c to store the new temperature inside a variable and set a flag to update temperature cluster.

    case THINGY_TEMPERATURE_UPDATE:
                new_temperature = (zb_int16_t)p_ble_evt->evt.gattc_evt.params.hvx.data[0];
                if (new_temperature != m_temperature)
                {
                    m_temperature = new_temperature;
                    NRF_LOG_INFO("main temperature update %d", p_ble_evt->evt.gattc_evt.params.hvx.data[0]);
                    m_update_temperature_flag = true;
                }
                else
                {
                    NRF_LOG_INFO("same temperature (%d)", new_temperature);
                }
                break;

    Then called update_temperature() function from main loop to update the ZCL temperature cluster using zb_zcl_set_attr_val() for a new temperature reading:

    static void update_temperature(zb_int16_t temperature)
    {
        zb_zcl_status_t zcl_status;
        static zb_int16_t new_temp_value;
        
        /* Get new temperature measured value */
        new_temp_value = temperature;
        new_temp_value = new_temp_value * 100;
        zcl_status = zb_zcl_set_attr_val(MULTI_SENSOR_ENDPOINT,
                                         ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT,
                                         ZB_ZCL_CLUSTER_SERVER_ROLE,
                                         ZB_ZCL_ATTR_TEMP_MEASUREMENT_VALUE_ID,
                                         (zb_uint8_t *)&new_temp_value,
                                         ZB_FALSE);
        if (zcl_status != ZB_ZCL_STATUS_SUCCESS)
        {
            NRF_LOG_INFO("Set temperature value fail. zcl_status &d", zcl_status);
        }
        else
        {
            NRF_LOG_INFO("Set temperature value success, val: 0x%04x, %d", new_temp_value, new_temp_value);
        }
    }

    Main loop at the end of main():

        /* Enter main loop */
        for (;;)
        {
            if(m_update_temperature_flag)
            {
                m_update_temperature_flag = false;
                update_temperature(m_temperature);
            }
            zboss_main_loop_iteration();
            UNUSED_RETURN_VALUE(NRF_LOG_PROCESS());
        }

    Links to the infocenter pages for the Zigbee examples that were used:

    BLE Thingy and Zigbee multiprotocol example: https://infocenter.nordicsemi.com/topic/sdk_tz_v4.1.0/zigbee_multi_dynamic_color_light_sed_thingy_master.html

    Zigbee multisensor example: https://infocenter.nordicsemi.com/topic/sdk_tz_v4.1.0/zigbee_multi_sensor_example.html

    Best regards,

    Marjeris

  • Hello Marjeris,

    this is helpful in understanding how to add the BLE thingy to the Zigbee Color Light bulb example.

    The other part of interest is the actual conversation with Alexa.

    Which example was used to have Alexa issue a directive,
    and in turn, have the thingy (840DK with Zigbee) respond with an event?


    thank-you,

  • Hi Simon,

    Alexa recognized the device automatically as a temperature sensor because of the zigbee temperature cluster, so it was added as a common zigbee temperature sensor device which Alexa had already voice command buid-in support for. We didn't use Alexa gadgets or skills in this demo. One thing that perhaps didn't come well explained in the video for that demo is that Alexa is not communicating with the Thingy:52 directly, but through a nRF52840 dongle used as a Zigbee/BLE gateway.

    Unfortunately I don't yet have experienced with creating new skills with Alexa, but we have just released an example using Amazon gadgets for BLE in NCS, it may be of help if you want to create a Amazon gadget using Thingy:52 directly: https://github.com/nrfconnect/sdk-nrf/tree/master/samples/bluetooth/alexa_gadget

    I think you should be able to compile the example for the Thingy:52 board. If you have some issues perhaps take a look at this other case where somebody have already tried to do it: https://devzone.nordicsemi.com/f/nordic-q-a/68569/error-building-alexa-gadget-example-in-nrf-connect-sdk

    Best regards,

    Marjeris

  • Hello Marjeris,

    I have the NCS-Zephyr gadget example working fine,
    and I was hoping to find some hints as to how this could be redone on nrf5 SDK,
    which could have been through this zigbee smart home demo.

    thank-you,

Reply Children
  • Hi Simon,

    Sorry for the innactivity due to the Holidays. It seems you have been in contact directly with Audun. To quote him "there are no technical limitations with the nRF5 SDK or SoftDevice that prevents one from running Gadgets there. A lot of the code from the  NCS example can be reused but you would have to replace some NCS dependencies with the nRF5 SDK equivalent, such as bluetooth functions and callbacks."

    Since it seems you have already gotten an answer for you question I recommend you closing this case if there are no other questions.

    BR,

    Marjeris

  • Our product is built around nRF5 SDK examples and all the available features that come with it.
    When the main IDE was transitioning from Keil to SES, there was a guide explaining how to migrate to SES, until all the examples became available on SES.
    A guide like that explaining how to migrate from nRF5 SDK to NCS-Zephyr would be of some help here,
    and if not a guide then maybe a common example to compare and see which part goes where.
    Having the gadget example in nRF5 would be even better.
    Unfamiliarity with the zephyr structure is what's hindering the matter of fact reply.

    thank-you,

  • Unfortunately, there is no easy way to create a simple migration guide from nRF5 SDK to NCS. There is a beast of features (libraries, drivers, protocols, examples) which in each could have their own individual migration guides in itself.

    But we do have a list of guides on Devzone for getting started with nRF Connect SDK: https://devzone.nordicsemi.com/nordic/nrf-connect-sdk-guides/

    If you want to migrate properly to NCS in most cases you need to start your project from scratch anyways.

    Simon said:
    Having the gadget example in nRF5 would be even better.

    Unfortunately I don't know if this is in the scope for future releases. You can try getting in contact with your RSM and requesting this, but it's probably easier if you try adapting the example yourself.

    BR,

    Marjeris

  • ok, I'll continue chipping away at the code.
    Curious as to why the gadget example was written in NCS-Zephyr for dual-chip,
    when most gadgets would be single chip nRF5.

    +1 for a nRF5 gadget version

Related