Push dev work to master #2

Merged
sixteenmillimeter merged 416 commits from dev into master 2018-07-19 15:29:02 +00:00
5 changed files with 61 additions and 108 deletions
Showing only changes of commit 0272ca21f6 - Show all commits

View File

@ -4,7 +4,7 @@ const restify = require('restify')
const log = require('./lib/log')('main')
const fs = require('fs')
//const ble = require('./lib/blootstrap')
const ble = require('./lib/ble')
const intval = require('./lib/intval')
const PACKAGE = require('./package.json')
@ -38,6 +38,10 @@ function createServer () {
})
}
function bleBindings () {
}
function rDir (req, res, next) {
let dir = true
let set = false

View File

@ -1,14 +1,14 @@
'use strict'
const ipc = require('node-ipc')
const os = require('os')
const bleno = require('bleno')
const util = require('util')
const log = require('../log')('ble')
const wifi = require('../../lib/wifi')
const BLENO_DEVICE_NAME = process.env.BLENO_DEVICE_NAME || 'my_project'
const DEVICE_ID = process.env.DEVICE_ID || 'my_project_id'
const BLENO_DEVICE_NAME = process.env.BLENO_DEVICE_NAME || 'intval3'
const DEVICE_ID = process.env.DEVICE_ID || 'intval3'
const SERVICE_ID = process.env.SERVICE_ID || 'blootstrap'
const CHAR_ID = process.env.CHAR_ID || 'blootstrapchar'
const WIFI_ID = process.env.WIFI_ID || 'blootstrapwifi'
@ -19,10 +19,6 @@ let currentWifi = 'disconnected'
const chars = []
ipc.config.id = 'blootstrap_ble'
ipc.config.retry = 1500
ipc.config.rawBuffer = true
ipc.config.encoding = 'hex'
function createChar(name, uuid, prop, write, read) {
function characteristic () {
@ -112,9 +108,17 @@ function spoofMac () {
return MACTMP
}
console.log('Starting bluetooth service')
bleno.on('stateChange', state => {
function capitalize (s) {
return s[0].toUpperCase() + s.slice(1)
}
/** Class representing the bluetooth interface */
class BLE {
constructor () {
log.info('Starting bluetooth service')
bleno.on('stateChange', state => {
const BLE_ID = `${DEVICE_ID}_${MAC}`
console.log(`on -> stateChange: ${state}`)
if (state === 'poweredOn') {
@ -123,9 +127,9 @@ bleno.on('stateChange', state => {
} else {
bleno.stopAdvertising()
}
})
})
bleno.on('advertisingStart', err => {
bleno.on('advertisingStart', err => {
console.log('on -> advertisingStart: ' + (err ? 'error ' + err : 'success'))
createChars()
if (!err) {
@ -136,26 +140,25 @@ bleno.on('advertisingStart', err => {
})
])
}
})
})
bleno.on('accept', clientAddress => {
bleno.on('accept', clientAddress => {
console.log(`${clientAddress} accepted`)
})
})
bleno.on('disconnect', clientAddress => {
bleno.on('disconnect', clientAddress => {
console.log(`${clientAddress} disconnected`)
})
})
}
/**
* Binds functions to events that are triggered by BLE messages
*
* @param {string} eventName Name of the event to to bind
* @param {function} callback Invoked when the event is triggered
*/
on (eventName, callback) {
this[`_on${capitalize(eventName)}`] = callback
}
}
ipc.serve(() => {
ipc.server.on('connect', socket => {
ipc.log('Client connected to socket')
})
ipc.server.on('disconnect', () => {
ipc.log('Client disconnected from socket')
})
ipc.server.on('data', (data, socket) => {
ipc.server.emit(socket, JSON.stringify({}))
})
})
ipc.server.start()
module.exports = new BLE()

View File

@ -1,48 +0,0 @@
'use strict'
const ipc = require('node-ipc')
const log = require('../log')('ble')
function capitalize (s) {
return s[0].toUpperCase() + s.slice(1)
}
/** Class representing the bluetooth interface */
class Blootstrap {
constructor () {
this._onData = () => {}
ipc.config.maxRetries = 0
ipc.connectTo('blootstrap_ble', () => {
ipc.of.blootstrap_ble.on('connect', () => {
log.info('connect', `Connected to the blootstrap_ble service`)
})
ipc.of.blootstrap_ble.on('data', data => {
const str = data.toString()
log.info('data', str)
this._onData(str)
})
ipc.of.blootstrap_ble.on('disconnect', () => {
log.info('disconnect', `Disconnected from the blootstrap_ble service`)
})
ipc.of.blootstrap_ble.on('error', (err) => {
if (err.code === 'EACCES') {
log.warn('ble', `Cannot access ipc`)
} else {
log.error('ble', { error : err })
}
})
})
}
/**
* Binds functions to events that are triggered by BLE messages
*
* @param {string} eventName Name of the event to to bind
* @param {function} callback Invoked when the event is triggered
*/
on (eventName, callback) {
this[`_on${capitalize(eventName)}`] = callback
}
}
module.exports = new Blootstrap()

View File

@ -1,9 +1,9 @@
{
"apps" : [
{
"name" : "ble",
"script" : "./services/bluetooth/index.js",
"watch" : false,
"name" : "intval3",
"script" : "./index.js",
"watch" : true,
"env" : {
"BLENO_DEVICE_NAME" : "intval3",
"DEVICE_ID" : "intval3",
@ -12,12 +12,6 @@
"WIFI_ID" : "3fe7d9cf-7bd2-4ff0-97c5-ebe87288c2cc",
"PORT" : 6699
}
},
{
"name" : "intval3",
"script" : "./index.js",
"watch" : false,
"env" : {}
}
]
}