From 8b1437ce6467d95765330fb8e12cbf65b59bcaa6 Mon Sep 17 00:00:00 2001 From: Lawrence Kincheloe Date: Thu, 16 Jun 2022 18:04:02 -0500 Subject: [PATCH 1/4] Revert "initial inclusiong of a custom manifest for twig modules" This reverts commit 496e812a20dbaa68b4f8af7baf65d88e8d46f3f7. --- improv-wifi-mod/manifest.json | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/improv-wifi-mod/manifest.json b/improv-wifi-mod/manifest.json index 437b65d..02146bc 100644 --- a/improv-wifi-mod/manifest.json +++ b/improv-wifi-mod/manifest.json @@ -1,40 +1,18 @@ { - "build": { - "SDKCONFIGPATH": "./sdkconfig", - "PARTITIONS_FILE": "./partitions.csv" - }, "include": [ "$(MODDABLE)/examples/manifest_base.json", "$(MODDABLE)/examples/manifest_net.json", "$(MODDABLE)/modules/network/ble/manifest_server.json" ], "preload": [ - "improv-wifi-mod", + "improv-wifi-mod", "btutils", - "gap", + "gap", "./bleservices/*" - ], - "platforms": { - "esp32": { - "defines": { - "i2c": { - "sda_pin": 21, - "scl_pin": 22 - }, - }, - "modules": { - "*": [ - "$(MODULES)/drivers/neopixel/esp32/*" - ] - } - }, - "...": { - "error": "platform unsupported" - } - }, + ], "modules": { "*": [ "./*" ] } - } + } \ No newline at end of file From 92ed223d271fe792ba92499b72991512fc367b08 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 26 Nov 2022 13:30:34 -0600 Subject: [PATCH 2/4] Updated per redaphids updates --- src/improv-wifi-mod.ts | 39 +++++++++++++-------------------------- src/improv.json | 4 ++-- 2 files changed, 15 insertions(+), 28 deletions(-) diff --git a/src/improv-wifi-mod.ts b/src/improv-wifi-mod.ts index 621acaa..693cc20 100644 --- a/src/improv-wifi-mod.ts +++ b/src/improv-wifi-mod.ts @@ -1,6 +1,6 @@ import BLEServer from "bleserver"; import GAP from 'gap' -import {uuid} from "btutils"; +import { uuid } from "btutils"; import BLEExports from './consts' const StateCodes = BLEExports.StateCodes @@ -29,26 +29,10 @@ export default class ImprovWifi extends BLEServer { startImprov() { let advertisingData = { flags: GAP.ADFlag.LE_GENERAL_DISCOVERABLE_MODE, + completeUUID128List: [uuid `00467768-6228-2272-4663-277478268000`], completeName: this.deviceName, - shortName:this.deviceName, - serviceDataUUID128: [uuid`00467768-6228-2272-4663-277478268000`], - completeUUID128List: [ - uuid`00467768-6228-2272-4663-277478268000`, - uuid`00467768-6228-2272-4663-277478268001`, - uuid`00467768-6228-2272-4663-277478268002`, - uuid`00467768-6228-2272-4663-277478268003`, - uuid`00467768-6228-2272-4663-277478268004`, - uuid`00467768-6228-2272-4663-277478268005` - ], - solicitationUUID128List: [ - uuid`00467768-6228-2272-4663-277478268000`, - uuid`00467768-6228-2272-4663-277478268001`, - uuid`00467768-6228-2272-4663-277478268002`, - uuid`00467768-6228-2272-4663-277478268003`, - uuid`00467768-6228-2272-4663-277478268004`, - uuid`00467768-6228-2272-4663-277478268005` - ] - } + shortName: this.deviceName, + }; this.startAdvertising({ advertisingData }); } @@ -65,13 +49,16 @@ export default class ImprovWifi extends BLEServer { } onCharacteristicRead(characteristic: Characteristic) { - if(characteristic.name === "STATE") { - return this.state - } - - if(characteristic.name === "ERROR") { + switch(characteristic.name){ + case "ERROR": + return this.error; + case "STATE": + case "RPC_RESULT": + return this.state; + default: + trace(`I have no idea what ${characteristic.name} is supposed to be`) return this.error - } + } } onConnected() { diff --git a/src/improv.json b/src/improv.json index 92ed17b..fe304f6 100644 --- a/src/improv.json +++ b/src/improv.json @@ -21,11 +21,11 @@ "type": "Uint8Array", "maxBytes": 20, "permissions": "write", - "properties": "write" + "properties": "write,writeNoResponse" }, "RPC_RESULT": { "uuid": "00467768-6228-2272-4663-277478268004", - "type": "Uint8Array", + "type": "Uint8", "maxBytes": 20, "permissions": "read", "properties": "notify" From 571d304e2fadc2bcc2eac0ad853afb52ce94eda8 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 26 Nov 2022 13:31:58 -0600 Subject: [PATCH 3/4] Updated build --- README.md | 4 ++++ improv-wifi-mod/bleservices/improv.json | 4 ++-- improv-wifi-mod/improv-wifi-mod.js | 32 ++++++++----------------- 3 files changed, 16 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index b00e134..542e8d7 100644 --- a/README.md +++ b/README.md @@ -40,3 +40,7 @@ function someHandleCredsFunction ({ ssid, password }) { } ``` + + +### Contributions +@Redaphid and @Loqwai helped debug significant issues/errors with this package, related to improperly advertising data and flags inside the repository: https://github.com/loqwai/juniper-gardens-twig-debug. Thank you both! \ No newline at end of file diff --git a/improv-wifi-mod/bleservices/improv.json b/improv-wifi-mod/bleservices/improv.json index 92ed17b..fe304f6 100644 --- a/improv-wifi-mod/bleservices/improv.json +++ b/improv-wifi-mod/bleservices/improv.json @@ -21,11 +21,11 @@ "type": "Uint8Array", "maxBytes": 20, "permissions": "write", - "properties": "write" + "properties": "write,writeNoResponse" }, "RPC_RESULT": { "uuid": "00467768-6228-2272-4663-277478268004", - "type": "Uint8Array", + "type": "Uint8", "maxBytes": 20, "permissions": "read", "properties": "notify" diff --git a/improv-wifi-mod/improv-wifi-mod.js b/improv-wifi-mod/improv-wifi-mod.js index 309dc67..02b8964 100644 --- a/improv-wifi-mod/improv-wifi-mod.js +++ b/improv-wifi-mod/improv-wifi-mod.js @@ -25,25 +25,9 @@ export default class ImprovWifi extends BLEServer { startImprov() { let advertisingData = { flags: GAP.ADFlag.LE_GENERAL_DISCOVERABLE_MODE, + completeUUID128List: [uuid `00467768-6228-2272-4663-277478268000`], completeName: this.deviceName, shortName: this.deviceName, - serviceDataUUID128: [uuid `00467768-6228-2272-4663-277478268000`], - completeUUID128List: [ - uuid `00467768-6228-2272-4663-277478268000`, - uuid `00467768-6228-2272-4663-277478268001`, - uuid `00467768-6228-2272-4663-277478268002`, - uuid `00467768-6228-2272-4663-277478268003`, - uuid `00467768-6228-2272-4663-277478268004`, - uuid `00467768-6228-2272-4663-277478268005` - ], - solicitationUUID128List: [ - uuid `00467768-6228-2272-4663-277478268000`, - uuid `00467768-6228-2272-4663-277478268001`, - uuid `00467768-6228-2272-4663-277478268002`, - uuid `00467768-6228-2272-4663-277478268003`, - uuid `00467768-6228-2272-4663-277478268004`, - uuid `00467768-6228-2272-4663-277478268005` - ] }; this.startAdvertising({ advertisingData }); } @@ -58,11 +42,15 @@ export default class ImprovWifi extends BLEServer { this.startImprov(); } onCharacteristicRead(characteristic) { - if (characteristic.name === "STATE") { - return this.state; - } - if (characteristic.name === "ERROR") { - return this.error; + switch (characteristic.name) { + case "ERROR": + return this.error; + case "STATE": + case "RPC_RESULT": + return this.state; + default: + trace(`I have no idea what ${characteristic.name} is supposed to be`); + return this.error; } } onConnected() { From 7f2da1c11dec878c7ffb7127c884152bd09fb4ec Mon Sep 17 00:00:00 2001 From: redaphid Date: Mon, 5 Dec 2022 12:20:44 -1000 Subject: [PATCH 4/4] I believe this is the fix we're looking for :) --- improv-wifi-mod/bleservices/improv.json | 2 +- improv-wifi-mod/improv-wifi-mod.js | 37 +++++++++++++++++++------ 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/improv-wifi-mod/bleservices/improv.json b/improv-wifi-mod/bleservices/improv.json index fe304f6..00ea3f1 100644 --- a/improv-wifi-mod/bleservices/improv.json +++ b/improv-wifi-mod/bleservices/improv.json @@ -40,4 +40,4 @@ } } } -} \ No newline at end of file +} diff --git a/improv-wifi-mod/improv-wifi-mod.js b/improv-wifi-mod/improv-wifi-mod.js index 02b8964..752ab04 100644 --- a/improv-wifi-mod/improv-wifi-mod.js +++ b/improv-wifi-mod/improv-wifi-mod.js @@ -5,6 +5,8 @@ import BLEExports from './consts'; const StateCodes = BLEExports.StateCodes; const ErrorCodes = BLEExports.ErrorCodes; const Commands = BLEExports.Commands; + +// FYI class definition for BLEServer can be found @ /modules/network/ble/bleserver.js export default class ImprovWifi extends BLEServer { deviceName; ssid; @@ -23,6 +25,7 @@ export default class ImprovWifi extends BLEServer { this.onCredentialsRecieved = onCredentialsRecieved; } startImprov() { + trace("Starting Improv\n"); let advertisingData = { flags: GAP.ADFlag.LE_GENERAL_DISCOVERABLE_MODE, completeUUID128List: [uuid `00467768-6228-2272-4663-277478268000`], @@ -32,6 +35,7 @@ export default class ImprovWifi extends BLEServer { this.startAdvertising({ advertisingData }); } onDisconnected() { + trace("Disconnected\n"); this.state = StateCodes.STATE_AUTHORIZED; this.error = ErrorCodes.ERROR_NONE; this.errorCharacteristic = null; @@ -39,10 +43,12 @@ export default class ImprovWifi extends BLEServer { this.startImprov(); } onReady() { + trace("Ready\n"); this.startImprov(); } onCharacteristicRead(characteristic) { - switch (characteristic.name) { + trace(`Read: ${JSON.stringify(characteristic)}\n`); + switch(characteristic.name){ case "ERROR": return this.error; case "STATE": @@ -50,14 +56,16 @@ export default class ImprovWifi extends BLEServer { return this.state; default: trace(`I have no idea what ${characteristic.name} is supposed to be`); - return this.error; + return this.error } } onConnected() { + trace("Connected\n"); this.state = StateCodes.STATE_AUTHORIZED; this.error = ErrorCodes.ERROR_NONE; } onCharacteristicNotifyDisabled(characteristic) { + trace('onCharacteristicNotifyDisabled\n'); switch (characteristic.name) { case 'STATE': this.stateCharacteristic = null; @@ -77,6 +85,7 @@ export default class ImprovWifi extends BLEServer { } } onCharacteristicNotifyEnabled(characteristic) { + trace(`onCharacteristicNotifyEnabled: characteristic: ${characteristic.name} \n`); this.notify = characteristic; switch (characteristic.name) { case 'STATE': @@ -102,11 +111,13 @@ export default class ImprovWifi extends BLEServer { } } onCharacteristicWritten(characteristic, value) { + trace(`Written: ${characteristic.name}, in state ${characteristic.state}, with value ${value}, value[0] is ${value?.[0]}, which is a type ${typeof value?.[0]} \n`); // this is where we go and update state again if necessary switch (characteristic.name) { case "RPC_COMMAND": this.ssid = value; if (value[0] === Commands.WIFI_SETTINGS) { + trace("Handling wifi settings\n"); this.state = StateCodes.STATE_PROVISIONING; this.notifyState(); this.handleInboundWifiSettings(value); @@ -123,6 +134,7 @@ export default class ImprovWifi extends BLEServer { } } handleInboundWifiSettings(data) { + trace("Handling inbound wifi settings\n"); const ssid_length = data[2]; const ssid_start = 3; const ssid_end = ssid_start + ssid_length; @@ -132,16 +144,21 @@ export default class ImprovWifi extends BLEServer { const ssid = this.buildValue(data, ssid_start, ssid_end); const password = this.buildValue(data, pass_start, pass_end); let result = this.onCredentialsRecieved({ ssid, password }); + trace(`Result of onCredentialsRecieved is ${result}\n`); if (!result) { - this.state = StateCodes.STATE_AUTHORIZED; - this.notifyState(); - } - else { - this.state = StateCodes.STATE_PROVISIONED; - this.notifyState(); + trace("Credentials weren't authorized :( \n"); + this.state = StateCodes.ERROR_UNKNOWN; + this.error = ErrorCodes.ERROR_NOT_AUTHORIZED; + this.notifyError(); + return; + } + trace("Credentials were authorized :) \n"); + this.state = StateCodes.STATE_PROVISIONED; + this.notifyState(); } buildValue(data, start, end) { + trace(`Building value from ${start} to ${end}\n`); let str = ''; for (var i = start; i < end; i++) { str += String.fromCharCode(data[i]); @@ -149,16 +166,20 @@ export default class ImprovWifi extends BLEServer { return str; } notifyState() { + trace(`Notifying state: ${this.state}\n`); if (!this.stateCharacteristic) return; this.notifyValue(this.stateCharacteristic, this.state); } notifyError() { + trace(`Notifying this characteristic: ${this.errorCharacteristic?.name} this error: ${this.error}\n`); if (!this.errorCharacteristic) return; + this.notifyValue(this.errorCharacteristic, this.error); } couldNotConnect() { + trace("Could not connect\n"); this.error = ErrorCodes.ERROR_UNABLE_TO_CONNECT; this.notifyError(); }