Bluetooth Low Energy for Smart Plug

Dependencies:   BLE_API mbed nRF51822

Fork of SmartPlugBLE by Pavit Noinongyao

Committer:
Slepnir
Date:
Tue Jul 07 04:02:14 2015 +0000
Revision:
0:25ad6eba7916
Child:
2:6db5c9a2894c
V1:; - Successfully advertise and connect ; - Update fail; - Can read only 4 bit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Slepnir 0:25ad6eba7916 1 #include "BLECommunication.h"
Slepnir 0:25ad6eba7916 2 //uint8_t DEVICE_NAME[] = "NRFTEST";
Slepnir 0:25ad6eba7916 3 //uint16_t list[] = {SPS_UUID_SERVICE};
Slepnir 0:25ad6eba7916 4
Slepnir 0:25ad6eba7916 5 BLECommunication::BLECommunication(SmartPlugBLE& system,BLE &_ble):
Slepnir 0:25ad6eba7916 6 ble(_ble),smartPlugService(ble,system),led(LED3)
Slepnir 0:25ad6eba7916 7 {
Slepnir 0:25ad6eba7916 8
Slepnir 0:25ad6eba7916 9 ble.init();
Slepnir 0:25ad6eba7916 10
Slepnir 0:25ad6eba7916 11 ble.gattServer().onDataWritten(&smartPlugService,&SmartPlugService::onDataWritten);
Slepnir 0:25ad6eba7916 12 smartPlugService.setupService();
Slepnir 0:25ad6eba7916 13 //start();
Slepnir 0:25ad6eba7916 14 }
Slepnir 0:25ad6eba7916 15
Slepnir 0:25ad6eba7916 16 void BLECommunication::start(void)
Slepnir 0:25ad6eba7916 17 {
Slepnir 0:25ad6eba7916 18 //ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
Slepnir 0:25ad6eba7916 19 // ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t*)list, sizeof(list));
Slepnir 0:25ad6eba7916 20 // ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::UNKNOWN);
Slepnir 0:25ad6eba7916 21 // ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));//cannot blink after this
Slepnir 0:25ad6eba7916 22 //
Slepnir 0:25ad6eba7916 23 // ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
Slepnir 0:25ad6eba7916 24 // ble.gap().setAdvertisingInterval(1000); /* 1000ms */
Slepnir 0:25ad6eba7916 25 //
Slepnir 0:25ad6eba7916 26 // ble.gap().startAdvertising();
Slepnir 0:25ad6eba7916 27 // while(true)
Slepnir 0:25ad6eba7916 28 // {
Slepnir 0:25ad6eba7916 29 // ble.waitForEvent();
Slepnir 0:25ad6eba7916 30 // }
Slepnir 0:25ad6eba7916 31 }
Slepnir 0:25ad6eba7916 32
Slepnir 0:25ad6eba7916 33 void BLECommunication::periodicCallback(void)
Slepnir 0:25ad6eba7916 34 {
Slepnir 0:25ad6eba7916 35 led = !led;
Slepnir 0:25ad6eba7916 36 }