Nathan Yonkee / Mbed 2 deprecated Blynk_RBL_BLE_Nano

Dependencies:   BLE_API Blynk mbed nRF51822

Fork of Blynk_RBL_BLE_Nano by Volodymyr Shymanskyy

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /**************************************************************
00002  * Blynk is a platform with iOS and Android apps to control
00003  * Arduino, Raspberry Pi and the likes over the Internet.
00004  * You can easily build graphic interfaces for all your
00005  * projects by simply dragging and dropping widgets.
00006  *
00007  *   Downloads, docs, tutorials: http://www.blynk.cc
00008  *   Blynk community:            http://community.blynk.cc
00009  *   Social networks:            http://www.fb.com/blynkapp
00010  *                               http://twitter.com/blynk_app
00011  *
00012  * Blynk library is licensed under MIT license
00013  * This example code is in public domain.
00014  *
00015  **************************************************************
00016  *
00017  * This example shows how to use RedBearLab BLE Nano
00018  * to connect your project to Blynk.
00019  *
00020  * NOTE: BLE support is in beta!
00021  *
00022  **************************************************************/
00023 
00024 #define BLYNK_DEBUG
00025 #define BLYNK_PRINT stdout
00026 
00027 //#define BLYNK_USE_DIRECT_CONNECT
00028 
00029 #include <BlynkSimpleRedBearLab_BLE_Nano.h>
00030 
00031 // You should get Auth Token in the Blynk App.
00032 // Go to the Project Settings (nut icon).
00033 char auth[] = "e371ee943c6145a4bcb4fb1a24ee3abe";
00034 
00035 uint8_t device_name[] = "Blynker";
00036 
00037 void setup() {
00038   ble.init();
00039 
00040   ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED);
00041   ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,
00042                                         device_name, sizeof(device_name) - 1);
00043                                         
00044   ble.gap().setDeviceName(device_name);
00045   ble.gap().setTxPower(4);
00046   
00047   // Add Blynk service...
00048   Blynk.begin(auth);
00049 
00050   ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED);
00051   ble.gap().setAdvertisingInterval(Gap::MSEC_TO_GAP_DURATION_UNITS(1000));
00052   ble.gap().setAdvertisingTimeout(0);
00053   ble.startAdvertising();
00054 
00055   printf("Waiting for connections...\n");
00056 }
00057 
00058 void loop() {
00059   Blynk.run();
00060 }
00061 
00062 int main(void) {
00063     setup();
00064     while(1) {
00065         loop();
00066     }
00067 }