Compile ble module with typescript. Add globals file to prevent errors.

This commit is contained in:
mmcwilliams 2020-05-19 17:31:55 -04:00
parent b4091bf06b
commit 7d779bc5c9
4 changed files with 16 additions and 15 deletions

View File

@ -164,8 +164,8 @@ class BLE {
this.listeners = {}; this.listeners = {};
log.info('Starting bluetooth service'); log.info('Starting bluetooth service');
getState = bleGetState; getState = bleGetState;
bleno_1.default.on('stateChange', state => { bleno_1.default.on('stateChange', (state) => {
log.info('stateChange', { state: state }); log.info('stateChange', { state });
if (state === 'poweredOn') { if (state === 'poweredOn') {
log.info('Starting advertising', { DEVICE_NAME, DEVICE_ID: process.env.BLENO_DEVICE_NAME }); log.info('Starting advertising', { DEVICE_NAME, DEVICE_ID: process.env.BLENO_DEVICE_NAME });
bleno_1.default.startAdvertising(DEVICE_NAME, [CHAR_ID]); bleno_1.default.startAdvertising(DEVICE_NAME, [CHAR_ID]);
@ -174,7 +174,7 @@ class BLE {
bleno_1.default.stopAdvertising(); bleno_1.default.stopAdvertising();
} }
}); });
bleno_1.default.on('advertisingStart', err => { bleno_1.default.on('advertisingStart', (err) => {
log.info('advertisingStart', { res: (err ? 'error ' + err : 'success') }); log.info('advertisingStart', { res: (err ? 'error ' + err : 'success') });
createChars(this._onWrite.bind(this), this._onRead.bind(this)); createChars(this._onWrite.bind(this), this._onRead.bind(this));
if (!err) { if (!err) {
@ -186,11 +186,11 @@ class BLE {
]); ]);
} }
}); });
bleno_1.default.on('accept', clientAddress => { bleno_1.default.on('accept', (clientAddress) => {
log.info('accept', { clientAddress: clientAddress }); log.info('accept', { clientAddress });
}); });
bleno_1.default.on('disconnect', clientAddress => { bleno_1.default.on('disconnect', (clientAddress) => {
log.info('disconnect', { clientAddress: clientAddress }); log.info('disconnect', { clientAddress });
}); });
this._refreshWifi(); this._refreshWifi();
} }

File diff suppressed because one or more lines are too long

View File

@ -198,8 +198,8 @@ class BLE {
getState = bleGetState getState = bleGetState
bleno.on('stateChange', state => { bleno.on('stateChange', (state : any ) => {
log.info('stateChange', { state : state }) log.info('stateChange', { state })
if (state === 'poweredOn') { if (state === 'poweredOn') {
log.info('Starting advertising', { DEVICE_NAME, DEVICE_ID : process.env.BLENO_DEVICE_NAME }) log.info('Starting advertising', { DEVICE_NAME, DEVICE_ID : process.env.BLENO_DEVICE_NAME })
bleno.startAdvertising(DEVICE_NAME, [CHAR_ID]) bleno.startAdvertising(DEVICE_NAME, [CHAR_ID])
@ -208,7 +208,7 @@ class BLE {
} }
}) })
bleno.on('advertisingStart', err => { bleno.on('advertisingStart', (err : Error) => {
log.info('advertisingStart', { res : (err ? 'error ' + err : 'success') }) log.info('advertisingStart', { res : (err ? 'error ' + err : 'success') })
createChars(this._onWrite.bind(this), this._onRead.bind(this)) createChars(this._onWrite.bind(this), this._onRead.bind(this))
if (!err) { if (!err) {
@ -221,12 +221,12 @@ class BLE {
} }
}) })
bleno.on('accept', clientAddress => { bleno.on('accept', (clientAddress : any) => {
log.info('accept', { clientAddress : clientAddress }) log.info('accept', { clientAddress })
}) })
bleno.on('disconnect', clientAddress => { bleno.on('disconnect', (clientAddress : any) => {
log.info('disconnect', { clientAddress : clientAddress }) log.info('disconnect', { clientAddress })
}) })
this._refreshWifi() this._refreshWifi()

1
src/globals.d.ts vendored Normal file
View File

@ -0,0 +1 @@
declare module 'bleno';