project for eddystone

Dependencies:   BLE_API mbed nRF51822

Fork of BLE_URIBeacon by Bluetooth Low Energy

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2006-2015 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #include "mbed.h"
00018 #include "ble/BLE.h"
00019 #include "ble/services/EddystoneService.h"
00020 
00021 DigitalOut led1(LED1, 1);
00022 
00023 static uint8_t UIDnamespace[] = {0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99,0xAA}; // 10Bytes for Namespace UUID
00024 static uint8_t UIDinstance[]  = {0xbb,0xcc,0xdd,0xee,0xff,0x00}; // 6Bytes for Instance UUID
00025 static char Url[] = "http://www.mbed.org";
00026 static int8_t radioTxPower = 20;
00027 static int8_t advTxPower = -20;
00028 static uint16_t beaconPeriodus = 1000;
00029 static uint8_t tlmVersion = 0x00;
00030 
00031 static int battery = 0;
00032 static int temp = 0;
00033 
00034 EddystoneService *eddyBeaconPtr;
00035 
00036 void blinkCallback(void)
00037 {
00038     led1 = !led1; /* Do blinky on LED1 while we're waiting for BLE events */
00039 }
00040 
00041 /* Optional Function to update Eddystone beacon TLM frame battery voltage */
00042 void tlmBatteryCallback(void){
00043     /* add the function to get battery */
00044     battery = 0xFEFE;
00045     eddyBeaconPtr->updateTlmBatteryVoltage(battery);
00046 }
00047 
00048 /* Optional Function to update Eddystone beacon TLM frame temperature */
00049 void tlmTemperatureCallback(void){
00050     /* add the function to get temperature*/
00051     eddyBeaconPtr->updateTlmBeaconTemp(temp++);
00052 }
00053 
00054 int main(void)
00055 {
00056 //    minar::Scheduler::postCallback(blinkCallback).period(minar::milliseconds(500));
00057     Ticker tickerBattery;
00058     Ticker tickerTemp;
00059     
00060     BLE &ble = BLE::Instance();
00061     ble.init();
00062 
00063     /* Setup Eddystone Service */
00064     eddyBeaconPtr = new EddystoneService(ble, beaconPeriodus, radioTxPower);
00065 
00066     /* Set Eddystone Frame Data (TLM,UID,URI...etc) */
00067     eddyBeaconPtr->setTLMFrameData(tlmVersion, 5.0);
00068     eddyBeaconPtr->setURLFrameData(advTxPower, Url, 2.0);
00069     eddyBeaconPtr->setUIDFrameData(advTxPower, UIDnamespace, UIDinstance, 3.0);
00070 
00071     /* Callbacks for temperature / battery updates */
00072 //    minar::Scheduler::postCallback(tlmTemperatureCallback).period(minar::milliseconds(2000));
00073 //    minar::Scheduler::postCallback(tlmBatteryCallback).period(minar::milliseconds(1000));
00074     tickerBattery.attach(tlmBatteryCallback, 1);
00075     tickerTemp.attach(tlmTemperatureCallback,1);
00076     /* Start Advertising the eddystone service. */
00077     eddyBeaconPtr->start();
00078     ble.gap().startAdvertising();
00079     
00080     while (true) {
00081         ble.waitForEvent();
00082     }
00083     
00084 }