diff --git a/cores/arduino/wiring_digital.c b/cores/arduino/wiring_digital.c index 09d4fd7..2543f9d 100755 --- a/cores/arduino/wiring_digital.c +++ b/cores/arduino/wiring_digital.c @@ -232,7 +232,7 @@ void pinMode( uint32_t ulPin, uint32_t ulMode ) if ( (ulPin == 34) && (ulMode == STM32_IT) ) { - delay(15); + nrf_delay_ms(15); TwoWire_begin(); TwoWire_beginTransmission(0x48); TwoWire_write(GPIO_USER1_IT); @@ -278,7 +278,7 @@ void digitalWrite( uint32_t ulPin, uint32_t ulVal ) switch ( ulPin ) { case 38: - delay(15); + nrf_delay_ms(15); if(ulVal == HIGH) { TwoWire_begin(); @@ -296,7 +296,7 @@ void digitalWrite( uint32_t ulPin, uint32_t ulVal ) break ; case 39: - delay(15); + nrf_delay_ms(15); if(ulVal == HIGH) { TwoWire_begin(); @@ -314,7 +314,7 @@ void digitalWrite( uint32_t ulPin, uint32_t ulVal ) break ; case 40: - delay(15); + nrf_delay_ms(15); if(ulVal == HIGH) { TwoWire_begin(); @@ -332,7 +332,7 @@ void digitalWrite( uint32_t ulPin, uint32_t ulVal ) break ; case 41: - delay(15); + nrf_delay_ms(15); if(ulVal == HIGH) { TwoWire_begin(); @@ -350,7 +350,7 @@ void digitalWrite( uint32_t ulPin, uint32_t ulVal ) break ; case 42: - delay(15); + nrf_delay_ms(15); if(ulVal == HIGH) { TwoWire_begin(); @@ -396,12 +396,12 @@ int digitalRead( uint32_t ulPin ) switch ( ulPin ) { case 44: - delay(15); + nrf_delay_ms(15); TwoWire_begin(); TwoWire_beginTransmission(0x48); TwoWire_write(USER2_BUTTON_IN); TwoWire_endTransmission(); - delay(15); + nrf_delay_ms(15); TwoWire_requestFrom(0x48, 2, true); char c = TwoWire_read(); if (c == 0xC3) diff --git a/libraries/BLE/BLECentralRole.cpp b/libraries/BLE/BLECentralRole.cpp index 28b5463..80eb230 100644 --- a/libraries/BLE/BLECentralRole.cpp +++ b/libraries/BLE/BLECentralRole.cpp @@ -35,6 +35,8 @@ BLECentralRole::BLECentralRole() : _messageEventHandler(NULL), + _status(DISCONNECT), + _localAttributes(NULL), _numLocalAttributes(0), _remoteAttributes(NULL), @@ -224,6 +226,10 @@ void BLECentralRole::allowMultilink(uint8_t linksNo){ _allowedPeripherals = linksNo; } +BLEStatus BLECentralRole::status(){ + return _status; +} + void BLECentralRole::setBondStore(BLEBondStore& bondStore){ this->_bondStore = bondStore; } @@ -604,7 +610,7 @@ void BLECentralRole::begin(){ } this->startScan(); - + this->_status = SCANNING; } void BLECentralRole::poll(ble_evt_t *bleEvt){ @@ -627,6 +633,7 @@ void BLECentralRole::poll(ble_evt_t *bleEvt){ } break; case BLE_GAP_EVT_CONNECTED: + _status = CONNECT; uint8_t index; //save the handler in the first free location for(index = 0; index < _allowedPeripherals; index++) @@ -685,6 +692,7 @@ void BLECentralRole::poll(ble_evt_t *bleEvt){ break; case BLE_GAP_EVT_DISCONNECTED: uint8_t currentPeripheral; + this->_status = DISCONNECT; for(currentPeripheral = 0; currentPeripheral < _allowedPeripherals; currentPeripheral++) if(this->_connectionHandle[currentPeripheral] == bleEvt->evt.gap_evt.conn_handle) break; @@ -712,6 +720,7 @@ void BLECentralRole::poll(ble_evt_t *bleEvt){ this->_remoteRequestInProgress = false; this->startScan(); + this->_status = SCANNING; break; case BLE_GAP_EVT_CONN_PARAM_UPDATE: diff --git a/libraries/BLE/BLECentralRole.h b/libraries/BLE/BLECentralRole.h index e3ac90a..e3c0162 100644 --- a/libraries/BLE/BLECentralRole.h +++ b/libraries/BLE/BLECentralRole.h @@ -78,6 +78,8 @@ class BLECentralRole : public BLECharacteristicValueChangeListener, void disconnect(); void allowMultilink(uint8_t linksNo); + + BLEStatus status(); void setBondStore(BLEBondStore& bondStore); void enableBond(BLEBondingType type = JUST_WORKS); @@ -138,6 +140,8 @@ class BLECentralRole : public BLECharacteristicValueChangeListener, uint16_t valueHandle; }; + BLEStatus _status; + short _scanInterval = 0x0004; short _scanWindow = 0x0004; short _scanTimeout = 0; diff --git a/libraries/BLE/BLEDevice.cpp b/libraries/BLE/BLEDevice.cpp index 946aa9e..7d17419 100644 --- a/libraries/BLE/BLEDevice.cpp +++ b/libraries/BLE/BLEDevice.cpp @@ -21,6 +21,7 @@ BLEDevice::BLEDevice() : _lesc(0), _io_caps(BLE_GAP_IO_CAPS_NONE), _passkey({0,0,0,0,0,0}), + _status(1), _userConfirm(false) { } diff --git a/libraries/BLE/BLEDevice.h b/libraries/BLE/BLEDevice.h index ad33217..af64dcf 100644 --- a/libraries/BLE/BLEDevice.h +++ b/libraries/BLE/BLEDevice.h @@ -119,6 +119,8 @@ class BLEDevice bool _userConfirm; BLEBondStore* _bondStore; BLEDeviceEventListener* _eventListener; + uint8_t _status; + }; #endif diff --git a/libraries/BLE/BLEPeripheral.cpp b/libraries/BLE/BLEPeripheral.cpp index 8103a73..950292f 100644 --- a/libraries/BLE/BLEPeripheral.cpp +++ b/libraries/BLE/BLEPeripheral.cpp @@ -282,6 +282,10 @@ bool BLEPeripheral::connected() { return this->_central; } +BLEStatus BLEPeripheral::status(){ + return (BLEStatus)this->_device->_status; +} + void BLEPeripheral::printBleMessage(int eventCode, int messageCode){ if(eventCode > sizeof(this->_evt_code_to_string)) return; diff --git a/libraries/BLE/BLEPeripheral.h b/libraries/BLE/BLEPeripheral.h index 7a0c7c7..492a5a0 100644 --- a/libraries/BLE/BLEPeripheral.h +++ b/libraries/BLE/BLEPeripheral.h @@ -62,6 +62,13 @@ enum BLEBondingType { LESC_CONFIRM_PASSKEY = 6 }; +enum BLEStatus { + CONNECT = 0, + DISCONNECT, + ADVERTISING, + SCANNING +}; + typedef void (*BLEPeripheralEventHandler)(BLECentral& central); typedef void (*BLEMessageEventHandler)(int eventNo, int messageCode); @@ -108,6 +115,8 @@ class BLEPeripheral : public BLEDeviceEventListener, BLECentral central(); bool connected(); + + BLEStatus status(); void printBleMessage(int eventCode, int messageCode); diff --git a/libraries/BLE/examples/Central/Bonding/enterPasskeyCentral/enterPasskeyCentral.ino b/libraries/BLE/examples/Central/Bonding/enterPasskeyCentral/enterPasskeyCentral.ino index f12ca44..0046496 100644 --- a/libraries/BLE/examples/Central/Bonding/enterPasskeyCentral/enterPasskeyCentral.ino +++ b/libraries/BLE/examples/Central/Bonding/enterPasskeyCentral/enterPasskeyCentral.ino @@ -8,6 +8,9 @@ Use the complementary example showPasskey.ino in File->Examples->BLE->Peripheral->Bonding to test this feature. + In this example BLE_LED shows the status of the board. It will blink every 200 ms when the board is scanning. + It will be on when the board is connected to a peripheral. It will be off when the board is disconnected. + This example code is in the public domain. */ @@ -27,6 +30,9 @@ BLERemoteCharacteristic dummyRemoteCharacteristic = BLERemote void setup() { Serial.begin(9600); + //initialize BLE led + pinMode(BLE_LED, OUTPUT); + // add service and characteristic bleCentral.addRemoteAttribute(dummyRemoteService); bleCentral.addRemoteAttribute(dummyRemoteCharacteristic); @@ -51,7 +57,18 @@ void setup() { } void loop() { - // Do nothing + // Handle BLE led + blinkOnScan(); +} + +void blinkOnScan(){ + // retrieve the central status in order to blink only when scanning + if(bleCentral.status() == SCANNING){ + digitalWrite(BLE_LED, LOW); + delay(200); + digitalWrite(BLE_LED, HIGH); + delay(200); + } } void receiveAdvPck(BLEPeripheralPeer& peer){ @@ -73,12 +90,16 @@ void bleCentralConnectHandler(BLEPeripheralPeer& peer) { // peer connected event handler Serial.print("Connected event, peripheral: "); Serial.println(peer.address()); + // turn BLE_LED on + digitalWrite(BLE_LED, HIGH); } void bleCentralDisconnectHandler(BLEPeripheralPeer& peer) { // peer disconnected event handler Serial.print("Disconnected event, peripheral: "); Serial.println(peer.address()); + // turn BLE_LED off + digitalWrite(BLE_LED, LOW); } void writePasskey(BLEPeripheralPeer& peer) { diff --git a/libraries/BLE/examples/Central/Bonding/numericComparisonCentral/numericComparisonCentral.ino b/libraries/BLE/examples/Central/Bonding/numericComparisonCentral/numericComparisonCentral.ino index f603123..7dd8927 100644 --- a/libraries/BLE/examples/Central/Bonding/numericComparisonCentral/numericComparisonCentral.ino +++ b/libraries/BLE/examples/Central/Bonding/numericComparisonCentral/numericComparisonCentral.ino @@ -10,7 +10,10 @@ to bond them. Use the complementary example numericComparison.ino in File->Examples->BLE->Peripheral->Bonding to test this feature. - + + In this example BLE_LED shows the status of the board. It will blink every 200 ms when the board is scanning. + It will be on when the board is connected to a peripheral. It will be off when the board is disconnected. + This example code is in the public domain. */ @@ -30,6 +33,9 @@ BLERemoteCharacteristic dummyRemoteCharacteristic = BLERemote void setup() { Serial.begin(9600); + + //initialize BLE led + pinMode(BLE_LED, OUTPUT); // initialize button pinMode(CONFIRM_BUTTON, INPUT); @@ -58,7 +64,18 @@ void setup() { } void loop() { - // Do nothing + // Handle BLE led + blinkOnScan(); +} + +void blinkOnScan(){ + // retrieve the central status in order to blink only when scanning + if(bleCentral.status() == SCANNING){ + digitalWrite(BLE_LED, LOW); + delay(200); + digitalWrite(BLE_LED, HIGH); + delay(200); + } } void receiveAdvPck(BLEPeripheralPeer& peer){ @@ -80,12 +97,16 @@ void bleCentralConnectHandler(BLEPeripheralPeer& peer) { // peer connected event handler Serial.print("Connected event, peripheral: "); Serial.println(peer.address()); + // turn BLE_LED on + digitalWrite(BLE_LED, HIGH); } void bleCentralDisconnectHandler(BLEPeripheralPeer& peer) { // peer disconnected event handler Serial.print("Disconnected event, peripheral: "); Serial.println(peer.address()); + // turn BLE_LED off + digitalWrite(BLE_LED, LOW); } void showPasskey(BLEPeripheralPeer& peer) { diff --git a/libraries/BLE/examples/Central/Bonding/showPasskeyCentral/showPasskeyCentral.ino b/libraries/BLE/examples/Central/Bonding/showPasskeyCentral/showPasskeyCentral.ino index d230445..5de20ab 100644 --- a/libraries/BLE/examples/Central/Bonding/showPasskeyCentral/showPasskeyCentral.ino +++ b/libraries/BLE/examples/Central/Bonding/showPasskeyCentral/showPasskeyCentral.ino @@ -7,6 +7,9 @@ Use the complementary example enterPasskeyBond.ino in File->Examples->BLE->Peripheral->Bonding to test this feature. + + In this example BLE_LED shows the status of the board. It will blink every 200 ms when the board is scanning. + It will be on when the board is connected to a peripheral. It will be off when the board is disconnected. This example code is in the public domain. */ @@ -27,6 +30,9 @@ BLERemoteCharacteristic dummyRemoteCharacteristic = BLERemote void setup() { Serial.begin(9600); + //initialize BLE led + pinMode(BLE_LED, OUTPUT); + // add service and characteristic bleCentral.addRemoteAttribute(dummyRemoteService); bleCentral.addRemoteAttribute(dummyRemoteCharacteristic); @@ -51,7 +57,18 @@ void setup() { } void loop() { - // Do nothing + // Handle BLE led + blinkOnScan(); +} + +void blinkOnScan(){ + // retrieve the central status in order to blink only when scanning + if(bleCentral.status() == SCANNING){ + digitalWrite(BLE_LED, LOW); + delay(200); + digitalWrite(BLE_LED, HIGH); + delay(200); + } } void receiveAdvPck(BLEPeripheralPeer& peer){ @@ -73,12 +90,16 @@ void bleCentralConnectHandler(BLEPeripheralPeer& peer) { // peer connected event handler Serial.print("Connected event, peripheral: "); Serial.println(peer.address()); + // turn BLE_LED on + digitalWrite(BLE_LED, HIGH); } void bleCentralDisconnectHandler(BLEPeripheralPeer& peer) { // peer disconnected event handler Serial.print("Disconnected event, peripheral: "); Serial.println(peer.address()); + // turn BLE_LED off + digitalWrite(BLE_LED, LOW); } void showPasskey(BLEPeripheralPeer& peer) { diff --git a/libraries/BLE/examples/Central/CTSServer/CTSServer.ino b/libraries/BLE/examples/Central/CTSServer/CTSServer.ino index dfee7be..707e49b 100644 --- a/libraries/BLE/examples/Central/CTSServer/CTSServer.ino +++ b/libraries/BLE/examples/Central/CTSServer/CTSServer.ino @@ -19,6 +19,9 @@ about CTS service please refer to the Bluetooth specifications: https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.service.current_time.xml + In this example BLE_LED shows the status of the board. It will blink every 200 ms when the board is scanning. + It will be on when the board is connected to a peripheral. It will be off when the board is disconnected. + This example code is in the public domain. */ @@ -41,8 +44,10 @@ RTCInt rtc; //create an RTCInt type object void setup() { Serial.begin(9600); - delay(2000); - Serial.println("start"); + + //initialize BLE led + pinMode(BLE_LED, OUTPUT); + rtc.begin(TIME_H24); //init RTC in 24 hour mode //time settings @@ -96,11 +101,17 @@ void loop() { // update characteristic value ctsCharacteristic.setValue((unsigned char *)time, 9); - - } - + // update the value every second delay(1000); + + } + else{ // if we are not connected we are scanning hence blink BLE led + digitalWrite(BLE_LED, LOW); + delay(200); + digitalWrite(BLE_LED, HIGH); + delay(200); + } } void receiveAdvPck(BLEPeripheralPeer& peer){ @@ -122,10 +133,14 @@ void bleCentralConnectHandler(BLEPeripheralPeer& peer) { // peer connected event handler Serial.print("Connected event, peripheral: "); Serial.println(peer.address()); + // turn BLE_LED on + digitalWrite(BLE_LED, HIGH); } void bleCentralDisconnectHandler(BLEPeripheralPeer& peer) { // peer disconnected event handler Serial.print("Disconnected event, peripheral: "); Serial.println(peer.address()); + // turn BLE_LED off + digitalWrite(BLE_LED, LOW); } \ No newline at end of file diff --git a/libraries/BLE/examples/Central/led_switch_client/led_switch_client.ino b/libraries/BLE/examples/Central/led_switch_client/led_switch_client.ino index 552318c..1a04bb6 100644 --- a/libraries/BLE/examples/Central/led_switch_client/led_switch_client.ino +++ b/libraries/BLE/examples/Central/led_switch_client/led_switch_client.ino @@ -15,6 +15,9 @@ This means that a pressure of USER1 button on one board will cause the led's state change on the other board and vice versa. + + In this example BLE_LED shows the status of the board. It will blink every 200 ms when the board is scanning. + It will be on when the board is connected to a peripheral. It will be off when the board is disconnected. This example code is in the public domain. @@ -71,7 +74,10 @@ void setup() { void loop() { if(bleCentral.connected()){ - + + //turn on BLE led + digitalWrite(BLE_LED, HIGH); + bool buttonValue = digitalRead(BUTTON_PIN); bool buttonChanged = (buttonState != buttonValue); @@ -85,6 +91,12 @@ void loop() { bleCentral.writeRemoteCharacteristic(remoteSwitchCharacteristic, &message, sizeof(message)); } } + else{ // if we are not connected we are scanning hence blink BLE led + digitalWrite(BLE_LED, LOW); + delay(200); + digitalWrite(BLE_LED, HIGH); + delay(200); + } } void receiveAdvPck(BLEPeripheralPeer& peer){ diff --git a/libraries/BLE/examples/Central/multilink/multilink.ino b/libraries/BLE/examples/Central/multilink/multilink.ino index cf84c01..bb41085 100644 --- a/libraries/BLE/examples/Central/multilink/multilink.ino +++ b/libraries/BLE/examples/Central/multilink/multilink.ino @@ -37,6 +37,10 @@ bool buttonState; void setup() { Serial.begin(9600); + + //initialize BLE led + pinMode(BLE_LED, OUTPUT); + pinMode(LED_PIN, OUTPUT); pinMode(BUTTON_PIN, INPUT); @@ -73,6 +77,11 @@ void setup() { void loop() { if(bleCentral.connected()){ + // We are connected to at least one peripheral. turn BLE led on. + // Please note that until the maximum number of allowed peripheral is reached + // the board will be scan at the same time. + digitalWrite(BLE_LED, HIGH); + bool buttonValue = digitalRead(BUTTON_PIN); bool buttonChanged = (buttonState != buttonValue); @@ -86,6 +95,12 @@ void loop() { bleCentral.writeRemoteCharacteristic(remoteSwitchCharacteristic, &message, sizeof(message)); } } + else{ // we are not connected to any peripheral. Signal the scan again + digitalWrite(BLE_LED, LOW); + delay(200); + digitalWrite(BLE_LED, HIGH); + delay(200); + } } void receiveAdvPck(BLEPeripheralPeer& peer){ diff --git a/libraries/BLE/examples/Central/scanner/scanner.ino b/libraries/BLE/examples/Central/scanner/scanner.ino index 7dc87cc..49ed1e7 100644 --- a/libraries/BLE/examples/Central/scanner/scanner.ino +++ b/libraries/BLE/examples/Central/scanner/scanner.ino @@ -37,7 +37,8 @@ void setup() { } void loop() { - // put the board in standby mode to save power + // since we want to realize a low power application we don't handle the + // BLE_LED in order to save power but put the board in low power mode instead. LowPower.standby(); } diff --git a/libraries/BLE/examples/Central/serialClient/serialClient.ino b/libraries/BLE/examples/Central/serialClient/serialClient.ino index 1d80cf9..99e4345 100644 --- a/libraries/BLE/examples/Central/serialClient/serialClient.ino +++ b/libraries/BLE/examples/Central/serialClient/serialClient.ino @@ -54,8 +54,10 @@ void setup() { } void loop() { - // if a device is connected send data read from the Serial port - if(bleCentral.connected()){ + // if a device is connected send data read from the Serial port + if(bleCentral.connected()){ + // turn BLE led on + digitalWrite(BLE_LED, HIGH); int len = 0; // send the message when it reaches the maximum value (20 char) // or when a carriage return (\n) is pressed @@ -77,6 +79,15 @@ void loop() { // send the message bleCentral.writeRemoteCharacteristic(remoteRxCharacteristic, message, len); } + else // if we are not connected we are scan. Move the BLE led accordingly + blinkOnScan(); +} + +void blinkOnScan(){ + digitalWrite(BLE_LED, LOW); + delay(200); + digitalWrite(BLE_LED, HIGH); + delay(200); } void receiveAdvPck(BLEPeripheralPeer& peer){ @@ -119,6 +130,9 @@ void bleCentralRemoteServicesDiscoveredHandler(BLEPeripheralPeer& peer) { void bleRemoteTxCharacteristicValueUpdatedHandle(BLEPeripheralPeer& peer, BLERemoteCharacteristic& characteristic) { - Serial.println("Remote characteristic value update handle"); - Serial.println((char *)remoteTxCharacteristic.value()); + // print the incoming message + char * message = (char *)remoteTxCharacteristic.value(); + for(int i=0; iExamples->BLE->Central->Bonding to test this feature. + In this example BLE_LED shows the status of the board. It will blink every 200 ms when the board is advertising. + It will be on when the board is connected to a central. It will be off when the board is disconnected. This example code is in the public domain. */ #include -#include #define CONFIRM_BUTTON USER1_BUTTON @@ -31,6 +32,9 @@ BLECharCharacteristic dummyCharacteristic = BLECharCharacteristic("19b10001 void setup() { Serial.begin(9600); + //initialize BLE led + pinMode(BLE_LED, OUTPUT); + // initialize button pinMode(CONFIRM_BUTTON, INPUT); @@ -60,8 +64,18 @@ void setup() { } void loop() { - // put the board in low power mode - LowPower.standby(); + // blink if the board is advertising + blinkOnAdv(); +} + +void blinkOnAdv(){ + // retrieve the peripheral status in order to blink only when advertising + if(blePeripheral.status() == ADVERTISING){ + digitalWrite(BLE_LED, LOW); + delay(200); + digitalWrite(BLE_LED, HIGH); + delay(200); + } } void showPasskey(BLECentral& central) { @@ -85,12 +99,16 @@ void blePeripheralConnectHandler(BLECentral& central) { // central connected event handler Serial.print(F("Connected event, central: ")); Serial.println(central.address()); + // turn BLE_LED on + digitalWrite(BLE_LED, HIGH); } void blePeripheralDisconnectHandler(BLECentral& central) { // central disconnected event handler Serial.print(F("Disconnected event, central: ")); Serial.println(central.address()); + // turn BLE_LED off + digitalWrite(BLE_LED, LOW); } void receiveMessage(int evtCode, int messageCode){ diff --git a/libraries/BLE/examples/Peripheral/Bonding/showPasskey/showPasskey.ino b/libraries/BLE/examples/Peripheral/Bonding/showPasskey/showPasskey.ino index f089a67..ecb1ab5 100644 --- a/libraries/BLE/examples/Peripheral/Bonding/showPasskey/showPasskey.ino +++ b/libraries/BLE/examples/Peripheral/Bonding/showPasskey/showPasskey.ino @@ -7,7 +7,10 @@ Use the complementary example enterPasskeyCentral.ino in File->Examples->BLE->Central->Bonding to test this feature. - + + In this example BLE_LED shows the status of the board. It will blink every 200 ms when the board is advertising. + It will be on when the board is connected to a central. It will be off when the board is disconnected. + This example code is in the public domain. */ @@ -26,6 +29,9 @@ BLECharCharacteristic dummyCharacteristic = BLECharCharacteristic("19b10001e8f void setup() { Serial.begin(9600); + //initialize BLE led + pinMode(BLE_LED, OUTPUT); + // set advertised local name and service UUID blePeripheral.setLocalName("BONDExample"); blePeripheral.setAdvertisedServiceUuid(dummyService.uuid()); @@ -53,8 +59,18 @@ void setup() { } void loop() { - // put the board in low power mode - LowPower.standby(); + // blink if the board is advertising + blinkOnAdv(); +} + +void blinkOnAdv(){ + // retrieve the peripheral status in order to blink only when advertising + if(blePeripheral.status() == ADVERTISING){ + digitalWrite(BLE_LED, LOW); + delay(200); + digitalWrite(BLE_LED, HIGH); + delay(200); + } } void showPasskey(BLECentral& central) { @@ -72,12 +88,16 @@ void blePeripheralConnectHandler(BLECentral& central) { // central connected event handler Serial.print(F("Connected event, central: ")); Serial.println(central.address()); + // turn BLE_LED on + digitalWrite(BLE_LED, HIGH); } void blePeripheralDisconnectHandler(BLECentral& central) { // central disconnected event handler Serial.print(F("Disconnected event, central: ")); Serial.println(central.address()); + // turn BLE_LED off + digitalWrite(BLE_LED, LOW); } void receiveMessage(int evtCode, int messageCode){ diff --git a/libraries/BLE/examples/Peripheral/CTSClient/CTSClient.ino b/libraries/BLE/examples/Peripheral/CTSClient/CTSClient.ino index be170ef..383da19 100644 --- a/libraries/BLE/examples/Peripheral/CTSClient/CTSClient.ino +++ b/libraries/BLE/examples/Peripheral/CTSClient/CTSClient.ino @@ -64,7 +64,8 @@ void setup() { } void loop() { - // put the board in standby mode to save power + // since we want to realize a low power application we don't handle the + // BLE_LED in order to save power but put the board in low power mode instead LowPower.standby(); } diff --git a/libraries/BLE/examples/Peripheral/Eddystone/EddystoneUID/EddystoneUID.ino b/libraries/BLE/examples/Peripheral/Eddystone/EddystoneUID/EddystoneUID.ino index 4636b64..79eeb98 100644 --- a/libraries/BLE/examples/Peripheral/Eddystone/EddystoneUID/EddystoneUID.ino +++ b/libraries/BLE/examples/Peripheral/Eddystone/EddystoneUID/EddystoneUID.ino @@ -21,6 +21,7 @@ void setup() { } void loop() { - // Put the board in low power mode + // since we want to realize a low power application we don't handle the + // BLE_LED in order to save power but put the board in low power mode instead LowPower.standby(); } diff --git a/libraries/BLE/examples/Peripheral/Eddystone/EddystoneURL/EddystoneURL.ino b/libraries/BLE/examples/Peripheral/Eddystone/EddystoneURL/EddystoneURL.ino index b8e93b7..7bfecf4 100644 --- a/libraries/BLE/examples/Peripheral/Eddystone/EddystoneURL/EddystoneURL.ino +++ b/libraries/BLE/examples/Peripheral/Eddystone/EddystoneURL/EddystoneURL.ino @@ -22,6 +22,7 @@ void setup() { } void loop() { - // Put the board in low power mode + // since we want to realize a low power application we don't handle the + // BLE_LED in order to save power but put the board in low power mode instead LowPower.standby(); } diff --git a/libraries/BLE/examples/Peripheral/HID/HID_joystick_mouse/HID_joystick_mouse.ino b/libraries/BLE/examples/Peripheral/HID/HID_joystick_mouse/HID_joystick_mouse.ino index d60f52d..a210e26 100644 --- a/libraries/BLE/examples/Peripheral/HID/HID_joystick_mouse/HID_joystick_mouse.ino +++ b/libraries/BLE/examples/Peripheral/HID/HID_joystick_mouse/HID_joystick_mouse.ino @@ -5,7 +5,9 @@ This example shows the use of the HID BLE library. Connect a joystick to the pins A0 and A1 of the board. Connect the board to the phone through the phone's bluetooth settings and try to - move the joystick or press the USER1_BUTTON to press a key + move the joystick or press the USER1_BUTTON to press a key. + In this example BLE_LED shows the status of the board. It will blink every 200 ms when the board is advertising. + It will be on when the board is connected to a central. It will be off when the board is disconnected. */ #include @@ -27,6 +29,9 @@ int joystickYCenter; void setup() { Serial.begin(9600); + //initialize BLE led + pinMode(BLE_LED, OUTPUT); + pinMode(JOYSTICK_BUTTON_PIN, INPUT_PULLUP); buttonState = digitalRead(JOYSTICK_BUTTON_PIN); @@ -50,7 +55,10 @@ void loop() { // central connected to peripheral Serial.print(F("Connected to central: ")); Serial.println(central.address()); - + + // turn on BLE_LED when connected + digitalWrite(BLE_LED, HIGH); + while (central.connected()) { int tempButtonState = digitalRead(JOYSTICK_BUTTON_PIN); if (tempButtonState != buttonState) { @@ -77,6 +85,12 @@ void loop() { Serial.print(F("Disconnected from central: ")); Serial.println(central.address()); } + + // here we are not connected. This means we are advertising + digitalWrite(BLE_LED, HIGH); + delay(200); + digitalWrite(BLE_LED, LOW); + delay(200); } int readJoystickAxis(int pin) { diff --git a/libraries/BLE/examples/Peripheral/HID/HID_keyboard/HID_keyboard.ino b/libraries/BLE/examples/Peripheral/HID/HID_keyboard/HID_keyboard.ino index ff81237..221b1f6 100644 --- a/libraries/BLE/examples/Peripheral/HID/HID_keyboard/HID_keyboard.ino +++ b/libraries/BLE/examples/Peripheral/HID/HID_keyboard/HID_keyboard.ino @@ -5,7 +5,9 @@ This example shows the use of the HID BLE library. Connect the board to the phone through the phone's bluetooth settings, open a text field in the phone and try to write something in the board serial terminal. - */ + In this example BLE_LED shows the status of the board. It will blink every 200 ms when the board is advertising. + It will be on when the board is connected to a central. It will be off when the board is disconnected. +*/ #include #include @@ -18,6 +20,9 @@ BLEKeyboard bleKeyboard; void setup() { Serial.begin(9600); + //initialize BLE led + pinMode(BLE_LED, OUTPUT); + // clear bond store data bleHIDPeripheral.clearBondStoreData(); @@ -41,6 +46,9 @@ void loop() { Serial.print(F("Connected to central: ")); Serial.println(central.address()); + // turn on BLE_LED when connected + digitalWrite(BLE_LED, HIGH); + while (central.connected()) { if (Serial.available() > 0) { // read in character @@ -57,4 +65,11 @@ void loop() { Serial.print(F("Disconnected from central: ")); Serial.println(central.address()); } + + // here we are not connected. This means we are advertising + digitalWrite(BLE_LED, HIGH); + delay(200); + digitalWrite(BLE_LED, LOW); + delay(200); + } \ No newline at end of file diff --git a/libraries/BLE/examples/Peripheral/HID/HID_keypad/HID_keypad.ino b/libraries/BLE/examples/Peripheral/HID/HID_keypad/HID_keypad.ino index e48604c..4484d72 100644 --- a/libraries/BLE/examples/Peripheral/HID/HID_keypad/HID_keypad.ino +++ b/libraries/BLE/examples/Peripheral/HID/HID_keypad/HID_keypad.ino @@ -8,6 +8,8 @@ columns: 7, 6, 5 Connect the board to the phone through the phone's bluetooth settings, open a text field in the phone and try to press a key in the keypad. + In this example BLE_LED shows the status of the board. It will blink every 200 ms when the board is advertising. + It will be on when the board is connected to a central. It will be off when the board is disconnected. */ #include @@ -35,6 +37,9 @@ BLEKeyboard bleKeyboard; void setup() { Serial.begin(9600); + //initialize BLE led + pinMode(BLE_LED, OUTPUT); + Serial.println(F("BLE HID Peripheral - clearing bond data")); // clear bond store data @@ -58,6 +63,9 @@ void loop() { Serial.print(F("Connected to central: ")); Serial.println(central.address()); + // turn on BLE_LED when connected + digitalWrite(BLE_LED, HIGH); + while (central.connected()) { char c = keypad.getKey(); @@ -71,4 +79,10 @@ void loop() { Serial.print(F("Disconnected from central: ")); Serial.println(central.address()); } + + // here we are not connected. This means we are advertising + digitalWrite(BLE_LED, HIGH); + delay(200); + digitalWrite(BLE_LED, LOW); + delay(200); } \ No newline at end of file diff --git a/libraries/BLE/examples/Peripheral/HID/HID_test/HID_test.ino b/libraries/BLE/examples/Peripheral/HID/HID_test/HID_test.ino index 3c9de75..6df5f8c 100644 --- a/libraries/BLE/examples/Peripheral/HID/HID_test/HID_test.ino +++ b/libraries/BLE/examples/Peripheral/HID/HID_test/HID_test.ino @@ -5,6 +5,8 @@ This example shows the use of the HID BLE library. Connect the board to the phone through the phone's bluetooth settings, open a serial terminal and type any characters. + In this example BLE_LED shows the status of the board. It will blink every 200 ms when the board is advertising. + It will be on when the board is connected to a central. It will be off when the board is disconnected. */ #include @@ -22,6 +24,9 @@ BLESystemControl bleSystemControl; void setup() { Serial.begin(9600); + //initialize BLE led + pinMode(BLE_LED, OUTPUT); + // clears bond data on every boot bleHID.clearBondStoreData(); @@ -50,6 +55,9 @@ void loop() { Serial.print(F("Connected to central: ")); Serial.println(central.address()); + // turn on BLE_LED when connected + digitalWrite(BLE_LED, HIGH); + while (bleHID.connected()) { if (Serial.available() > 0) { Serial.read(); @@ -67,4 +75,10 @@ void loop() { Serial.print(F("Disconnected from central: ")); Serial.println(central.address()); } + + // here we are not connected. This means we are advertising + digitalWrite(BLE_LED, HIGH); + delay(200); + digitalWrite(BLE_LED, LOW); + delay(200); } diff --git a/libraries/BLE/examples/Peripheral/HID/HID_volume/HID_volume.ino b/libraries/BLE/examples/Peripheral/HID/HID_volume/HID_volume.ino deleted file mode 100644 index aad6f69..0000000 --- a/libraries/BLE/examples/Peripheral/HID/HID_volume/HID_volume.ino +++ /dev/null @@ -1,107 +0,0 @@ -/* Copyright (c) Sandeep Mistry. All rights reserved. - Licensed under the MIT license. See LICENSE file in the project root for full license information. -*/ - -#include -#include - -// http://www.pjrc.com/teensy/td_libs_Encoder.html -#include - -#define BUTTON_PIN 5 - -#define ENC_RIGHT_PIN 3 -#define ENC_LEFT_PIN 4 - -#define INPUT_POLL_INTERVAL 100 - -BLEHIDPeripheral bleHIDPeripheral = BLEHIDPeripheral(); -BLEMultimedia bleMultimedia; - -Encoder encoder(ENC_RIGHT_PIN, ENC_LEFT_PIN); - -int buttonState; -unsigned long lastInputPollTime = 0; - -void setup() { - Serial.begin(9600); - - pinMode(BUTTON_PIN, INPUT_PULLUP); - buttonState = digitalRead(BUTTON_PIN); - - Serial.println(F("BLE HID Peripheral - clearing bond data")); - // clear bond store data - bleHIDPeripheral.clearBondStoreData(); - - encoder.write(0); - - bleHIDPeripheral.setReportIdOffset(1); - - - bleHIDPeripheral.setLocalName("HID Volume"); - bleHIDPeripheral.addHID(bleMultimedia); - - bleHIDPeripheral.begin(); - - Serial.println(F("BLE HID Volume Knob")); -} - -void loop() { - BLECentral central = bleHIDPeripheral.central(); - - if (central) { - // central connected to peripheral - Serial.print(F("Connected to central: ")); - Serial.println(central.address()); - - while (bleHIDPeripheral.connected()) { - pollInputs(); - } - - // central disconnected - Serial.print(F("Disconnected from central: ")); - Serial.println(central.address()); - } -} - -void pollInputs() { - // only poll the input every 100ms - if (millis() - lastInputPollTime > INPUT_POLL_INTERVAL) { - pollButton(); - - pollEncoder(); - - lastInputPollTime = millis(); - } -} - -void pollButton() { - // check the button - int tempButtonState = digitalRead(BUTTON_PIN); - - if (tempButtonState != buttonState) { - buttonState = tempButtonState; - - if (buttonState == LOW) { - Serial.println(F("Mute")); - bleMultimedia.write(MMKEY_MUTE); - } - } -} - -void pollEncoder() { - // check the encoder - int encoderState = encoder.read(); - - if (encoderState != 0) { - if (encoderState > 0) { - Serial.println(F("Volume up")); - bleMultimedia.write(MMKEY_VOL_UP); - } else { - Serial.println(F("Volume down")); - bleMultimedia.write(MMKEY_VOL_DOWN); - } - - encoder.write(0); - } -} \ No newline at end of file diff --git a/libraries/BLE/examples/Peripheral/ancs/ancs.ino b/libraries/BLE/examples/Peripheral/ancs/ancs.ino index 263e3f2..00cb18f 100644 --- a/libraries/BLE/examples/Peripheral/ancs/ancs.ino +++ b/libraries/BLE/examples/Peripheral/ancs/ancs.ino @@ -5,6 +5,8 @@ This example implements an Apple Notification Center Service client For detailed information about the Apple Notification Center Service, see Apple's iOS Developer Library https://developer.apple.com/library/content/documentation/CoreBluetooth/Reference/AppleNotificationCenterServiceSpecification/Introduction/Introduction.html + In this example BLE_LED shows the status of the board. It will blink every 200 ms when the board is advertising. + It will be on when the board is connected to a central. It will be off when the board is disconnected. */ #include @@ -26,6 +28,8 @@ BLERemoteCharacteristic ancsNotificationSourceCharacteristic = BLER void setup() { Serial.begin(9600); + pinMode(BLE_LED, OUTPUT); + // clears bond data on every boot bleBondStore.clearData(); @@ -61,18 +65,35 @@ void setup() { void loop() { blePeripheral.poll(); + // BLE_LED will be blinking when the board is advertising, + // on when the board is connected and off when it's disconnected. + blinkOnAdv(); +} + +void blinkOnAdv(){ + // retrieve the peripheral status in order to blink only when advertising + if(blePeripheral.status() == ADVERTISING){ + digitalWrite(BLE_LED, LOW); + delay(200); + digitalWrite(BLE_LED, HIGH); + delay(200); + } } void blePeripheralConnectHandler(BLECentral& central) { // central connected event handler Serial.print(F("Connected event, central: ")); Serial.println(central.address()); + // turn BLE_LED on + digitalWrite(BLE_LED, HIGH); } void blePeripheralDisconnectHandler(BLECentral& central) { // central disconnected event handler Serial.print(F("Disconnected event, central: ")); Serial.println(central.address()); + // turn BLE_LED off + digitalWrite(BLE_LED, LOW); } void blePeripheralBondedHandler(BLECentral& central) { diff --git a/libraries/BLE/examples/Peripheral/led/led.ino b/libraries/BLE/examples/Peripheral/led/led.ino index 4c66924..b53ee95 100644 --- a/libraries/BLE/examples/Peripheral/led/led.ino +++ b/libraries/BLE/examples/Peripheral/led/led.ino @@ -5,6 +5,9 @@ This example shows how to read/write a characteristic to turn a LED on or off You can use nRFConnect app to read/write the characteristic https://www.nordicsemi.com/eng/Products/Nordic-mobile-Apps/nRF-Connect-for-mobile-previously-called-nRF-Master-Control-Panel + + In this example BLE_LED shows the status of the board. It will blink every 200 ms when the board is advertising. + It will be on when the board is connected to a central. It will be off when the board is disconnected. */ #include @@ -24,6 +27,9 @@ BLECharCharacteristic switchCharacteristic = BLECharCharacteristic("19b10001e void setup() { Serial.begin(9600); + //initialize BLE led + pinMode(BLE_LED, OUTPUT); + // set LED pin to output mode pinMode(LED_PIN, OUTPUT); @@ -49,6 +55,9 @@ void loop() { Serial.print(F("Connected to central: ")); Serial.println(central.address()); + // turn on BLE_LED when connected + digitalWrite(BLE_LED, HIGH); + while (central.connected()) { // central still connected to peripheral if (switchCharacteristic.written()) { @@ -67,4 +76,10 @@ void loop() { Serial.print(F("Disconnected from central: ")); Serial.println(central.address()); } + + // here we are not connected. This means we are advertising + digitalWrite(BLE_LED, HIGH); + delay(200); + digitalWrite(BLE_LED, LOW); + delay(200); } diff --git a/libraries/BLE/examples/Peripheral/led_callback/led_callback.ino b/libraries/BLE/examples/Peripheral/led_callback/led_callback.ino index ea34c49..6fd7d01 100644 --- a/libraries/BLE/examples/Peripheral/led_callback/led_callback.ino +++ b/libraries/BLE/examples/Peripheral/led_callback/led_callback.ino @@ -59,7 +59,8 @@ void setup() { } void loop() { - // put the board in low power mode + // since we want to realize a low power application we don't handle the + // BLE_LED in order to save power but put the board in low power mode instead LowPower.standby(); } diff --git a/libraries/BLE/examples/Peripheral/led_switch/led_switch.ino b/libraries/BLE/examples/Peripheral/led_switch/led_switch.ino index e35b7c0..95de715 100644 --- a/libraries/BLE/examples/Peripheral/led_switch/led_switch.ino +++ b/libraries/BLE/examples/Peripheral/led_switch/led_switch.ino @@ -8,7 +8,10 @@ You can use nRFConnect app to read/write the characteristic https://www.nordicsemi.com/eng/Products/Nordic-mobile-Apps/nRF-Connect-for-mobile-previously-called-nRF-Master-Control-Panel or use another board with led_switch_client example in File->Examples->BLE->Central menu. - */ + + In this example BLE_LED shows the status of the board. It will blink every 200 ms when the board is advertising. + It will be on when the board is connected to a central. It will be off when the board is disconnected. + */ #include @@ -29,6 +32,9 @@ BLECharCharacteristic buttonCharacteristic = BLECharCharacteristic("19b10012e void setup() { Serial.begin(115200); + //initialize BLE led + pinMode(BLE_LED, OUTPUT); + // set LED pin to output mode, button pin to input mode pinMode(LED_PIN, OUTPUT); pinMode(BUTTON_PIN, INPUT); @@ -74,4 +80,14 @@ void loop() { digitalWrite(LED_PIN, LOW); } } + + // retrieve the peripheral status in order to blink only when advertising + if(blePeripheral.status() == ADVERTISING){ + digitalWrite(BLE_LED, LOW); + delay(200); + digitalWrite(BLE_LED, HIGH); + delay(200); + } + else // if we are not advertising, we are connected + digitalWrite(BLE_LED, HIGH); } \ No newline at end of file diff --git a/libraries/BLE/examples/Peripheral/remote_service/remote_service.ino b/libraries/BLE/examples/Peripheral/remote_service/remote_service.ino index d15f963..7474aea 100644 --- a/libraries/BLE/examples/Peripheral/remote_service/remote_service.ino +++ b/libraries/BLE/examples/Peripheral/remote_service/remote_service.ino @@ -19,6 +19,9 @@ BLERemoteCharacteristic remoteDeviceNameCharacteristic = BLER void setup() { Serial.begin(9600); + //initialize BLE led + pinMode(BLE_LED, OUTPUT); + blePeripheral.setLocalName("remote-attributes"); // set device name and appearance @@ -44,18 +47,34 @@ void setup() { void loop() { blePeripheral.poll(); + // blink if the board is advertising + blinkOnAdv(); +} + +void blinkOnAdv(){ + // retrieve the peripheral status in order to blink only when advertising + if(blePeripheral.status() == ADVERTISING){ + digitalWrite(BLE_LED, LOW); + delay(200); + digitalWrite(BLE_LED, HIGH); + delay(200); + } } void blePeripheralConnectHandler(BLECentral& central) { // central connected event handler Serial.print(F("Connected event, central: ")); Serial.println(central.address()); + // turn BLE_LED on + digitalWrite(BLE_LED, HIGH); } void blePeripheralDisconnectHandler(BLECentral& central) { // central disconnected event handler Serial.print(F("Disconnected event, central: ")); Serial.println(central.address()); + // turn BLE_LED off + digitalWrite(BLE_LED, LOW); } void blePeripheralRemoteServicesDiscoveredHandler(BLECentral& central) { diff --git a/libraries/BLE/examples/Peripheral/remote_test/remote_test.ino b/libraries/BLE/examples/Peripheral/remote_test/remote_test.ino index 9835365..129294d 100644 --- a/libraries/BLE/examples/Peripheral/remote_test/remote_test.ino +++ b/libraries/BLE/examples/Peripheral/remote_test/remote_test.ino @@ -22,6 +22,9 @@ BLERemoteCharacteristic remoteCharacteristic4 = BLER void setup() { Serial.begin(9600); + //initialize BLE led + pinMode(BLE_LED, OUTPUT); + blePeripheral.setLocalName("remote-test"); // set device name and appearance @@ -53,18 +56,34 @@ void setup() { void loop() { blePeripheral.poll(); + // blink if the board is advertising + blinkOnAdv(); +} + +void blinkOnAdv(){ + // retrieve the peripheral status in order to blink only when advertising + if(blePeripheral.status() == ADVERTISING){ + digitalWrite(BLE_LED, LOW); + delay(200); + digitalWrite(BLE_LED, HIGH); + delay(200); + } } void blePeripheralConnectHandler(BLECentral& central) { // central connected event handler Serial.print(F("Connected event, central: ")); Serial.println(central.address()); + // turn BLE_LED on + digitalWrite(BLE_LED, HIGH); } void blePeripheralDisconnectHandler(BLECentral& central) { // central disconnected event handler Serial.print(F("Disconnected event, central: ")); Serial.println(central.address()); + // turn BLE_LED off + digitalWrite(BLE_LED, LOW); } void blePeripheralRemoteServicesDiscoveredHandler(BLECentral& central) { diff --git a/libraries/BLE/examples/Peripheral/serial/serial.ino b/libraries/BLE/examples/Peripheral/serial/serial.ino index aea59ad..8b7d8a4 100644 --- a/libraries/BLE/examples/Peripheral/serial/serial.ino +++ b/libraries/BLE/examples/Peripheral/serial/serial.ino @@ -14,6 +14,9 @@ * Please note that TX and RX characteristics use Notify and WriteWithoutResponse, so there's no guarantee * that the data will make it to the other end. However, under normal circumstances and reasonable signal * strengths everything works well. + * + * In this example BLE_LED shows the status of the board. It will blink every 200 ms when the board is advertising. + * It will be on when the board is connected to a central. It will be off when the board is disconnected. */ @@ -28,6 +31,9 @@ void setup() { // custom services and characteristics can be added as well bleSerial.setLocalName("UART"); + //initialize BLE led + pinMode(BLE_LED, OUTPUT); + Serial.begin(9600); bleSerial.begin(); } @@ -38,6 +44,16 @@ void loop() { forward(); // loopback(); // spam(); + + // handle the BLE led. Blink when advertising + if(bleSerial.status() == ADVERTISING){ + digitalWrite(BLE_LED, LOW); + delay(200); + digitalWrite(BLE_LED, HIGH); + delay(200); + } + else // if we are not advertising, we are connected + digitalWrite(BLE_LED, HIGH); } diff --git a/libraries/BLE/examples/Peripheral/starter/starter.ino b/libraries/BLE/examples/Peripheral/starter/starter.ino index 109d931..60d2b2a 100644 --- a/libraries/BLE/examples/Peripheral/starter/starter.ino +++ b/libraries/BLE/examples/Peripheral/starter/starter.ino @@ -3,6 +3,8 @@ Modified by Chiara Ruggeri This example shows how to use the BLEPeripheral library. + The example also uses BLE_LED to show the status of the board. It will blink every 200 ms when the board is advertising. + It will be on when the board is connected to a central. It will be off when the board is disconnected. */ #include @@ -26,6 +28,9 @@ BLEDescriptor descriptor = BLEDescriptor("2901", "value"); void setup() { Serial.begin(115200); + //initialize BLE led + pinMode(BLE_LED, OUTPUT); + blePeripheral.setLocalName("local-name"); // optional blePeripheral.setAdvertisedServiceUuid(service.uuid()); // optional @@ -64,4 +69,14 @@ void loop() { Serial.print(F("Disconnected from central: ")); Serial.println(central.address()); } + + // retrieve the peripheral status in order to blink only when advertising + if(blePeripheral.status() == ADVERTISING){ + digitalWrite(BLE_LED, LOW); + delay(200); + digitalWrite(BLE_LED, HIGH); + delay(200); + } + else // if we are not advertising, we are connected + digitalWrite(BLE_LED, HIGH); } \ No newline at end of file diff --git a/libraries/BLE/keywords.txt b/libraries/BLE/keywords.txt index eec43a0..9841d7b 100644 --- a/libraries/BLE/keywords.txt +++ b/libraries/BLE/keywords.txt @@ -116,6 +116,7 @@ hasData KEYWORD2 clearData KEYWORD2 storeData KEYWORD2 restoreData KEYWORD2 +status KEYWORD2 setValueLE KEYWORD2 valueLE KEYWORD2 @@ -193,3 +194,8 @@ BLEScanReceived LITERAL1 BLEMessage LITERAL1 BLEValueUpdated LITERAL1 + +ADVERTISING LITERAL1 +SCANNING LITERAL1 +CONNECT LITERAL1 +DISCONNECT LITERAL1 \ No newline at end of file diff --git a/libraries/BLE/nRF51822.cpp b/libraries/BLE/nRF51822.cpp index f381fe0..9678125 100644 --- a/libraries/BLE/nRF51822.cpp +++ b/libraries/BLE/nRF51822.cpp @@ -487,6 +487,7 @@ void nRF51822::begin(unsigned char advertisementDataSize, } this->startAdvertising(); + this->_status = 2; #ifdef __RFduino__ RFduinoBLE_enabled = 1; @@ -522,7 +523,7 @@ void nRF51822::poll(ble_evt_t *bleEvt) { Serial.print(F("Evt Connected ")); Serial.println(address); #endif - + this->_status = 0; this->_connectionHandle = bleEvt->evt.gap_evt.conn_handle; #if defined(NRF5) && !defined(S110) @@ -564,6 +565,7 @@ void nRF51822::poll(ble_evt_t *bleEvt) { #endif this->_connectionHandle = BLE_CONN_HANDLE_INVALID; this->_txBufferCount = 0; + this->_status = 1; for (int i = 0; i < this->_numLocalCharacteristics; i++) { struct localCharacteristicInfo* localCharacteristicInfo = &this->_localCharacteristicInfo[i]; @@ -596,6 +598,7 @@ void nRF51822::poll(ble_evt_t *bleEvt) { this->_remoteRequestInProgress = false; this->startAdvertising(); + this->_status = 2; break;