Development

Communication / Bluetooth Low Energy:

» BLE 03 Limited scan

This example shows how to make a limited scan with Bluetooth low energy, till find two devices, printing them by USB

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.

Code

/*
 *  ------------------ [BLE_03] - Limited scan ------------------- 
 *
 *  Explanation: This example shows how to make a limited scan with 
 *  Bluetooth low energy, till find two devices, printing them by USB 
 *  
 *
 *  Copyright (C) 2014 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 FOR A PARTICULAR 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 <http://www.gnu.org/licenses/>.
 *
 *  Version:		0.1
 *  Design:		David Gascón
 *  Implementation:	Javier Siscart
 */
#include <WaspBLE.h>

// Auxiliary variable
uint8_t aux = 0;
void setup() 
{  
  USB.println("BLE_03 Example");  

  // 0. Turn BLE module ON
  BLE.ON(SOCKET0);
}

void loop() 
{

  // 1. Limited scan
  USB.println(F("Scan till find 2 devices."));
  BLE.scanNetworkLimited(2);

  // Printing information
  USB.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();

  // 2. Limited scan at desired TX power
  USB.println(F("Scan till find 2 devices at MAX power"));
  BLE.scanNetworkLimited(2, TX_POWER_MAX);

  // Printing information
  USB.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

E#
BLE_03 Example
Scan till find 2 devices.
discovered: 2
Print Last inquiry saved on EEPROM
Scan params: GAP mode=2; scan_interval=75: scan_window=50; scan_duplicate_filtering=1; TXPower=15;
Device 0; 000780789ebf; RSSI:-39; Name:
Device 1; 00078053c1b9; RSSI:-39; Name:
devices printed:2

Scan till find 2 devices at MAX power
discovered: 2
Print Last inquiry saved on EEPROM
Scan params: GAP mode=2; scan_interval=75: scan_window=50; scan_duplicate_filtering=1; TXPower=15;
Device 0; 000780789ebf; RSSI:-39; Name:
Device 1; 00078053c1b9; RSSI:-39; Name:
devices printed:2

Quick Publish: