BT Mesh on Mesh Kit - Add a 2nd Sensor to the Temp Sensor Example

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
MiRo_263836
Level 5
Level 5
100 replies posted 50 likes received 50 replies posted

I have an ambient light sensor that I want to add to the temp sensor example.  Is there a 2 sensor example available?  Can you tell the the required steps?  I have integrated the light sensor driver in the temp sensor demo and have that working.  I just need to know how to add it to the mesh.

I created a 2nd element.

wiced_bt_mesh_core_config_model_t   mesh_element2_models[] =

{

WICED_BT_MESH_MODEL_SENSOR_SERVER,

};

#define MESH_APP_NUM_MODELS_RED  (sizeof(mesh_element2_models) / sizeof(wiced_bt_mesh_core_config_model_t))

wiced_bt_mesh_core_config_sensor_t mesh_element2_sensors[] =

{

    {

        .property_id    = WICED_BT_MESH_PROPERTY_PRESENT_AMBIENT_LIGHT_LEVEL,

        .prop_value_len = WICED_BT_MESH_PROPERTY_LEN_PRESENT_AMBIENT_LIGHT_LEVEL,

        .descriptor =

        {

            .positive_tolerance = MESH_RED_SENSOR_POSITIVE_TOLERANCE,

            .negative_tolerance = MESH_RED_SENSOR_NEGATIVE_TOLERANCE,

            .sampling_function  = MESH_RED_SENSOR_SAMPLING_FUNCTION,

            .measurement_period = MESH_RED_SENSOR_MEASUREMENT_PERIOD,

            .update_interval    = MESH_RED_SENSOR_UPDATE_INTERVAL,

        },

        .data = (uint8_t*)&mesh_sensor_sent_value,

        .cadence =

        {

            // Value 0 indicates that cadence does not change depending on the measurements

            .fast_cadence_period_divisor = 64,          // Recommended publish period is 320sec, 64 will make fast period 5sec

            .trigger_type_percentage     = WICED_FALSE, // The Property is Bool, does not make sense to use percentage

            .trigger_delta_down          = 0,           // This will not cause message when presence changes from 1 to 0

            .trigger_delta_up            = 1,           // This will cause immediate message when presence changes from 0 to 1

            .min_interval                = (1 << 10),   // Milliseconds. Conversion to SPEC values is done by the mesh models library

            .fast_cadence_low            = 1,           // If fast_cadence_low is greater than fast_cadence_high and the measured value is either is lower

                                                        // than fast_cadence_high or higher than fast_cadence_low, then the message shall be published

                                                        // with publish period (equals to mesh_sensor_publish_period divided by fast_cadence_divisor_period)

            .fast_cadence_high           = 0,           // is more or equal cadence_low or less then cadence_high. This is what we need.

        },

        .num_series     = 0,

        .series_columns = NULL,

        .num_settings   = 0,

        .settings       = NULL,

    },

};

And I added a 2nd element to the core config

wiced_bt_mesh_core_config_element_t mesh_elements[] =

