Skip to content

Commit

Permalink
[#394] Add support for configuring BLE scan options 1M/2M/Coded PHY, …
Browse files Browse the repository at this point in the history
…company filter, etc.
  • Loading branch information
TheSomeMan committed Oct 23, 2024
1 parent bbc3a66 commit 7edd440
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 149 deletions.
4 changes: 3 additions & 1 deletion scripts/ruuvi_gw_http_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,11 @@
'coordinates': "",
'scan_coded_phy': False,
'scan_1mbit_phy': True,
'scan_extended_payload': True,
'scan_2mbit_phy': True,
'scan_channel_37': True,
'scan_channel_38': True,
'scan_channel_39': True,
'scan_default': True,
'scan_filter_allow_listed': False,
'scan_filter_list': [
# 'AA:BB:CC:00:00:01',
Expand Down Expand Up @@ -707,6 +708,7 @@ def _do_post_ruuvi_json(self):
print(f'Response: {resp}')
self.wfile.write(resp)
return
print(f'Content: {req_dict}')
lan_auth_type = None
lan_auth_user = None
lan_auth_pass = None
Expand Down
48 changes: 33 additions & 15 deletions src/gw_cfg.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ export class GwCfg {
this.scan.is_default()
}

is_use_ruuvi_scan_with_default_options () {
return this.company_filter.is_default() &&
this.scan.is_default()
}

#parseResponse (data) {
this.info.parse(data)
this.eth.parse(data)
Expand Down Expand Up @@ -185,13 +190,18 @@ export class GwCfg {
}

data.company_use_filtering = this.company_filter.company_use_filtering
data.company_id = this.company_filter.company_id

if (!this.scan.scan_default) {
data.scan_coded_phy = this.scan.scan_coded_phy
data.scan_1mbit_phy = this.scan.scan_1mbit_phy
data.scan_2mbit_phy = this.scan.scan_2mbit_phy
data.scan_channel_37 = this.scan.scan_channel_37
data.scan_channel_38 = this.scan.scan_channel_38
data.scan_channel_39 = this.scan.scan_channel_39
}
data.scan_default = this.scan.scan_default

data.scan_coded_phy = this.scan.scan_coded_phy
data.scan_1mbit_phy = this.scan.scan_1mbit_phy
data.scan_extended_payload = this.scan.scan_extended_payload
data.scan_channel_37 = this.scan.scan_channel_37
data.scan_channel_38 = this.scan.scan_channel_38
data.scan_channel_39 = this.scan.scan_channel_39
data.scan_filter_allow_listed = this.scan.scan_filter_allow_listed
data.scan_filter_list = this.scan.scan_filter_list

Expand All @@ -218,31 +228,39 @@ export class GwCfg {
/**
* @param {Auth} auth
* @param {Boolean} company_use_filtering
* @param {Number} company_id
* @param {Boolean} scan_coded_phy
* @param {Boolean} scan_1mbit_phy
* @param {Boolean} scan_extended_payload
* @param {Boolean} scan_2mbit_phy
* @param {Boolean} scan_channel_37
* @param {Boolean} scan_channel_38
* @param {Boolean} scan_channel_39
* @param {Boolean} scan_default
*/
async saveBluetoothScanningConfig(auth,
company_use_filtering,
company_id,
scan_coded_phy,
scan_1mbit_phy,
scan_extended_payload,
scan_2mbit_phy,
scan_channel_37,
scan_channel_38,
scan_channel_39) {
scan_channel_39,
scan_default) {
let data = {}

data.company_use_filtering = company_use_filtering
data.company_id = company_id

data.scan_coded_phy = scan_coded_phy
data.scan_1mbit_phy = scan_1mbit_phy
data.scan_extended_payload = scan_extended_payload
data.scan_channel_37 = scan_channel_37
data.scan_channel_38 = scan_channel_38
data.scan_channel_39 = scan_channel_39
data.scan_default = scan_default
if (!data.scan_default) {
data.scan_coded_phy = scan_coded_phy
data.scan_1mbit_phy = scan_1mbit_phy
data.scan_2mbit_phy = scan_2mbit_phy
data.scan_channel_37 = scan_channel_37
data.scan_channel_38 = scan_channel_38
data.scan_channel_39 = scan_channel_39
}

return Network.httpEncryptAndPostJson(auth, '/bluetooth_scanning.json', 10000, data)
}
Expand Down
6 changes: 4 additions & 2 deletions src/gw_cfg.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,11 @@ describe('GwCfg', () => {
'company_id': 1177,
'scan_coded_phy': false,
'scan_1mbit_phy': true,
'scan_extended_payload': true,
'scan_2mbit_phy': true,
'scan_channel_37': true,
'scan_channel_38': true,
'scan_channel_39': true,
'scan_default': true,
'scan_filter_allow_listed': false,
'scan_filter_list': [],
'coordinates': '',
Expand Down Expand Up @@ -176,10 +177,11 @@ describe('GwCfg', () => {
'company_id': 1177,
'scan_coded_phy': false,
'scan_1mbit_phy': true,
'scan_extended_payload': true,
'scan_2mbit_phy': true,
'scan_channel_37': true,
'scan_channel_38': true,
'scan_channel_39': true,
'scan_default': true,
'coordinates': '',
'scan_filter_allow_listed': false,
'scan_filter_list': [],
Expand Down
13 changes: 7 additions & 6 deletions src/gw_cfg_scan.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,22 @@ import * as utils from './utils.mjs'
export class GwCfgScan {
scan_coded_phy = null
scan_1mbit_phy = null
scan_extended_payload = null
scan_2mbit_phy = null
scan_channel_37 = null
scan_channel_38 = null
scan_channel_39 = null
scan_default = null
scan_filter_allow_listed = null
scan_filter_list = []

parse (data) {
this.scan_coded_phy = utils.fetchBoolKeyFromData(data, 'scan_coded_phy', true)
this.scan_1mbit_phy = utils.fetchBoolKeyFromData(data, 'scan_1mbit_phy', true)
this.scan_extended_payload = utils.fetchBoolKeyFromData(data, 'scan_extended_payload', true)
this.scan_2mbit_phy = utils.fetchBoolKeyFromData(data, 'scan_2mbit_phy', true)
this.scan_channel_37 = utils.fetchBoolKeyFromData(data, 'scan_channel_37', true)
this.scan_channel_38 = utils.fetchBoolKeyFromData(data, 'scan_channel_38', true)
this.scan_channel_39 = utils.fetchBoolKeyFromData(data, 'scan_channel_39', true)
this.scan_default = utils.fetchBoolKeyFromData(data, 'scan_default', true)
this.scan_filter_allow_listed = utils.fetchBoolKeyFromData(data, 'scan_filter_allow_listed', false, false)
let scan_filter_list = utils.fetchListKeyFromData(data, 'scan_filter_list')
this.scan_filter_list = []
Expand All @@ -38,18 +40,17 @@ export class GwCfgScan {
}

is_default () {
return !this.scan_coded_phy && this.scan_1mbit_phy && this.scan_extended_payload &&
this.scan_channel_37 && this.scan_channel_38 && this.scan_channel_39 &&
this.scan_filter_list.length === 0
return this.scan_default && this.scan_filter_list.length === 0
}

set_default () {
this.scan_coded_phy = false
this.scan_1mbit_phy = true
this.scan_extended_payload = true
this.scan_2mbit_phy = true
this.scan_channel_37 = true
this.scan_channel_38 = true
this.scan_channel_39 = true
this.scan_default = true
this.scan_filter_allow_listed = false
this.scan_filter_list = []
}
Expand Down
Loading

0 comments on commit 7edd440

Please sign in to comment.