I have so far succeeded. My initial test was to change the local name which a very common function and I have not made it to function as a beacon. I am taking it 1 step at a time. I used the sample program provided by Sparkfun on their website which is the Ble Blink Example. I added the following features:
- Added a new Service to change the local name
- Added a characteristics under the new Service
- When the value on the said characteristic change, it will change the local name and reset the BLE.
The logic is very much the same as the original program when turning on/off the LED connected at pin 7. And here is the source code :
// Import libraries (BLEPeripheral depends on SPI)#include <SPI.h>#include <BLEPeripheral.h>//////////////// Hardware ////////////////#define LED_PIN 7 // LED on pin 7#define LED_ACTIVE LOW // Pin 7 LED is active low#define LED_DEFAULT LOW///////////////////////// BLE Advertisments /////////////////////////const char * localName = "LED Off"; //change the local nameBLEPeripheral blePeriph;BLEService bleServ("1207");BLEService chgName("1208");//added new serviceBLECharCharacteristic ledChar("1207", BLERead | BLEWrite);BLECharCharacteristic chgChar("1208", BLERead | BLEWrite);//added new characteristicsint vb =0;void setup(){Serial.begin(115200); // Set up serial at 115200 baudpinMode(LED_PIN, OUTPUT);digitalWrite(LED_PIN, !LED_ACTIVE);setupBLE();}void loop(){blePeriph.poll();//--if (ledChar.written()){int ledState = ledChar.value();if (ledState) {digitalWrite(LED_PIN, LED_ACTIVE);} else {digitalWrite(LED_PIN, !LED_ACTIVE);}}//--//--This my added service when change this is triggeredif (chgChar.written()){int chgState = chgChar.value();if (chgState) {blePeriph.end();setupBLE0();} else {blePeriph.end();setupBLE1();}}//--}void setupBLE(){// Advertise name and service:blePeriph.setDeviceName(localName);blePeriph.setLocalName(localName);blePeriph.setAdvertisedServiceUuid(bleServ.uuid());// Add serviceblePeriph.addAttribute(bleServ);// Add characteristicblePeriph.addAttribute(ledChar);//my New Service and characteristicblePeriph.addAttribute(chgName);blePeriph.addAttribute(chgChar);// Now that device6, service, characteristic are set up,// initialize BLE:blePeriph.begin();// Set led characteristic to default value:ledChar.setValue(!LED_ACTIVE);}void setupBLE1(){// Advertise name and service:blePeriph.setDeviceName("LED Off");blePeriph.setLocalName("LED Off");// initialize BLE:blePeriph.begin();}void setupBLE0(){// Advertise name and service:blePeriph.setDeviceName(localName);blePeriph.setLocalName(localName);// initialize BLE:blePeriph.begin();}And here is the video on how it is done(1208 is the new service visible in nRF Connect:
“I jumped on an opportunity to purchase a rental property over the 4th of weekend. Mr Lee was quick to respond and since this was my first time getting a loan to buy a rental property , he was able to help me walk through the loan process. It was a great experience working with a good and kind loan lender Mr Lee. I hopefully know very well if you are outta looking for loan to purchase a property or funding business purpose then Mr Lee will be able to help you with such process here his details WhatsApp +1-989-394-3740. / 247officedept@gmail.com !”
ReplyDeletebest Mixer Grinder Under 6000
ReplyDeletebest mixer grinder under 3500
best mixer grinder under 1000
best mixer grinder in India
Wow this is amazing post. Thanks for sharing the valuable content with us.
ReplyDeleteWigs for women
best chairs mart