{

    {

        .location = MESH_ELEM_LOC_MAIN,                                  // location description as defined in the GATT Bluetooth Namespace Descriptors section of the Bluetooth SIG Assigned Numbers

        .default_transition_time = MESH_DEFAULT_TRANSITION_TIME_IN_MS,   // Default transition time for models of the element in milliseconds

        .onpowerup_state = WICED_BT_MESH_ON_POWER_UP_STATE_RESTORE,      // Default element behavior on power up

        .default_level = 0,                                              // Default value of the variable controlled on this element (for example power, lightness, temperature, hue...)

        .range_min = 1,                                                  // Minimum value of the variable controlled on this element (for example power, lightness, temperature, hue...)

        .range_max = 0xffff,                                             // Maximum value of the variable controlled on this element (for example power, lightness, temperature, hue...)

        .move_rollover = 0,                                              // If true when level gets to range_max during move operation, it switches to min, otherwise move stops.

        .properties_num = 0,                                             // Number of properties in the array models

        .properties = NULL,                                              // Array of properties in the element.

        .sensors_num = 1,                                                // Number of properties in the array models

        .sensors = mesh_element1_sensors,                                // Array of properties in the element.

        .models_num = MESH_APP_NUM_MODELS,                               // Number of models in the array models

        .models = mesh_element1_models,                                  // Array of models located in that element. Model data is defined by structure wiced_bt_mesh_core_config_model_t

    },

    {

        .location = MESH_ELEM_LOC_MAIN,                     // location description as defined in the GATT Bluetooth Namespace Descriptors section of the Bluetooth SIG Assigned Numbers

        .default_transition_time = MESH_DEFAULT_TRANSITION_TIME_IN_MS,   // Default transition time for models of the element in milliseconds

        .onpowerup_state = WICED_BT_MESH_ON_POWER_UP_STATE_RESTORE,      // Default element behavior on power up

        .default_level = 0,                                              // Default value of the variable controlled on this element (for example power, lightness, temperature, hue...)

        .range_min = 1,                                                  // Minimum value of the variable controlled on this element (for example power, lightness, temperature, hue...)

        .range_max = 0xffff,                                             // Maximum value of the variable controlled on this element (for example power, lightness, temperature, hue...)

        .move_rollover = 0,                                              // If true when level gets to range_max during move operation, it switches to min, otherwise move stops.

        .properties_num = 0,                                             // Number of properties in the array models

        .properties = NULL,                                              // Array of properties in the element.

        .sensors_num = 1,                                                // Number of properties in the array models

        .sensors = mesh_element2_sensors,                                // Array of properties in the element.

        .models_num = MESH_APP_NUM_MODELS_RED,                            // Number of models in the array models

        .models = mesh_element2_models,                                  // Array of models located in that element. Model data is defined by structure wiced_bt_mesh_core_config_model_t

    },

};

Is this correct and what else do I need to do?

Thanks,

Mike Roberts

0 Likes
1 Solution

I did something correctly.  I am seeing 2 devices once provisioned in the iOS App.  One with the Property ID: Temperature and one with Property ID: Light Level.  Now I just need to get the data over correctly.  The Temp Sensor GET is timing out.  I will check it out.

View solution in original post

26 Replies
MiRo_263836
Level 5
Level 5
100 replies posted 50 likes received 50 replies posted

One other question. Does it require a an NVRAM_ID like the Temp Sensor

#define MESH_TEMPERATURE_SENSOR_CADENCE_NVRAM_ID        WICED_NVRAM_VSID_START

I created a #define just adding 0x100 to  VSID_START

#define MESH_AMBIENT_SENSOR_CADENCE_VSID             WICED_NVRAM_VSID_START + 0x100

is this OK?

0 Likes

Yes, you will need to have a separate VSID for the second element because Configuration Manager can configure cadence for every sensor differently and it shall be persistent. + 1 should work the same as + 256.

Don't forget to initialize sensor_server_model on both elements. You will probably also need to have 2 timers.  The client can configured to send you temperature once per hour and ambient light sensor data once per 10 minutes or 10 times more often if the level significantly changes.

0 Likes

I have never done a wiced timer before, so I am using the temp sensor example.

This is the temperature sensor cadence.  

// initialize the cadence timer.  Need a timer for each element because each sensor model can be    

// configured for different publication period.  This app has only one sensor.    

wiced_init_timer(&mesh_sensor_cadence_timer,&mesh_sensor_publish_timer_callback,TIMER_PARAM_TYPE)&mesh_config.elements[MESH_SENSOR_SERVER_ELEMENT_INDEX].sensors[MESH_TEMPERATURE_SENSOR_INDEX], WICED_MILLI_SECONDS_TIMER);    

//restore the cadence from NVRAM    

wiced_hal_read_nvram(MESH_TEMPERATURE_SENSOR_CADENCE_NVRAM_ID, sizeof(wiced_bt_mesh_sensor_config_cadence_t), (uint8_t*)(&p_sensor->cadence), &result);

