This example shows how to configure scan parameters and makin a scan with them, printing number of discovered devices and scan results stored in EEPROM.
Required Materials
1 x Waspmote
1 x Battery
1 x Bluetooth Low Energy module
1 x Bluetooth module antenna
1 x Expansion board (if socket 1 is used)
1 x SD card
Notes
- Socket 0 is used by default
- EEPROM is used in this example by default.
- Never unplug module while Waspmote is turned ON.
- Bluetooth module antenna should be connected.
- The battery must be connected in ANY example.
- This example can be executed in Waspmote v12 and Waspmote v15
Code
/* * ------------------ [BLE_05] - Configuring a scan ------------------- * * Explanation: This example shows how to configure scan parameters and * making a scan with them, printing number of discovered devices * and scan results stored in EEPROM. * * Copyright (C) 2016 Libelium Comunicaciones Distribuidas S.L. * http://www.libelium.com * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS ARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * Version: 1.0 * Design: David Gascón * Implementation: Javier Siscart */#include<WaspBLE.h>// Auxiliary variableuint8_t aux =0;voidsetup() { USB.println(F("BLE_05 Example")); // 0. Turn BLE module ONBLE.ON(SOCKET0);// 1. Configure a scan with desired parameters// 1.1 Set TX power to maximum BLE.setTXPower(TX_POWER_MAX); if (BLE.errorCode !=0) USB.println(F("TX Fail"));// 1.2 Set GAP Discover mode.BLE.setDiscoverMode(BLE_GAP_BROADCAST);if (BLE.errorCode !=0) USB.println(F("GAP Fail"));// 1.3 set scan interval to 75 and scan window to 50, // and enable active scanningBLE.setScanningParameters(75,50,BLE_ACTIVE_SCANNING);if (BLE.errorCode !=0) USB.println(F("Active scanning not enabled"));// 1.4 enable mac filterBLE.setFiltering(BLE_MAC_FILTER_ENABLED);if (BLE.errorCode !=0) USB.println(F("Mac filter not enabled"));}voidloop() {// 2. Make a scan with desired parametersUSB.println(F("New scan...")); BLE.scanNetwork(5);// Printing informationUSB.print("discovered devices: ");USB.println(BLE.numberOfDevices, DEC);USB.println();USB.println(F("Printing Last inquiry saved on EEPROM:")); aux =BLE.printInquiry();USB.print("devices printed: ");USB.println(aux, DEC);USB.println();}
Output
H#
BLE_05 Example
New scan...
discovered devices: 2
Printing Last inquiry saved on EEPROM:
Scan params: GAP mode=2; scan_interval=75: scan_window=64; scan_duplicate_filtering=1; TXPower=15;
Device 0; 000780789ebf; RSSI:-41; Name:
Device 1; 00078053c1b9; RSSI:-39; Name:
devices printed:2
New scan...
discovered devices: 2
Printing Last inquiry saved on EEPROM:
Scan params: GAP mode=2; scan_interval=75: scan_window=64; scan_duplicate_filtering=1; TXPower=15;
Device 0; 000780789ebf; RSSI:-40; Name:
Device 1; 00078053c1b9; RSSI:-39; Name:
devices printed:2