diff --git a/nrf5/modules/ubluepy/ubluepy_service.c b/nrf5/modules/ubluepy/ubluepy_service.c index baea19f6bc..d7e6095f07 100644 --- a/nrf5/modules/ubluepy/ubluepy_service.c +++ b/nrf5/modules/ubluepy/ubluepy_service.c @@ -78,6 +78,9 @@ STATIC mp_obj_t ubluepy_service_make_new(const mp_obj_type_t *type, size_t n_arg "Invalid UUID parameter")); } + // clear reference to peripheral + s->p_periph = NULL; + return MP_OBJ_FROM_PTR(s); } @@ -92,6 +95,10 @@ STATIC mp_obj_t service_add_characteristic(mp_obj_t self_in, mp_obj_t characteri bool retval = ble_drv_characteristic_add(p_char); + if (retval) { + p_char->p_service = self; + } + return mp_obj_new_bool(retval); } STATIC MP_DEFINE_CONST_FUN_OBJ_2(ubluepy_service_add_char_obj, service_add_characteristic);