General considerations
Last updated
Last updated
This section will describe the Bluetooth module API. The functions which manage Bluetooth module belong to the class WaspBT_Pro, and the object created to use them is defined as BT_Pro. All of them are described below including some examples of use.
WaspBT_Pro.h, WaspBT_Pro.cpp.
*Note: If you are planning to detect a big amount of Bluetooth devices, it is highly recommended to increase RX buffer of Waspmote UART. To do that, go to file wiring_serial.c and change value of RX_BUFFER_SIZE to 1024. More information can be obtained in the Libelium forum.*
To start using Waspmote Bluetooth library, an object from class WaspBT must be created. This object, called BT_Pro, is created inside Waspmote Bluetooth library and it is public to all libraries. It is used through this guide to show how Waspmote Bluetooth library works.
When creating this constructor, all the variables are defined with an initial value by default.
Next tables show all functions and variables contained in class "BT_Pro", including a brief description. In the next section, main functions are described in deep. However, not relevant ones will be ignored.
In the Waspmote Development section you can find complete examples about using this module: http://www.libelium.com/development/waspmote/examples
Private functions:
Public variables are described below. Private variables are not relevant.
When Waspmote is rebooted or it comes up from a hibernate state (battery is disconnected), the application code will start again, creating all the variables and objects from the beginning.
There are some constants predefined in the Bluetooth library. Internal parameters like module baudrate, file names or transmission powers are defined here.
ON()
Turns on Bluetooth module
OFF()
Turns off Bluetooth module
checkActiveConnections()
Checks if there are active connections
createConnection()
Creates a transparent connection with other Bluetooth module using serial port profile
enterCommandMode
()
Enters command mode of Bluetooth module
getNodeID()
Reads Bluetooth Node Identifier
GetOwnMac()
Gets Bluetooth module MAC address
getOwnName()
Gets public name of Bluetooth device
getRSSI()
Returns the Receiver Signal Strength Indication of a link
getTemp()
Reads internal temperature sensor of Bluetooth module
init()
Initializes some parameters of the module
printInquiry();
Prints last inquiry results. Use only for debugging purposes
removeConnection()
Removes a transparent connection
reset()
Resets the module
returnToDataMode()
Switches from command mode to data mode
scanNetwok (time , power)
Normal scan
scanNetwokLimited (Max_DEVICES, power)
Time limited scan
scanDevice (MAC, maxtime, power)
Scans for specific device
scanNetworkName ( time, power)
Scans showing also friendly name
sendData()
Sends data trough a transparent connection with other Bluetooth module using serial port profile
setNodeID(ID)
Saves Bluetooth Node identifier into the EEPROM
setOwnName(publicName)
Sets public name on Bluetooth device module. Maximum length is 20 chars.
sleep()
Turns Bluetooth module into Sleep mode
wakeUp()
Wakes up Bluetooth module from Sleep mode
changeInquiryPower()
Changes Inquiry TX power
createSDFiles()
Creates required files by Bluetooth module into SD card
eraseSDFiles()
Erases files created by Bluetooth module on SD card
getSetDateID()
Reads nodeID and date and stores it
lookForAnswer()
Searches a string in a text
parseBlock()
Parses received data from module
parseNames()
Looks for friendly names and stores them
ReadCommandAnswer()
Reads command answer and saves it
ScanNetworkCancel()
Cancels currently inquiry
sendCommand()
Sends command to Bluetooth module
setInquiryTime()
Sets time to be waiting for inquiry answer
waitInquiryAnswer()
Reads UART while inquiry is being answered
waitScanDeviceAnswer()
Reads UART while inquiry is being answered
uint16_t numberOfDevices
Stores number of discovered devices in last inquiry
char temperature
Stores module temperature
uint32_t numLinesBefore
Stores number of lines of devices file before inquiry
uint32_t numLinesAfter
Stores number of lines of devices file after inquiry
uint8_t commandMode
Variable to know if module is in data or command mode
uint8_t activeConnections
Variable to store number of active connections
BLOCK_MAC_SIZE
Block size used to store MAC address
BLOCK_SIZE
Block size used to parse data
BT_BLUEGIGA_RATE
Default Baudrate of Bluetooth module
BT_NODE_ID_ADDR
EPROM address where node ID is stored.
BT_PW_1
Bluetooth power pin when UART1 is used.
BT_PW_0
Bluetooth power pin when UART0 is used.
COMMAND_SIZE
Reserved bytes for Bluetooth module commands.
DEFAULT_MAX_INQUIRY_RESULTS
Maximum inquiry results defined by internal firmware
ENABLE_DATE_AND_TIME
Uncomment to enable date and time in each device
ENABLE_FRIENDLY_NAME
Uncomment to enable friendly name features
ENDSTRING
File definition. By default “---”
ERRORSD1, ERRORSD2, ERRORSD2
SD card error codes for debugging.
INQFILE
File name where inquiry is stored
INQFILEHEAD
"Discovered devices". Format of inquiry file.
RX_BUFFER
Buffer for received data
TOTAL
File definition. By default “total:”
TX_POWER_0....6
TX power values accepted by module in dBm. 0 is minimum.
TX_POWER_DEFAULT_WT12
By default module is at this TX power
TX_POWER_MAX_WT12
Max TX power. Is equal to TX_POWER_6