1 2 Previous Next 26 Replies Latest reply on Sep 3, 2019 2:05 PM by MiRo_263836

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

    MiRo_263836

      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

        • 1. Re: BT Mesh on Mesh Kit - Add a 2nd Sensor to the Temp Sensor Example
          MiRo_263836

          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?

          • 2. Re: BT Mesh on Mesh Kit - Add a 2nd Sensor to the Temp Sensor Example
            VictorZ_46

            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.

            • 3. Re: BT Mesh on Mesh Kit - Add a 2nd Sensor to the Temp Sensor Example
              MiRo_263836

              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.

              • 4. Re: BT Mesh on Mesh Kit - Add a 2nd Sensor to the Temp Sensor Example
                VictorZ_46

                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.

                2 of 2 people found this helpful
                • 5. Re: BT Mesh on Mesh Kit - Add a 2nd Sensor to the Temp Sensor Example
                  MiRo_263836

                  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?

                  • 6. Re: BT Mesh on Mesh Kit - Add a 2nd Sensor to the Temp Sensor Example
                    VictorZ_46

                    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. 

                    2 of 2 people found this helpful
                    • 7. Re: BT Mesh on Mesh Kit - Add a 2nd Sensor to the Temp Sensor Example
                      MiRo_263836

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

                      • 8. Re: BT Mesh on Mesh Kit - Add a 2nd Sensor to the Temp Sensor Example
                        MiRo_263836

                        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.

                        • 9. Re: BT Mesh on Mesh Kit - Add a 2nd Sensor to the Temp Sensor Example
                          VictorZ_46

                          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

                          • 10. Re: BT Mesh on Mesh Kit - Add a 2nd Sensor to the Temp Sensor Example
                            MiRo_263836

                            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,     }, };

                            • 11. Re: BT Mesh on Mesh Kit - Add a 2nd Sensor to the Temp Sensor Example
                              MiRo_263836

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

                              • 12. Re: BT Mesh on Mesh Kit - Add a 2nd Sensor to the Temp Sensor Example
                                MiRo_263836

                                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.

                                • 13. Re: BT Mesh on Mesh Kit - Add a 2nd Sensor to the Temp Sensor Example
                                  MiRo_263836

                                  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?

                                  • 14. Re: BT Mesh on Mesh Kit - Add a 2nd Sensor to the Temp Sensor Example
                                    MiRo_263836

                                    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.

                                    1 of 1 people found this helpful
                                    1 2 Previous Next