Skip to content

Instantly share code, notes, and snippets.

@don
Created February 17, 2016 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save don/a8fb0b9b11a4393e4b9b to your computer and use it in GitHub Desktop.
Save don/a8fb0b9b11a4393e4b9b to your computer and use it in GitHub Desktop.
BluetoothSerial counter showing count and raw data
var macAddress = "00:13:EF:00:08:8B";
var app = {
initialize: function() {
this.bindEvents();
},
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
onDeviceReady: function() {
bluetoothSerial.connect(macAddress, app.onConnect, app.onDisconnect);
},
onConnect: function() {
bluetoothSerial.subscribe("\n", app.onMessage, app.subscribeFailed);
bluetoothSerial.subscribeRawData(app.onRawData, app.subscribeFailed);
statusDiv.innerHTML="Connected to " + macAddress + ".";
},
onDisconnect: function() {
alert("Disconnected");
statusDiv.innerHTML="Disconnected.";
},
onMessage: function(data) {
counter.innerHTML = data;
},
onRawData: function(data) {
rawDataDiv.innerHTML = new Uint8Array(data);
},
subscribeFailed: function() {
alert("subscribe failed");
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment