clone
Dependencies: BLE_API Blynk mbed nRF51822
Fork of Blynk_RBL_BLE_Nano by
main.cpp@2:56696744060e, 2017-11-24 (annotated)
- Committer:
- tulanthoar
- Date:
- Fri Nov 24 18:43:11 2017 +0000
- Revision:
- 2:56696744060e
- Parent:
- 1:6b5c74442c7a
clone;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
vshymanskyy | 1:6b5c74442c7a | 1 | /************************************************************** |
vshymanskyy | 1:6b5c74442c7a | 2 | * Blynk is a platform with iOS and Android apps to control |
vshymanskyy | 1:6b5c74442c7a | 3 | * Arduino, Raspberry Pi and the likes over the Internet. |
vshymanskyy | 1:6b5c74442c7a | 4 | * You can easily build graphic interfaces for all your |
vshymanskyy | 1:6b5c74442c7a | 5 | * projects by simply dragging and dropping widgets. |
vshymanskyy | 1:6b5c74442c7a | 6 | * |
vshymanskyy | 1:6b5c74442c7a | 7 | * Downloads, docs, tutorials: http://www.blynk.cc |
vshymanskyy | 1:6b5c74442c7a | 8 | * Blynk community: http://community.blynk.cc |
vshymanskyy | 1:6b5c74442c7a | 9 | * Social networks: http://www.fb.com/blynkapp |
vshymanskyy | 1:6b5c74442c7a | 10 | * http://twitter.com/blynk_app |
vshymanskyy | 1:6b5c74442c7a | 11 | * |
vshymanskyy | 1:6b5c74442c7a | 12 | * Blynk library is licensed under MIT license |
vshymanskyy | 1:6b5c74442c7a | 13 | * This example code is in public domain. |
vshymanskyy | 1:6b5c74442c7a | 14 | * |
vshymanskyy | 1:6b5c74442c7a | 15 | ************************************************************** |
vshymanskyy | 1:6b5c74442c7a | 16 | * |
vshymanskyy | 1:6b5c74442c7a | 17 | * This example shows how to use RedBearLab BLE Nano |
vshymanskyy | 1:6b5c74442c7a | 18 | * to connect your project to Blynk. |
vshymanskyy | 1:6b5c74442c7a | 19 | * |
vshymanskyy | 1:6b5c74442c7a | 20 | * NOTE: BLE support is in beta! |
vshymanskyy | 1:6b5c74442c7a | 21 | * |
vshymanskyy | 1:6b5c74442c7a | 22 | **************************************************************/ |
vshymanskyy | 0:cf8e8a71c9c3 | 23 | |
vshymanskyy | 0:cf8e8a71c9c3 | 24 | #define BLYNK_DEBUG |
vshymanskyy | 1:6b5c74442c7a | 25 | #define BLYNK_PRINT stdout |
vshymanskyy | 0:cf8e8a71c9c3 | 26 | |
vshymanskyy | 1:6b5c74442c7a | 27 | //#define BLYNK_USE_DIRECT_CONNECT |
vshymanskyy | 0:cf8e8a71c9c3 | 28 | |
vshymanskyy | 1:6b5c74442c7a | 29 | #include <BlynkSimpleRedBearLab_BLE_Nano.h> |
vshymanskyy | 0:cf8e8a71c9c3 | 30 | |
vshymanskyy | 0:cf8e8a71c9c3 | 31 | // You should get Auth Token in the Blynk App. |
vshymanskyy | 0:cf8e8a71c9c3 | 32 | // Go to the Project Settings (nut icon). |
tulanthoar | 2:56696744060e | 33 | char auth[] = "e371ee943c6145a4bcb4fb1a24ee3abe"; |
vshymanskyy | 0:cf8e8a71c9c3 | 34 | |
tulanthoar | 2:56696744060e | 35 | uint8_t device_name[] = "Blynker"; |
vshymanskyy | 1:6b5c74442c7a | 36 | |
vshymanskyy | 1:6b5c74442c7a | 37 | void setup() { |
vshymanskyy | 1:6b5c74442c7a | 38 | ble.init(); |
vshymanskyy | 0:cf8e8a71c9c3 | 39 | |
vshymanskyy | 1:6b5c74442c7a | 40 | ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED); |
vshymanskyy | 1:6b5c74442c7a | 41 | ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME, |
vshymanskyy | 1:6b5c74442c7a | 42 | device_name, sizeof(device_name) - 1); |
vshymanskyy | 1:6b5c74442c7a | 43 | |
vshymanskyy | 1:6b5c74442c7a | 44 | ble.gap().setDeviceName(device_name); |
vshymanskyy | 1:6b5c74442c7a | 45 | ble.gap().setTxPower(4); |
vshymanskyy | 1:6b5c74442c7a | 46 | |
vshymanskyy | 1:6b5c74442c7a | 47 | // Add Blynk service... |
vshymanskyy | 1:6b5c74442c7a | 48 | Blynk.begin(auth); |
vshymanskyy | 0:cf8e8a71c9c3 | 49 | |
vshymanskyy | 1:6b5c74442c7a | 50 | ble.gap().setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); |
vshymanskyy | 1:6b5c74442c7a | 51 | ble.gap().setAdvertisingInterval(Gap::MSEC_TO_GAP_DURATION_UNITS(1000)); |
vshymanskyy | 1:6b5c74442c7a | 52 | ble.gap().setAdvertisingTimeout(0); |
vshymanskyy | 1:6b5c74442c7a | 53 | ble.startAdvertising(); |
vshymanskyy | 0:cf8e8a71c9c3 | 54 | |
vshymanskyy | 1:6b5c74442c7a | 55 | printf("Waiting for connections...\n"); |
vshymanskyy | 0:cf8e8a71c9c3 | 56 | } |
vshymanskyy | 0:cf8e8a71c9c3 | 57 | |
vshymanskyy | 1:6b5c74442c7a | 58 | void loop() { |
vshymanskyy | 1:6b5c74442c7a | 59 | Blynk.run(); |
vshymanskyy | 0:cf8e8a71c9c3 | 60 | } |
vshymanskyy | 0:cf8e8a71c9c3 | 61 | |
vshymanskyy | 1:6b5c74442c7a | 62 | int main(void) { |
vshymanskyy | 0:cf8e8a71c9c3 | 63 | setup(); |
vshymanskyy | 0:cf8e8a71c9c3 | 64 | while(1) { |
vshymanskyy | 0:cf8e8a71c9c3 | 65 | loop(); |
vshymanskyy | 0:cf8e8a71c9c3 | 66 | } |
vshymanskyy | 0:cf8e8a71c9c3 | 67 | } |