![](/media/cache/profiles/profile2.jpg.50x50_q85.jpg)
This software setup a central node of a star topology network
Dependencies: MQTT target_st_bluenrg
Fork of ble-star-mbed by
Diff: source/BleSlaveService.cpp
- Revision:
- 4:4af40af2530e
- Parent:
- 3:3f35e80ed848
diff -r 3f35e80ed848 -r 4af40af2530e source/BleSlaveService.cpp --- a/source/BleSlaveService.cpp Tue Mar 13 16:31:07 2018 +0000 +++ b/source/BleSlaveService.cpp Sat Mar 31 15:10:54 2018 +0000 @@ -84,9 +84,8 @@ //Restart loop ops - perDevs.status = CONN_INIT; - perDevs.discovery_enabled = true; - //printf("\rstatus = CONN_INIT (%d)\n", perDevs.status);//DEBUG + //perDevs.status = CONN_INIT; + //perDevs.discovery_enabled = true; } /*----------------------------------------------------------------------------*/ @@ -143,7 +142,7 @@ /* The gatt write function above is w/out response, so we just wait for a short time before going on */ writeCharacValueWithoutResp(conn_handle, attr_handle, value_len, attr_value); - HAL_Delay(2000);//N ms + HAL_Delay(1000);//N ms } /*----------------------------------------------------------------------------*/ @@ -155,8 +154,8 @@ //printf("\r\nnotifyMaster\n");//DEBUG ble_error_t notifyError; - - notifyError = BLE::Instance().gattServer().write(attribute_handle+1, attribute_value, data_length, false); + if (slaveDev.is_connected !=0) + notifyError = BLE::Instance().gattServer().write(attribute_handle+1, attribute_value, data_length, false); if (notifyError != BLE_ERROR_NONE){ printf("\r\n(notifyMaster) Error (%d) while updating characteristic\n", notifyError);//BLE_STACK_BUSY @@ -277,16 +276,16 @@ switch (enabled) { case 0x01: perDevs.discovery_enabled = true; - //printf("\r\nScanning enabled (%d)\n", enabled); +// printf("\r\nScanning enabled (%d)\n", enabled); break; case 0x02: perDevs.discovery_enabled = false; - //printf("\r\nScanning disabled (%d)\n", enabled); +// printf("\r\nScanning disabled (%d)\n", enabled); break; default: - //printf("\r\nScanning set to unrecognized value (%d)\n", enabled); +// printf("\r\nScanning set to unrecognized value (%d)\n", enabled); break; } @@ -297,8 +296,8 @@ /* Notify master for scanning */ /* Check the scan enable/disable */ -// notifyMaster(slaveDev.star_config_value_len, slaveDev.star_config_value, -// slaveDev.star_config_char_handle); + notifyMaster(slaveDev.star_config_value_len, slaveDev.star_config_value, + slaveDev.star_config_char_handle); } /*----------------------------------------------------------------------------*/ @@ -405,8 +404,7 @@ /* This function is called when a local attribute gets modified */ void AttributeModified_CB(const GattWriteCallbackParams* param){ -// printf("\r\nAttributeModified_CB (%d)\n", perDevs.status);//DEBUG - + //printf("\r\nAttributeModified_CB\n");//DEBUG /* Assign prototype vars */ uint16_t handle = param->handle; @@ -640,7 +638,6 @@ /* Then, call the Change_Notification_Status from the readCallback with these params */ }else if (readCompleted == 1) { - //notificationPending = 0; Change_Notification_Status(att_data, attr_value, conn_handle, i, FEATURE_MASK_SENSORFUSION, SENDING_INTERVAL_100MS_MULTIPLE); } @@ -766,8 +763,7 @@ attr_value[0] = 0x01; setNotificationProperty(perDevs.connection_handle[j], j, FEATURE_MASK_WAKEUP_EVENTS, WAKEUP_NOTIFICATION_CMD, 1); - -// if (discoveryCompleted == 1){ + writeDescriptorCompleted=0; ble_error_t wupErrOn = writeCharacDescriptorWithError(perDevs.connection_handle[j], attr_handle, value_len, attr_value); @@ -775,14 +771,12 @@ perDevs.wup_event_enabled = 1; perDevs.wup_event[j] = 1; printf("\r\nWUP notification on node [%d] ON\n", j); - + } else { printf("\r\nWrite WUP char descriptor failed! (%d)\n", wupErrOn); writeDescriptorCompleted=1; }//if-else - -// }//if-else-discovery-completed }//if }//for @@ -799,7 +793,6 @@ attr_value[0] = 0x00; -// if (discoveryCompleted == 1){ writeDescriptorCompleted=0; ble_error_t wupErrOff = writeCharacDescriptorWithError(perDevs.connection_handle[j], attr_handle, value_len, attr_value); @@ -813,25 +806,25 @@ writeDescriptorCompleted=1; } - -// }//if-discovery-completed }//if }//for + if (perDevs.wup_event_enabled == 0) + //printf("\r\nAll WUP notifications turned OFF\n");//DEBUG perDevs.status = NOTIFICATIONS_DATA_READ; }//if-else-wup + + attr_value[0] = att_data[3]; perDevs.readDeviceIdx = i; - + + /* No notification is pending anymore */ notificationPending = 0; //Return to connectionProcess - perDevs.status = CONN_INIT; - + //perDevs.status = CONN_INIT; - - } /*----------------------------------------------------------------------------*/