BLE features are working, minus the wifi feature. Good work today.

This commit is contained in:
mmcwilliams 2017-12-13 18:40:14 -05:00
parent 57efee6d7f
commit 22d497b464
6 changed files with 48 additions and 12 deletions

View File

@ -70,6 +70,8 @@
<select id="bluetooth"> <select id="bluetooth">
<option>N/A</option> <option>N/A</option>
</select> </select>
<button id="disconnect" onclick="mobile.ble.disconnect();">DISCONNECT</button>
<button id="scan" class="active" onclick="mobile.ble.scan();">SCAN FOR DEVICE</button>
</div> </div>
<div class="ble"> <div class="ble">
<h2>WIFI</h2> <h2>WIFI</h2>
@ -79,6 +81,7 @@
<div> <div>
<input type="password" id="password" placeholder="Wifi Password" /> <input type="password" id="password" placeholder="Wifi Password" />
</div> </div>
<button id="wifi" onclick="alert('WIFI');">CONNECT</button>
</div> </div>
</div> </div>
<div id="mscript" class="page"> <div id="mscript" class="page">

View File

@ -37,7 +37,7 @@ html,body,button,h2,label,input{
} }
body{ body{
padding-top: 15px; padding-top: 35px;
} }
.page{ .page{
padding: 5px 10% 0 10%; padding: 5px 10% 0 10%;
@ -142,7 +142,7 @@ button{
border-radius: 5px; border-radius: 5px;
color: #fff; color: #fff;
font-size: 18px; font-size: 18px;
background: transparent; background: #363636;
-webkit-appearance: none; -webkit-appearance: none;
box-shadow: none; box-shadow: none;
outline: none; outline: none;
@ -274,3 +274,11 @@ footer > div.selected{
#spinner{ #spinner{
margin-top: 200px; margin-top: 200px;
} }
#disconnect,#scan{
display: none;
}
#disconnect.active,
#scan.active{
display: block;
}

View File

@ -19,15 +19,15 @@ mobile.ble.scan = function () {
mobile.ble.devices = []; mobile.ble.devices = [];
setTimeout(() => { setTimeout(() => {
if (!mobile.ble.connected) { if (!mobile.ble.connected) {
ble.stopScan(() => {}, mobile.ble.onError);
spinnerHide(); spinnerHide();
alert('No INTVAL devices found.'); alert('No INTVAL devices found.');
settingsPage();
} }
}, 5000) }, 5000)
}; };
mobile.ble.onDiscover = function (device) { mobile.ble.onDiscover = function (device) {
if (device && device.name && device.name === 'intval3') { if (device && device.name && device.name.indexOf('intval3') !== -1) {
console.log('BLE - Discovered INTVAL'); console.log('BLE - Discovered INTVAL');
console.dir(device); console.dir(device);
mobile.ble.devices.push(device); mobile.ble.devices.push(device);
@ -47,19 +47,36 @@ mobile.ble.connect = function (device) {
}; };
mobile.ble.onConnect = function (peripheral, device) { mobile.ble.onConnect = function (peripheral, device) {
const elem = document.getElementById('bluetooth')
const option = document.createElement('option')
const disconnect = document.getElementById('disconnect');
const scan = document.getElementById('scan');
spinnerHide(); spinnerHide();
ble.stopScan(() => {}, moble.ble.onError);
console.log(`BLE - Connected to ${device.id}`); console.log(`BLE - Connected to ${device.id}`);
console.log(peripheral); console.log(peripheral);
console.dir(device); console.dir(device);
mobile.ble.device = device; mobile.ble.device = device;
mobile.ble.connected = true; mobile.ble.connected = true;
elem.innerHTML = '';
option.text = device.name;
option.value = device.id;
elem.add(option);
disconnect.classList.add('active');
scan.classList.remove('active');
getState(); getState();
}; };
mobile.ble.disconnect = function () { mobile.ble.disconnect = function () {
let device const elem = document.getElementById('bluetooth');
const option = document.createElement('option');
const disconnect = document.getElementById('disconnect');
const scan = document.getElementById('scan');
let device;
if (!mobile.ble.connected) { if (!mobile.ble.connected) {
console.warn('Not connected to any device') console.warn('Not connected to any device')
return false return false
@ -67,6 +84,13 @@ mobile.ble.disconnect = function () {
device = mobile.ble.device device = mobile.ble.device
console.log(`BLE - Disconnecting from ${device.id}`) console.log(`BLE - Disconnecting from ${device.id}`)
ble.disconnect(device.id, mobile.ble.onDisconnect, mobile.ble.onDisconnect); ble.disconnect(device.id, mobile.ble.onDisconnect, mobile.ble.onDisconnect);
elem.innerHTML = '';
option.text = 'N/A';
elem.add(option);
disconnect.classList.remove('active');
scan.classList.add('active');
}; };
mobile.ble.onDisconnect = function (res) { mobile.ble.onDisconnect = function (res) {

View File

@ -314,10 +314,10 @@ function bFrame (obj, cb) {
} }
} }
log.info('frame', { method : 'ble', dir : dir, exposure : exposure }) log.info('frame', { method : 'ble', dir : dir, exposure : exposure })
/*intval.frame(dir, exposure, (len) => { intval.frame(dir, exposure, (len) => {
return cb() return cb()
})*/ })
setTimeout(cb, exposure === 0 ? 630 : exposure) //setTimeout(cb, exposure === 0 ? 630 : exposure)
} }
function bDir (obj, cb) { function bDir (obj, cb) {

View File

@ -9,13 +9,14 @@ const os = require('os')
const log = require('../log')('ble') const log = require('../log')('ble')
const wifi = require('../wifi') const wifi = require('../wifi')
const DEVICE_NAME = process.env.DEVICE_ID || 'intval3' const DEVICE_NAME = process.env.DEVICE_NAME || 'intval3'
const SERVICE_ID = process.env.SERVICE_ID || 'intval3_ble' const SERVICE_ID = process.env.SERVICE_ID || 'intval3_ble'
const CHAR_ID = process.env.CHAR_ID || 'intval3char' const CHAR_ID = process.env.CHAR_ID || 'intval3char'
const WIFI_ID = process.env.WIFI_ID || 'wifichar' const WIFI_ID = process.env.WIFI_ID || 'wifichar'
const NETWORK = os.networkInterfaces() const NETWORK = os.networkInterfaces()
const MAC = getMac() || spoofMac() const MAC = getMac() || spoofMac()
//Give the device a unique device name, needs to be in env
process.env.BLENO_DEVICE_NAME += '_' + MAC process.env.BLENO_DEVICE_NAME += '_' + MAC
const bleno = require('bleno') const bleno = require('bleno')

View File

@ -6,7 +6,7 @@
"watch" : false, "watch" : false,
"env" : { "env" : {
"BLENO_DEVICE_NAME" : "intval3", "BLENO_DEVICE_NAME" : "intval3",
"DEVICE_ID" : "intval3", "DEVICE_NAME" : "intval3",
"SERVICE_ID" : "149582bd-d49d-4b5c-acd1-1ae503d09e7a", "SERVICE_ID" : "149582bd-d49d-4b5c-acd1-1ae503d09e7a",
"CHAR_ID" : "47bf69fb-f62f-4ef8-9be8-eb727a54fae4", "CHAR_ID" : "47bf69fb-f62f-4ef8-9be8-eb727a54fae4",
"WIFI_ID" : "3fe7d9cf-7bd2-4ff0-97c5-ebe87288c2cc", "WIFI_ID" : "3fe7d9cf-7bd2-4ff0-97c5-ebe87288c2cc",