This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Initializing Cycling Power Service 0x1818

Hello!

I am trying to implement the Cycling Power from https://devzone.nordicsemi.com/f/nordic-q-a/9169/cycling-power-service-0x1818

Please, could you show how we need to configure the service?
This way is not working:
memset(&cp_init, 0, sizeof(cp_init));
            
            cp_init.ctrlpt_evt_handler    = NULL;
            cp_init.feature                     = BLE_CPS_FEATURE_WHEEL_REV_BIT | BLE_CPS_FEATURE_CRANK_REV_BIT | BLE_CPS_FEATURE_MULTIPLE_SENSORS_BIT;
            
            // Here the sec level for the Cycling Speed and Cadence Service can be changed/increased.
            BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cp_init.cp_meas_attr_md.cccd_write_perm);   // for the measurement characteristic, only the CCCD write permission can be set by the application, others are mandated by service specification
            BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cp_init.cp_feature_attr_md.read_perm);      // for the feature characteristic, only the read permission can be set by the application, others are mandated by service specification
            
            
            //cp_init.ctrlpt_evt_handler            = sc_ctrlpt_event_handler;
            
            
            err_code = ble_cps_init(&m_cp, &cp_init);
            APP_ERROR_CHECK(err_code);

Parents
  • Hello,

    I am trying to initialize the service Power Cycling from the files of this link https://devzone.nordicsemi.com/f/nordic-q-a/9169/cycling-power-service-0x1818

    I get the CSC example from Nordic and I tried to initialize the service of Power Cycling from the files that I downloaded.
    That's all

  • the code does not compile with SDK15 and SDv6.0.0. Can you tell me which versions are you using so that i can give it a try

  • Hello,

     

    You can get the example of Nordic --> ble_app_cscs with s132_nrf52_2.0.0-7.alpha_softdevice

     

  • in services init you call this

        ble_cps_init_t        cps_init;
        
        // Initialize Cycling Power Service module
        memset(&cps_init, 0, sizeof(cps_init));
    
        cps_init.evt_handler = NULL;
        cps_init.feature     = BLE_CPS_FEATURE_WHEEL_REV_BIT | BLE_CSCS_FEATURE_CRANK_REV_BIT |
                                BLE_CSCS_FEATURE_MULTIPLE_SENSORS_BIT;
    
        // Here the sec level for the Cycling Speed and Cadence Service can be changed/increased.
        BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cps_init.cp_meas_attr_md.cccd_write_perm);   // for the measurement characteristic, only the CCCD write permission can be set by the application, others are mandated by service specification
        BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cps_init.cp_feature_attr_md.read_perm);      // for the feature characteristic, only the read permission can be set by the application, others are mandated by service specification
        BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cps_init.cp_ctrlpt_attr_md.write_perm);      // for the SC control point characteristic, only the write permission and CCCD write can be set by the application, others are mandated by service specification
        BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cps_init.cp_ctrlpt_attr_md.cccd_write_perm); // for the SC control point characteristic, only the write permission and CCCD write can be set by the application, others are mandated by service specification
        
        cps_init.ctrplt_supported_functions    = BLE_SRV_SC_CTRLPT_CUM_VAL_OP_SUPPORTED
                                                  |BLE_SRV_SC_CTRLPT_SENSOR_LOCATIONS_OP_SUPPORTED
                                                  |BLE_SRV_SC_CTRLPT_START_CALIB_OP_SUPPORTED;
        cps_init.ctrlpt_evt_handler            = sc_ctrlpt_event_handler;
        cps_init.list_supported_locations      = supported_locations;
        cps_init.size_list_supported_locations = sizeof(supported_locations) / sizeof(ble_sensor_location_t);            
        
        sensor_location           = BLE_SENSOR_LOCATION_FRONT_WHEEL;                    // initializes the sensor location to add the sensor location characteristic.
        cps_init.sensor_location = &sensor_location;
        BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cps_init.cp_sensor_loc_attr_md.read_perm);    // for the sensor location characteristic, only the read permission can be set by the application, others are mendated by service specification
    
        err_code = ble_cps_init(&m_cps, &cps_init);
        APP_ERROR_CHECK(err_code);

    in ble_srv_common.h file you add below

    #define BLE_UUID_CYCLING_POWER                                   0x1818     /**< Cycling Power UUID. */
    
    #define BLE_UUID_CYCLING_POWER_MEASUREMENT_CHAR                  0x2A63     /**< Cycling Power Feature characteristic UUID. */
    #define BLE_UUID_CYCLING_POWER_FEATURE_CHAR                      0x2A65     /**< Cycling Power Measurement characteristic UUID. */
    

    I guess that should be enough.

  • Hello Aryan,

    Thanks in advance.

    But it doesn't work. I can connect with device as Speed & Cadence but I can not see the Power Cycling.

  • I just tried to run this code and the CP service does show up along with CSC

Reply Children
  • Hi Juan,

    I did not touch them. I only modified main.c and added few defines in ble_srv_common.h.

    I am home already, so I can attach you my whole project tomorrow if you think that will help you. I tested this on SDK 11.

  • Hello,

    Now I am trying to change the value of power:

    cps_measurement.power_measurement = 1000;        
                err_code = ble_cps_measurement_send(&m_cps, &cps_measurement);
                err_code_CPS = err_code;
                    if ((err_code != NRF_SUCCESS) &&
                            (err_code != NRF_ERROR_INVALID_STATE) &&
                            (err_code != BLE_ERROR_NO_TX_PACKETS) &&
                            (err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)
                            )
                    {
                            APP_ERROR_HANDLER(err_code);
                    }

    But an error jumps:  NRF_ERROR_INVALID_STATE

    I see that it is because if (p_cps->conn_handle != BLE_CONN_HANDLE_INVALID){ in ble_cps_measurement_send.

    I see that you initialize cps_init.evt_handler = NULL; in the init_services.

    Do you undestand why it happens?

Related