I actually am reading a red, green and blue sensor for ambient light, so this is the red sensor.  Do I need to create another variable different from

wiced_bt_mesh_core_config_sensor_t *p_sensor;

like

wiced_bt_mesh_core_config_sensor_t *p_red_sensor;  

 

wiced_init_timer(&mesh_red_sensor_cadence_timer,&mesh_red_sensor_publish_timer_callback,TIMER_PARAM_TYPE)&mesh_config.elements[MESH_SENSOR_SERVER_ELEMENT_INDEX].sensors[MESH_RED_SENSOR_INDEX],WICED_MILLI_SECONDS_TIMER);      

//restore the cadence from NVRAM     wiced_hal_read_nvram(MESH_RED_SENSOR_CADENCE_VSID,sizeof(wiced_bt_mesh_sensor_config_cadence_t), (uint8_t*)(&p_red_sensor->cadence), &result);

Do I need another mesh_model_server_data routine for the red sensor?

wiced_bt_mesh_model_sensor_server_data(MESH_SENSOR_SERVER_ELEMENT_INDEX, WICED_BT_MESH_PROPERTY_PRESENT_AMBIENT_TEMPERATURE, NULL);

Sorry if this is pretty basic stuff, but it is new to me.

0 Likes

I think you are missing ( before TIMER_PARAM_TYPE. You need 2 timers for 2 elements.  You can either provide 2 different callbacks.  Or you can specify one callback and pass the argument which will tell your callback which timer expired.  In the code that you quoted, the parameter is the address of the sensor configuration structure.  But you can pass whatever you want, for example an index.

I have the (TIMER_PARAM_TYPE) in my code.  I deleted it when I was formatting it to be readable. I will leave it as 2 callbacks for now. I am trying to understand the publish temperature callback and what I need and don't need for my light sensor.  I don't need to send time.  What can I remove? I don't need the percentage increase or decrease.  Can I remove all of that safely? What is the minimum code just to publish the light sensor data?

0 Likes
VictorZ_46
Employee
Employee
5 comments on blog 25 sign-ins 250 likes received

If you want to do production device you need to make sure that your device is spec compliant.  That means that somebody can configure your device any way they want and "I don't need the percentage increase or decrease" is not what you need, but what Configuration wants your device to do. If you are just playing with BLE mesh, to send the data you can fill

        .data = (uint8_t*)&mesh_sensor_sent_value,

with the current measurement

and tell mesh core to send it out by calling wiced_bt_mesh_model_sensor_server_data(element_index, 0, NULL); anytime. 

OK.  I thought the percentages were temperature limits, but they are timer percentages.  This is need to meet the spec. 

0 Likes

It is temperature percentages. So it published when it sees a delta of 0.01%?  Not sure how to set these up for my light sensor.

0 Likes
VictorZ_46
Employee
Employee
5 comments on blog 25 sign-ins 250 likes received

I did not participate in the beginning of the discussion and I do not know what exactly you are trying to publish.  The valid properties are defined in the Mesh Device Properties spec.

You need to publish when you see delta as configured in the cadence

0 Likes

Sorry.  I am very new to this.  It would be nice if there was another sensor example other than just temperature.  You have me spinning in circles. Just trying to publish a uint16_t from a light sensor.  Not concerned about changes right now.  What do the cadence and limits need to be set to?  I just changed the publish time to 5 sec.  Is there anything else that I need to change here?  I can just change the tests / percentages in the publish callback if I want to publish on a change, correct? wiced_bt_mesh_core_config_sensor_t mesh_element2_sensors[] = {     {         .property_id    = WICED_BT_MESH_PROPERTY_PRESENT_AMBIENT_LIGHT_LEVEL,         .prop_value_len = WICED_BT_MESH_PROPERTY_LEN_PRESENT_AMBIENT_LIGHT_LEVEL,         .descriptor =         {             .positive_tolerance = MESH_RED_SENSOR_POSITIVE_TOLERANCE,             .negative_tolerance = MESH_RED_SENSOR_NEGATIVE_TOLERANCE,             .sampling_function  = MESH_RED_SENSOR_SAMPLING_FUNCTION,             .measurement_period = MESH_RED_SENSOR_MEASUREMENT_PERIOD,             .update_interval    = MESH_RED_SENSOR_UPDATE_INTERVAL,         },         .data = (uint8_t*)&mesh_red_sensor_sent_value,         .cadence =         {             // Value 0 indicates that cadence does not change depending on the measurements             .fast_cadence_period_divisor = 64,          // Recommended publish period is 320sec, 64 will make fast period 5sec             .trigger_type_percentage    = WICED_FALSE, // The Property is Bool, does not make sense to use percentage             .trigger_delta_down          = 0,          // This will not cause message when presence changes from 1 to 0             .trigger_delta_up            = 1,          // This will cause immediate message when presence changes from 0 to 1             .min_interval                = (1 << 10),  // Milliseconds. Conversion to SPEC values is done by the mesh models library             .fast_cadence_low            = 1,          // If fast_cadence_low is greater than fast_cadence_high and the measured value is either is lower                                                         // than fast_cadence_high or higher than fast_cadence_low, then the message shall be published                                                         // with publish period (equals to mesh_sensor_publish_period divided by fast_cadence_divisor_period)             .fast_cadence_high          = 0,          // is more or equal cadence_low or less then cadence_high. This is what we need.         },         .num_series    = 0,         .series_columns = NULL,         .num_settings  = 0,         .settings      = NULL,     }, };

0 Likes
lock attach
Attachments are accessible only for community members.

Maybe it is easier to see if I attach the file.

0 Likes

I went to the Mesh Device Properties spec and this is what it says 3.9.8 Present Ambient Light Level property This property represents the light level as measured by a light sensor measuring illuminance (Lux). Characteristic: Illuminance I am reading Illuminance in lux. This really doesn't help.

0 Likes

I noticed that the Temperature is an 8 bit value and the .data in sensor_config is an 8 bit value.  How do I send a 16 bit value?  Is it better if I just convert it to an 8 bit value?

0 Likes

I did something correctly.  I am seeing 2 devices once provisioned in the iOS App.  One with the Property ID: Temperature and one with Property ID: Light Level.  Now I just need to get the data over correctly.  The Temp Sensor GET is timing out.  I will check it out.

Just trying to get data.  When I select the Temperature Sensor and click on get, I see this in the Debug Window ================ company_id:ffff opcode:8231 mesh_sensor_server_report_handler msg: 112 =================== When I select the Light Level Sensor and click on get ================ company_id:ffff opcode:8231 ================ but no mesh_sensor_server_report_handler msg: 112 What did I miss?  I did an init of the server data wiced_bt_mesh_model_sensor_server_data(MESH_RED_SENSOR_INDEX, WICED_BT_MESH_PROPERTY_PRESENT_AMBIENT_LIGHT_LEVEL , NULL);

0 Likes

I am sorry, but I still do not understand what you are trying to do. Is it a sensor which publishes Ambient Light Level property?  According to the spec

3.9.8 Present Ambient Light Level property

This property represents the light level as measured by a light sensor measuring illuminance (Lux).

Characteristic: Illuminance

Now you need to go to GATT Specification Supplement to find out that

3.94 Illuminance

3.94.1 Description

The Illuminance characteristic is used to represent a measure of illuminance in units of lux.

Illuminance Data Type: uint24 Size: 3 octets

Unit is lux with a resolution of 0.01. Minimum: 0 Maximum: 167772.14 Represented values: M = 1, d = -2, b = 0 Unit: org.bluetooth.unit.illuminance.lux A value of 0xFFFFFF represents ’value is not known’.

You cannot convert it to uint8 or to uint16.  Otherwise standard sensor client will not understand what you mean.

It might be interesting what you are putting in the cadence, but not really important.  A good client will configure you the way he needs the sensor to publish data.  And if he configures publication period to be 20 seconds, and fast cadence divisor 2 to publish data twice often if sensor value is between 10 and 50, you need to publish data exactly how client told you to do.

you should turn on Mesh Models traces, Hopefully it will provide you more info. The should be Mesh Models Debug flag in the project settings.  You will also need to add following in the app_init.

#if 1

    extern uint8_t wiced_bt_mesh_model_trace_enabled;

    wiced_bt_mesh_model_trace_enabled = WICED_TRUE;

#endif

I have an ADI Light Sensor that the driver gives me 3 floating point value for red, green and blue luminescence in lux.  In my Read data I convert them to 3 uint16 values.  I am just trying to get the read sensor to show up in the app. Ultimately, I would like send all 3 values.  I thought if I got one working, then the other 2 would be easy.  Now I understand why WICED_BT_MESH_PROPERTY_LEN_PRESENT_AMBIENT_LIGHT_LEVEL  = 3. How do I set it up to send 3 octets when the .data is a uint8?  uint24 doesn't resolve. in the mesh_core_config_element  ---- should I be setting the number of sensors to 3?  How do I define my data as a 3 item array?  Does the rest of the FW take care of it all?

0 Likes

.data has a pointer to where you need to put the data and where mesh stack will copy it from.  If you have a global uint8_t sensor_data[3]. and .data = sensor_data, it should do the trick. Make sure that ID and length are setup correctly as well.

        .property_id = WICED_BT_MESH_PROPERTY_LEN_PRESENT_AMBIENT_LIGHT_LEVEL,

        .prop_value_len = WICED_BT_MESH_PROPERTY_LEN_PRESENT_AMBIENT_LIGHT_LEVEL,

I got it working.  I am seeing the data in the application. If I want to send 3 values,  Red Lux, Green Lux and Blue Lux.  What Model would be best to use? Also,  I am going to develop a project that converts the RGB to HSL and use the HSL Model.

0 Likes

There is no standard way to send Red Lux, Green Lux and Blue Lux.  If you want to develop standard ambient light sensor that can be used in the industry, you will have to use ambient light level as defined in the Mesh Device Properties specification.  If you are just playing with the technology, or you will always have your Light Controllers with your ambient color light sensor, you will need to use Vendor Specific Model.  There is associated sample in the SDK. 

Alternatively if you think RGB sensor is attractive in the industry, we can try to update Mesh Device Property spec to introduce your values.

0 Likes

So this sensor is to measure incident light intensity and the color content.  The application is agricultural growing.  Here is a description of the Adruino eval board that I am using CN0397 is an Arduino compatible shield that is optimized for smart agriculture utilizing wavelength specific photodiodes. Photosynthetic response of plants vary due to the wavelength and intensity of light received. Photodiodes used in this circuit has peak sensitivities over the wavelengths of interest, red and blue region, and over the green region which is mainly rejected by the leaves of the plant. It is more than just playing.  It is a real world application.I am an Applications Engineer from Arrow. I am not creating an end product but a demo for customers who are interested in incorporating light sensing.  This will be used in our upcoming series of BT Mesh Worskhops in Q4  and Q1 next year.

So I think that this should be attractive since agriculture is a growing industry and end users want to know the growing conditions, light intensity and color content are important.

0 Likes

Agriculture is indeed important.  Whatever you say makes perfect sense to me, but I am not the one to judge.  Please have a look at the Mesh Device Properties spec and at the existing properties.  If you know enough about it and you want to add new text, or if you know people who can write new sections for new properties, I will be happy to work with Bluetooth SIG to update the document. The process is relatively simple and you can do it yourself if Arrow is an Associate member.

Without updating the spec, we can only use Vendor Specific model.

0 Likes

I don't have the expertise or know enough about it to add text.  I will look at the Vendor Specific Model to see what it will do.  It sounds similar to a custom profile for BLE which I have done. Do you know what the iOS app or Android will display if it is not in the spec but a Vendor Specific Model? Thank you, Victor for all of you help.  I wouldn't have made it this far without your help.  I am confident that I will be able to put something together that will demonstrate how to add this sensor shield to a BT Mesh application.

0 Likes