I had manged to deploy and configure mesh networks on Nordic Thingy devices based on these 2 examples separately.
1. Generic OnOff models
https://github.com/NordicPlayground/thingy52-mesh-provisioning-demo
(based on nRF Mesh SDK 3.2.0 and nRF5 SDK v 15.3)
2. Simple Thingy models
https://github.com/NordicPlayground/Nordic-Thingy52-mesh-demo
(based on nRF Mesh SDK 1.0.1 and nRF5 SDK v15.3
I would like to include the Simple Thingy models with the OnOff Generic models.
I managed to add the Simple Thingy models into the first example to perform the following:
1. Use simple_thingy_client to set on/off LED on simple_thingy_server.
2. Use simple_thingy_client to set sensor configuration to report sensor readings every 1s. The humidity and temperature readings are retrieved and printed in debug window of simple_thingy_server.
However, I noted that the led status and sensor status messages are not received at the simple_thingy_client.
(The status messages are received for app_generic_onoff_client_status_cb.)
I wonder if there is anything missing for the implementation of the Simple Thingy models or my code:
https://github.com/NordicPlayground/Nordic-Thingy52-mesh-demo/tree/master/simple_thingy
Code snippets for my implementation of simple_thingy_server:
simple_thingy_server_t m_server2;
static ble_uis_led_t led_get_cb()
{
return m_server2.present_led_status;
__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "get led status\r\n");
}
static ble_uis_led_t led_set_cb(const simple_thingy_server_t * server, ble_uis_led_t led_config)
{
__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "set led status\r\n");
uint32_t status = publish_led_state(&m_server2, led_config); //ADDED
__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "publish_led_state: %d\r\n", status);
thingy_led_set(&m_server2, led_config);
return led_config;
}
static void sensor_set_cb(const simple_thingy_server_t * server, sensor_config_t sensor_cfg)
{
__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "set sensor status, cfg = %x\r\n", sensor_cfg.report_timer);
switch(sensor_cfg.report_timer)
{
case SENSOR_REPORT_NONE:
app_timer_stop(m_sensor_timer_id);
break;
case SENSOR_REPORT_EVERY_1S:
app_timer_stop(m_sensor_timer_id);
app_timer_start(m_sensor_timer_id, APP_TIMER_TICKS(1000), NULL);
break;
case SENSOR_REPORT_EVERY_5S:
app_timer_stop(m_sensor_timer_id);
app_timer_start(m_sensor_timer_id, APP_TIMER_TICKS(5000), NULL);
break;
case SENSOR_REPORT_EVERY_10S:
app_timer_stop(m_sensor_timer_id);
app_timer_start(m_sensor_timer_id, APP_TIMER_TICKS(10000), NULL);
break;
case SENSOR_REPORT_MANUAL:
app_timer_stop(m_sensor_timer_id);
sensor_timer_handler();
break;
default:
break;
}
}
Inside app_model_init():
m_server2.led_get_cb = led_get_cb; m_server2.led_set_cb = led_set_cb; m_server2.sensor_set_cb = sensor_set_cb; ERROR_CHECK(simple_thingy_server_init(&m_server2, APP_ONOFF_ELEMENT_INDEX)); ERROR_CHECK(access_model_subscription_list_alloc(m_server2.model_handle)); __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Server2 Model Handle: %d\n", m_server2.model_handle);
static void sensor_timer_handler()
{
//__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "sensor log start\r\n");
drv_humidity_sample();
float humidity = drv_humidity_get();
float temperature = drv_humidity_temp_get();
sensor_reading_t sensor_data = {
.humidity = humidity,
.temperature = temperature
};
__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Humidity:" NRF_LOG_FLOAT_MARKER "\t Temperature:" NRF_LOG_FLOAT_MARKER "\r\n", NRF_LOG_FLOAT(humidity), NRF_LOG_FLOAT(temperature));
simple_thingy_sensor_report(&m_server2, sensor_data);
}
Code snippets for my implementation of simple_thingy_client:
simple_thingy_client_t m_client2;
static void led_status_cb(const simple_thingy_client_t * p_self, ble_uis_led_t status, uint16_t src)
{
__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Led status received!");
}
static void sensor_status_cb(const simple_thingy_client_t * p_self, sensor_reading_t status, uint16_t src)
{
__LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Sensor status received!");
}
Inside models_init_cb():
m_client2.led_status_cb = led_status_cb; m_client2.sensor_status_cb = sensor_status_cb; ERROR_CHECK(simple_thingy_client_init(&m_client2, APP_ONOFF_ELEMENT_INDEX+1)); ERROR_CHECK(access_model_subscription_list_alloc(m_client2.model_handle)); __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Client2 Model Handle: %d\n", m_client2.model_handle);
Inside button_event_handler():
sensor_config_t sensor_config; sensor_config.report_timer = SENSOR_REPORT_EVERY_1S; ERROR_CHECK(simple_thingy_client_sensor_set(&m_client2, sensor_config));
Any insights would be greatly appreciated! Thank you!