prod

Dependencies:   BLE_API mbed nRF51822 X_NUCLEO_IDB0XA1

Fork of BLE_EddystoneBeacon_Service by Bluetooth Low Energy

main.cpp

Committer:
mbedAustin
Date:
2015-10-01
Revision:
33:862e6e0831ea
Parent:
32:41840b78597e
Child:
34:f6d4a699a1ea

File content as of revision 33:862e6e0831ea:

/* mbed Microcontroller Library
 * Copyright (c) 2006-2013 ARM Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "mbed.h"
#include "BLE.h"
#include "ble/services/EddystoneService.h"

BLE ble;
uint8_t UIDnamespace[] = {0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99,0xAA}; // 10Bytes for Namespace UUID
uint8_t UIDinstance[]  = {0xbb,0xcc,0xdd,0xee,0xff,0x00}; // 6Bytes for Instance UUID
char Url[] = "http://www.mbed.org";
int8_t radioTxPower = 20;
int8_t advTxPower = -20;
uint16_t beaconPeriodus = 1000;
uint8_t tlmVersion = 0x00;


//Callbacks for temperature / battery updates
Ticker tlmBattery;
Ticker tlmTemperature;
int battery = 0;
int temp = 0;

// Setup Eddystone Service 
EddystoneService eddyBeacon(ble,beaconPeriodus,radioTxPower);


// Function to update beacon battery voltage
void tlmBatteryCallback(void){
    eddyBeacon.updateTlmBatteryVoltage(battery++);
}

// Function to update Beacon Temperature
void tlmTemperatureCallback(void){
    eddyBeacon.updateTlmBeaconTemp(temp++);
}

int main(void)
{
    printf("Starting Example\r\n"); // To enable low power mode disable all printf's
    ble.init();
    
    // Set Eddystone Frame Data (TLM,UID,URI...etc)
    eddyBeacon.setTLMFrameData(tlmVersion,5.0);
    eddyBeacon.setURLFrameData(advTxPower, Url, 2.0);
    eddyBeacon.setUIDFrameData(advTxPower, UIDnamespace, UIDinstance, 3.0);
    
    // Attach functions to modify TLM data
    tlmTemperature.attach(tlmTemperatureCallback,2.0f);
    tlmBattery.attach(tlmBatteryCallback, 1.0f);

    // Start Advertising the eddystone service. 
    eddyBeacon.start(); 
    ble.gap().startAdvertising();
    
    printf("Running...\r\n");
    while (true) {
        ble.waitForEvent();
    }
}