ApacheCon North America - April 7, 2014
Presented by Don Coleman / @doncoleman
#include <SoftwareSerial.h>
#define RxD 6
#define TxD 7
SoftwareSerial bluetooth(RxD,TxD);
int counter = 0;
void setup() {
Serial.begin(9600);
bluetooth.begin(9600);
Serial.println("Bluetooth Counter\n");
}
void loop() {
Serial.println(counter);
bluetooth.println(counter);
counter++;
delay(1000);
}
$ cordova plugin install \
com.megster.cordova.bluetoothserial
var macAddress = "00:00:AA:BB:CC:DD";
bluetoothSerial.connect(
macAddress,
connected,
disconnected);
bluetoothSerial.write("Hello Arduino");
var onMessage = function(data) {
console.log(data);
};
bluetoothSerial.subscribe("\n",
onMessage,
onFailure);
bluetoothSerial.list(success, failure);
[{
"class": 276,
"id": "10:BF:48:CB:00:00",
"address": "10:BF:48:CB:00:00",
"name": "Nexus 7"
}, {
"class": 7936,
"id": "00:06:66:4D:00:00",
"address": "00:06:66:4D:00:00",
"name": "RN42"
}]
aka Bluetooth Smart
but available hardware has "serial like" services
bluetoothSerial.list(success, failure);
No pairing, finds devices
[{
"id": "CC410A23-2865-F03E-FC6A-4C17E858E11E",
"uuid": "CC410A23-2865-F03E-FC6A-4C17E858E11E",
"name": "Biscuit",
"rssi": -68
},{
"id": "ED7127D4-593B-490E-9DA7-959FE78EC603",
"uuid": "ED7127D4-593B-490E-9DA7-959FE78EC603",
"name": "UART",
"rssi": -47
}]
(except for BLE only handles small chunks of data)
onColorChange: function (evt) {
var c = app.getColor();
rgbText.innerText = c; // 0,0,255
previewColor.style.backgroundColor =
"rgb(" + c + ")";
app.sendToArduino(c);
},
sendToArduino: function(c) {
bluetoothSerial.write("c" + c + "\n");
},
void loop() {
if (bluetooth.find("c")) {
red = bluetooth.parseInt();
green = bluetooth.parseInt();
blue = bluetooth.parseInt();
showColor(red, green, blue);
}
}
rfduino.discover(seconds, success, failure);
{
"name": "RFduino",
"uuid": "BD922605-1B07-4D55-8D09-B66653E51BBA",
"advertising": "echo",
"rssi": -79
}
rfduino.connect(uuid, success, failure);
rfduino.write("hello", success, failure);
rfduino.onData(success, failure);
var onData = function(arrayBuffer) {
var a = new Float32Array(arrayBuffer);
celsius = a[0];
fahrenheit = celsius * 1.8 + 32;
}
Tomorrow, Tuesday April 8, 2014
10:30am - 5:30pm
McCourt room at ApacheCon
Don Coleman
Connecting Arduino & Phones with Bluetooth & Cordova by Don Coleman
is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Based on a work at https://github.com/don/.../2014-04-07-apachecon-bluetooth.