Attempting to add another custom characteristic to BLE101 project, need a little help.

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
MaSa_2723681
Level 2
Level 2
5 replies posted Welcome! First question asked

Hello,

I started with the BLE101 (CapSenseLed) example project and that worked fine (using CY8CKIT-042-KIT  aka BLE Pioneer Kit). I wanted to track the time since reset so I put a timer component on the schematic and added an ISR to the TC (Terminal Count) of the timer. The Timer_ISR, which occurs every 5 seconds, toggles the green led and increments a variable "OnTime". And that all works fine.

Then I tried to add a custom characteristic to track the time since reset. I think I did everything right in the BLE component in PSoC Creator 4.1. I used the CySmart1.2 to verify operation and it looks good. (capsenseled Project archive attached).

Then I modified the BLE101 Android Studio project to accomidate the additional "OnTime" data. I did it just like the "capsense" data I think.

However, when click the notify switch for my "OnTime" I get a null pointer exception at the line number 310 in PSoCCapSenseLedService.java. The offending instruction is mOnTimeCccd.setValue(byteVal);

The Android Monitor shows:

Shutting down VM

09-06 13:54:40.786 5263-5263/com.cypress.academy.ble101 E/AndroidRuntime: FATAL EXCEPTION: main

                                                                          Process: com.cypress.academy.ble101, PID: 5263

                                                                          java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.bluetooth.BluetoothGattDescriptor.setValue(byte[])' on a null object reference

                                                                              at com.cypress.academy.ble101.PSoCCapSenseLedService.writeOnTimeNotification(PSoCCapSenseLedService.java:310)

                                                                              at com.cypress.academy.ble101.MainActivity$5.onCheckedChanged(MainActivity.java:186)

                                                                              at android.widget.CompoundButton.setChecked(CompoundButton.java:165)

                                                                              at android.widget.Switch.setChecked(Switch.java:1138)

                                                                              at android.widget.Switch.toggle(Switch.java:1133)

                                                                              at android.widget.CompoundButton.performClick(CompoundButton.java:123)

                                                                              at android.view.View$PerformClick.run(View.java:22570)

                                                                              at android.os.Handler.handleCallback(Handler.java:739)

                                                                              at android.os.Handler.dispatchMessage(Handler.java:95)

                                                                              at android.os.Looper.loop(Looper.java:158)

                                                                              at android.app.ActivityThread.main(ActivityThread.java:7231)

                                                                              at java.lang.reflect.Method.invoke(Native Method)

                                                                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)

                                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

I have no idea why that is a null pointer. Since this is only a slight variation from the example code I was wondering if someone could try out my code and see what I am doing wrong. Any help would be greatly appricated!

Thank you,

Mark

0 Likes
1 Solution

Never mind. Got it working. Evidently all CCCD UUIDs are 00002902-0000-1000-8000-00805f9b34fb despite what you put in the BLE component GUI. I also moved my updateOnTime() routine from main() to the Timer_ISR().

Thanks,

Mark

View solution in original post

0 Likes
6 Replies