Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BLE_API mbed nRF51822
Fork of BLE_GATT_test1 by
main.cpp
- Committer:
- alexanderlea
- Date:
- 2015-01-18
- Revision:
- 2:f538ff758828
- Parent:
- 1:ebdf445c4bcc
- Child:
- 3:f3d20b36b7ea
File content as of revision 2:f538ff758828:
/*
* TODO:
* - Make it work!
*/
#include "mbed.h"
#include "BLEDevice.h"
#include "CarCommsService.h"
#include "TestGattService.h"
#include <string>
using namespace std;
BLEDevice ble;
DigitalOut led1(LED1);
Serial pc(USBTX, USBRX);
/*Variable Declarations*/
const static char DEVICE_NAME[] = "BLE_NODE";
static volatile bool connected;
void blink(void)
{
led1 = !led1; /* Do blinky on LED1 while we're waiting for BLE events */
}
void disconnectionCallback(Gap::Handle_t handle, Gap::DisconnectionReason_t reason)
{
pc.printf("Disconnected! - start advertising. Handle:%d, Reason:0x%02x\r\n", handle, reason);
connected=false;
ble.startAdvertising();
}
//Handle_t, addr_type_t peerAddrType, const address_t peerAddr, const ConnectionParams_t *
void connectionCallback(Gap::Handle_t handle, Gap::addr_type_t peerAddrType, const Gap::address_t peerAddr, const Gap::ConnectionParams_t *parms)
{
pc.printf("Connected! - stop advertising. Handle:%d, eType:%d, Add:%u.\r\n", handle, peerAddrType, peerAddr);
connected = true;
// ble.stopAdvertising();
}
int main(void)
{
uint8_t testCommand = 12;
//blinky
led1 = 1;
Ticker t;
t.attach(blink, 1.0f);
//Create BLE stuff
ble.init();
ble.onDisconnection(disconnectionCallback);
ble.onConnection(connectionCallback);
//CarCommsService commsService(ble, cmd);
TestGattService testService(ble, 0);
/*
**BREDR_NOT_SUPPORTED = BLE only
**LE_GENERAL_DISCOVERABLE = Device is discoverable at any moment (no time out)
**ADV_CONNECTABLE_UNDIRECTED = Any central device can connect
*/
ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
// ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list));
ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));
ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
//Advertise
ble.setAdvertisingInterval(160); /* 1s; in multiples of 0.625ms. */ //was 1600
ble.startAdvertising();
pc.printf("Advertising node %s\n\r", DEVICE_NAME);
while(true) {
ble.waitForEvent(); // this will return upon any system event (such as an interrupt or a ticker wakeup)
testCommand++;
if (testCommand < 100) {
testCommand = 0;
}
pc.printf("Level = %u\r\n", testCommand);
testService.sendCommand(testCommand);
}
}
