#include #define LED_BUILTIN 8 BLEService BlinkySvc("19b10000-e8f2-537e-6969-d104768a1214"); // from https://www.guidgenerator.com/ BLEIntCharacteristic BlinkyChar("19b10001-e8f2-537e-6969-d104768a1214", BLERead | BLEWrite | BLENotify); BLEDescriptor FamilyDesc( "2969", "CanHobby" ); bool CX; // we are Connected. void setup() { Serial.begin( 115200 ); printf( "Built-In is 0x%02x\n", LED_BUILTIN ); pinMode( LED_BUILTIN, OUTPUT ); //set pins as outputs and set LED's HIGH (HIGH is off for this board) digitalWrite( LED_BUILTIN, LOW ); if (!BLE.begin()) { // begin initialization delay( 200 ); // while (1); // wait until initialization complete } printf("I waited 2 secs\n"); BLE.setLocalName("BlinkyBLE"); // set advertised local name BLE.setAdvertisedService( BlinkySvc ); // set advertised service UUID BlinkySvc.addCharacteristic( BlinkyChar ); // add the red characteristic to the service BlinkySvc. BLE.addService( BlinkySvc ); // add service BLE.advertise(); // start advertising printf("end Setup\n"); } uint8_t BlinkyCharVal; void loop() { BLEDevice central = BLE.central(); // listen for BLE devices to connect: if (central) { // if a central is connected to peripheral: printf("Phone connected to BlinkyBLE\n"); // put code here to preform 1 time when device is connected CX = true; while (central.connected()) { // while the central is still connected to peripheral /**** if( BathChar.valueUpdated() ) { BathChar.readValue( BathCharVal ); printf("BathCharVal = 0x%X\n", BathCharVal ); if( BathCharVal & 1 ) { printf("BathCharVal id Odd\n" ); } else { printf("BathCharVal id Even\n" ); } } ******/ // if there is an update from Android App, change light ON (0) or OFF (1) if ( BlinkyChar.written()) { BlinkyCharVal = BlinkyChar.value(); printf("Blinky Written = 0x%0X\n", BlinkyCharVal ); digitalWrite( LED_BUILTIN, BlinkyCharVal ); } } // end of while loop } if(CX) { printf("not connected\n"); CX=0; } // digitalWrite( LED_BUILTIN, HIGH ); } } // end of loop