The iOS app is split into separate Javascript modules for charting, audio, bluetooth, and sensor readings. Some of these might not be useful for your specific needs, but they are a good starting point for hardware interaction over BLE.
├── README.md
├── arduino_ble
│ └── arduino_ble.ino
├── config.xml
├── hooks
│ └── README.md
├── install.sh
└── www
├── css
│ └── index.css
├── index.html
└── js
├── audio.js
├── chart.js
├── d3.js
├── index.js
└── reading.js
5 directories, 12 files
If you need to modify any of the files in the www folder, you will need to run cordova build after every change, and re-upload the app to your device with XCode.
The main BLE connection and data parsing portion of the code can be found in www/js/index.js.
proto.processData = function(data) {
past_low = this.low_battery;
data = data.split(',');
this.yaw.update(data[0]);
this.roll.update(parseFloat(data[2]) + 180);
this.low_battery = parseInt(data[3]) < 3300 ? true : false;
if(this.low_battery && !past_low)
navigator.notification.alert('The Bluefruit\'s battery is low', null, 'Warning');
this.update();
};
You can see that the data parsed out here is sent in the CSV format from the main loop in the arduino_ble.ino sketch.
ble.print("AT+BLEUARTTX=");
ble.print(event.orientation.x, 1);
ble.print(",");
ble.print(event.orientation.y, 1);
ble.print(",");
ble.print(event.orientation.z, 1);
ble.print(",");
ble.print(battery, DEC);
ble.println("|");
You can modify this portion of the sketch to send data from any sensor to iOS.
Resources
You may find the following resources helpful when developing or modifying a BLE Cordova Application.
- Cordova Documentation
- Bluetooth Serial Plugin
- Phonegap Documentation - Phonegap is based on Cordova, so a large portion of the documenatation, tutorials and plugins apply to both Cordova and Phonegap.
- Debugging in Phonegap
- BNO055 Guide
- Bluefruit LE UART Friend Guide
Page last edited June 30, 2015
Text editor powered by tinymce.