I’m connecting two Argons (one as central and one as peripheral). I know the devices are connected because I can see the peripheral device responding. However, I’m having issues using onConnected and onDisconnected (basically the LED doesn’t turn on and the Log statements don’t appear).
I looked through the docs and the forum, and the relevant code is below.
When I tested your peripheral code with nRF Connect the LED behaved as expected (when defining my own const int PIN_LED = D7 - are you missing that in your running code or have you just not copied it over to your post?).
However, the log statement doesn’t, because you are missing a log handler.
Add this to your definitions
If these tips don’t help:
Can you try to advertise your device and then check whether a it works with some other “central” device (e.g. via nRF Connect app).
When that works it may also be related to your central code.
Thanks @ScruffR for your response. I did have the const int PIN_LED and SerialLogHandler declarations but I had forgotten to paste them in.
I connected to the peripheral device with the Bluefruit app, and the LED did turn on and off when the app connects and disconnects. Even though the peripheral LED connect/disconnected worked with Bluefruit, I wondered if a PWM output I was using on pin D7 could interfere. When I moved that PWM output to another pin, the peripheral device LED connect/disconnect now works with both Bluefruit and the Argon central device! Thank you for your suggestion!
–
It does lead me to a related question. On the central device, I’d like to have the same connect/disconnect functionality with the on board LED–meaning when the central device connects to a peripheral device, the central device LED should turn on also.
When I use the put the above code in my central device, the on board LED doesn’t turn on when connected. However, the following code does work though
Can you elaborate on that or provide some code we could test that with?
When I set PIN_LED = D7 and use analogWrite() rather than digitalWrite() in the callback it works just the same.
So I cannot see a direct correlation between PWM on D7 and the callback not firing.
Given that, on a central device I'd put the digitalWrite(PIN_LED, HIGH) after the BLE.connect() call and only if (!peer.connected()) digitalWrite(PIN_LED, LOW) into loop(). Since a connection won't automagically establish without the central initiating it, I'd see little use in forcing the LED on over and over while the connection persists.