Last active
August 29, 2015 14:22
-
-
Save cgreening/b460b52c0390bb0834f6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <head> | |
| </head> | |
| <body> | |
| <script src='https://code.jquery.com/jquery-2.1.3.min.js'></script> | |
| <script src='https://www.nodule.io/js/nodule.151851370efa27253700.js'></script> | |
| <script language='javascript'> | |
| console.log('Using nodule version', nodule.version); | |
| // connect to nodule | |
| nodule.connect('wss://app.nodule.io', 'API_ACCESS_TOKEN').then(function(nodule) { | |
| console.log('Connected to the nodule server'); | |
| nodule.on('centralManagerAdded', function(newCentralManager) { | |
| console.log('Got a new remote central manager', newCentralManager.deviceName); | |
| }); | |
| nodule.on('centralManagerRemoved', function(removedCentralManager) { | |
| console.log('Central manager removed', removedCentralManager.deviceName); | |
| }); | |
| nodule.on('scan', function(peripherals) { | |
| nodule.stopScanning(); | |
| console.log('Found peripheral', peripherals[0].name); | |
| peripherals[0].connect().then(function(profile) { | |
| console.log(profile); | |
| var humid_srv = profile.services['F000AA20-0451-4000-B000-000000000000']; | |
| var humid_data = humid_srv.characteristics['F000AA21-0451-4000-B000-000000000000']; | |
| var humid_conf = humid_srv.characteristics['F000AA22-0451-4000-B000-000000000000']; | |
| // switch on the humidity sensor | |
| humid_conf.writeUint8(1); | |
| // start notifications from the humidity sensor | |
| humid_data.setNotifyState(true); | |
| // show the values that come back | |
| humid_data.on('read', function(value) { | |
| console.log('New value', value); | |
| }); | |
| }, function(error) { | |
| console.log(error); | |
| }); | |
| }); | |
| // start scanning for the TI sensor tag | |
| nodule.scanForPeripherals(/.*Sensor.*/); | |
| }, function(error) { | |
| console.log('Connection failed'); | |
| }); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment