Adding a new cid value in light example

XiotSamuel
Posts: 53
Joined: Sun Aug 29, 2021 1:50 pm

Adding a new cid value in light example

Postby XiotSamuel » Tue Nov 16, 2021 2:52 am

Hi all. I am using the light example in the MDF library for adding new cid value.

I have try to add a new value[SENSOR_CID_STATUS] in mlink_set_value

The modified code in the light_handle.c

Code: Select all

mdf_err_t mlink_set_value(uint16_t cid, void *arg)
{
    int value = *((int *)arg);

    switch (cid) {
        case LIGHT_CID_STATUS:
            switch (value) {
                case LIGHT_STATUS_ON:
                case LIGHT_STATUS_OFF:
                    light_driver_set_switch(value);
                    // if (value == 1){
                    //     //saving value of user setted luminance
                    //     mdf_info_save("luminance", 100, sizeof(int));
                    // }else {
                    //     mdf_info_save("luminance",0, sizeof(int));}
                    break;

 ..........
        case LIGHT_CID_BRIGHTNESS:
            light_driver_set_brightness(value);
            break;

        case SENSOR_CID_STATUS:
            MDF_LOGI("SENSOR_CID_STATUS ohere lalala");
            switch (value) {
                case LIGHT_STATUS_ON:
                    MDF_LOGI("SENSOR_CID_STATUS ohere lalala");
                    if (light_driver_get_switch()== 1) {
                        
                    }                   
                    break;
                case LIGHT_STATUS_OFF:
                    MDF_LOGI("SENSOR_CID_STATUS ohere lalala");
                    if (light_driver_get_switch() == 0){
                        
                    }
                    break;
                default:
                    break;

            }
            break;

        default:
            MDF_LOGE("No support cid: %d", cid);
            return MDF_FAIL;
    }

    MDF_LOGD("cid: %d, value: %d", cid, value);

    return MDF_OK;
}


The code to send the message

Code: Select all


                    MDF_LOGI("Format control message (light on). dest addr:" MACSTR, MAC2STR(dest_addr));
                    size = asprintf(&data, "{\"type\":\"sensor_control\",\"request\": \"set_status\",\"characteristics\": [{\"cid\": 7,\"value\": 1}]}\n");
                    
                    ret = mwifi_write(dest_addr, &mwifi_type, data, size, true);
                    memcpy(&mwifi_type.custom, &header_info, sizeof(mlink_httpd_type_t));

But, the lighthandle.c seem cannot get the new value [SENSOR_CID_STATUS]. Any reason for that? or Any other part I need to check/modify?

Who is online

Users browsing this forum: No registered users and 5 guests