Introduction
A typical sensor device integrated with a SmartMesh IP mote will need to be configured in some way while deployed in the field. Since most of these devices are designed for extremely long battery life, they often do not have a user interface, which limits the options for configuring to the device.
By adding BLE capability to the sensor device, configuration can be accomplished with a cell phone that supports BLE, such as an iPhone. This example shows how BLE connectivity can be easily added to the device with a direct connection to the SmartMesh IP mote.
Description
This sample application showcases using the OCSDK to interface the mote to a Nordic Semiconductor nrf8001 BLE chip. We chose the nrf8001 because it was one of the few BLE chips available that supported an SPI slave interface. The OCSDK stack currently only supports being an SPI master.
For the purpose of this demo, two software components are needed, namely an iPhone application for the user interface and a mote application running on the SmartMesh IP device to receive commands from the BLE device. Adafruit provides an iOS demo application (the BlueFruit LE Connect iOS app) that connects to the nrf8001 and supports the sending and receiving of short text strings. The mote sample application created here implements a get and set network ID command, a "join" command, a "reset" command. Note that any number of additional commands or security for the BLE connection can be implemented: this small subset was selected to keep the example simple.
The nrf8001 uses an SPI-like interface they call ACI. Transactions are asynchronous - the master (the LTC5800) sends a command, and the nrf8001 uses the RDYn line to indicate that a response is available to be retrieved by the master. Incoming BLE data also is signaled by the nrf8001 RDYn line.
Since transactions are asynchronous, it is possible to send a command while receiving incoming data or a response to a previous command. The application could handle this by always transferring a maximum (32-byte) SPI buffer for each master transaction, but the mote SPI bus allows for more flexibility than that. Rather than using one of the built-in slave-select lines, the application uses an output line (S_MOSI) to stop the SPI transfer after receiving the incoming header. It decides which packet (incoming or outgoing) is longer, and only clocks out the needed bytes to send in each direction.
Hardware Connection
LTC5800 pin | Direction (from LTC5800) | nrf8001 pin | Notes |
---|---|---|---|
M_SCK | OUT (SPI) | SCK | SPI Master clock |
M_MISO | IN (SPI) | MISO | SPI Master input |
M_MOSI | OUT (SPI) | MOSI | SPI Master output |
S_MOSI | OUT | REQn | Used in place of slave select (active low) |
DP2 | IN | RDYn | Signals that the nrf8001 is ready to transfer asynchronous data (active low) |
NC | ACT | No connect | |
PWM0 | OUT | RSTn | nrf8001 reset (active low) |
NC | 3Vo | No connect | |
GND | GND | Ground | |
VSUPPLY | VIN | 3.6 volts |
Mote CLI commands
The sample app adds two CLI commands to the basic set provided by the stack:
send -
once connected, this command allows you to send text strings (<= 20 bytes) to the iOS Connect application. It prints an error if there is no BLE connectionreset -
resets the mote (and the nrf8001 chip)
Running the Demo
Connect to the mote CLI (9600 baud, 8 data bits, 1 stop bit, no parity) to view mote prints.
When the mote boots, you will see the following screen (assuming the nrf8001 is properly connected):
nrf8001 app, ver 1.1.0.8 SmartMeshIP stack, ver 1.3.0.28 Setting up BLE chip... Ready for remote connection...
At this point you can use the Adafruit BlueFruit LE Connect iOS app to connect to the nrf8001:
Select the UART connect button. This will bring up a menu of interfaces - select the UART for the connection mode. Once connected, he mote CLI will show that a peer has connected.
Connected to peer
At this point, the BlueFruit LE Connect app will display a text window for entering commands:
The following remote commands are available:
getnetid
-
gets the current netid setting from the motegetstatus
- gets the current mote status (idle, joining, operational, or disconnected)join -
causes the mote to begin searching for the network with the currently configured netidreset -
resets the mote, which also resets the BLE chip. BlueFruit LE Connect will tell you that the nrf8001 has disconnectedsetnetid <netid> -
sets the netid on the mote
The mote will print out messages for each command received via the nrf8001, e.g.
Data received = getnetid Remote command: getnetid, returning netid = 293 Data received = setnetid 295 Changing network ID to 295 Data received = join Joining... 179017 : Joining 180764 : Connected 189045 : Active Data received = reset Resetting...
Source Code
The source code has been tested with release 1.1.07 of the On-chip SDK. Utility files from Nordic Semiconductor are subject to their licensing terms. All other files subject to the OCSDK licensing terms.