Bluetooth Low Energy for Smart Plug
Dependencies: BLE_API mbed nRF51822
Fork of SmartPlugBLE by
BLECommunication.cpp
00001 #include "BLECommunication.h" 00002 00003 00004 BLECommunication::BLECommunication(SmartPlugBLE& system,BLE &_ble): 00005 ble(_ble),smartPlugService(ble,system) 00006 { 00007 00008 ble.init(); 00009 ble.gattServer().onDataWritten(&smartPlugService,&SmartPlugService::onDataWritten); 00010 smartPlugService.setupService(); 00011 start(); 00012 } 00013 00014 void BLECommunication::start(void) 00015 { 00016 ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE); 00017 ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t*)list, sizeof(list)); 00018 ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::UNKNOWN); 00019 ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME));//cannot blink after this 00020 00021 ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); 00022 ble.gap().setAdvertisingInterval(1000); /* 1000ms */ 00023 00024 ble.gap().startAdvertising(); 00025 while(true) 00026 { 00027 ble.waitForEvent(); 00028 } 00029 }
Generated on Fri Jul 22 2022 14:22:22 by 1.7.2