Skip to content

Commit 78ee88c

Browse files
author
Scott Powell
committed
* companion, HeltecV3: now picks random BLE pin for every session (from boot), unless a (non-zero) one stored in _prefs
* companion, WSL3: uses static BLE pin, per build BLE_PIN_CODE define
1 parent 01d84d5 commit 78ee88c

File tree

3 files changed

+35
-11
lines changed

3 files changed

+35
-11
lines changed

examples/companion_radio/UITask.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ void UITask::renderCurrScreen() {
7878
if (_connected) {
7979
//_display->printf("freq : %03.2f sf %d\n", _prefs.freq, _prefs.sf);
8080
//_display->printf("bw : %03.2f cr %d\n", _prefs.bw, _prefs.cr);
81-
} else {
81+
} else if (_pin_code != 0) {
8282
_display->setTextSize(2);
8383
_display->setCursor(0, 43);
8484
sprintf(tmp, "Pin:%d", _pin_code);

examples/companion_radio/main.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ class MyMesh : public BaseChatMesh {
204204
ContactsIterator _iter;
205205
uint32_t _iter_filter_since;
206206
uint32_t _most_recent_lastmod;
207+
uint32_t _active_ble_pin;
207208
bool _iter_started;
208209
uint8_t app_target_ver;
209210
uint8_t cmd_frame[MAX_FRAME_SIZE+1];
@@ -220,11 +221,6 @@ class MyMesh : public BaseChatMesh {
220221
if (!_identity_store->load("_main", self_id)) {
221222
self_id = mesh::LocalIdentity(&trng); // create new random identity
222223
saveMainIdentity(self_id);
223-
224-
#if defined(BLE_PIN_CODE) && defined(DISPLAY_CLASS)
225-
// start with randomly assigned BLE pin
226-
_prefs.ble_pin = trng.nextInt(100000, 999999);
227-
#endif
228224
}
229225
}
230226

@@ -617,9 +613,6 @@ class MyMesh : public BaseChatMesh {
617613
_prefs.bw = LORA_BW;
618614
_prefs.cr = LORA_CR;
619615
_prefs.tx_power_dbm = LORA_TX_POWER;
620-
#ifdef BLE_PIN_CODE
621-
_prefs.ble_pin = BLE_PIN_CODE;
622-
#endif
623616
//_prefs.rx_delay_base = 10.0f; enable once new algo fixed
624617
}
625618

@@ -672,6 +665,20 @@ class MyMesh : public BaseChatMesh {
672665
}
673666
}
674667

668+
#ifdef BLE_PIN_CODE
669+
if (_prefs.ble_pin == 0) {
670+
#ifdef DISPLAY_CLASS
671+
_active_ble_pin = trng.nextInt(100000, 999999); // random pin each session
672+
#else
673+
_active_ble_pin = BLE_PIN_CODE; // otherwise static pin
674+
#endif
675+
} else {
676+
_active_ble_pin = _prefs.ble_pin;
677+
}
678+
#else
679+
_active_ble_pin = 0;
680+
#endif
681+
675682
// init 'blob store' support
676683
_fs->mkdir("/bl");
677684

@@ -686,7 +693,7 @@ class MyMesh : public BaseChatMesh {
686693
}
687694

688695
const char* getNodeName() { return _prefs.node_name; }
689-
uint32_t getBLEPin() { return _prefs.ble_pin; }
696+
uint32_t getBLEPin() { return _active_ble_pin; }
690697

691698
void startInterface(BaseSerialInterface& serial) {
692699
_serial = &serial;

platformio.ini

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ build_flags =
185185
-D MAX_CONTACTS=100
186186
-D MAX_GROUP_CHANNELS=1
187187
-D DISPLAY_CLASS=SSD1306Display
188-
-D BLE_PIN_CODE=123456
188+
-D BLE_PIN_CODE=0 ; dynamic, random PIN
189189
-D BLE_DEBUG_LOGGING=1
190190
; -D ENABLE_PRIVATE_KEY_IMPORT=1
191191
; -D ENABLE_PRIVATE_KEY_EXPORT=1
@@ -196,6 +196,23 @@ lib_deps =
196196
${Heltec_lora32_v3.lib_deps}
197197
densaugeo/base64 @ ~1.4.0
198198

199+
[env:Heltec_WSL3_companion_radio_ble]
200+
extends = Heltec_lora32_v3
201+
build_flags =
202+
${Heltec_lora32_v3.build_flags}
203+
-D MAX_CONTACTS=100
204+
-D MAX_GROUP_CHANNELS=1
205+
-D BLE_PIN_CODE=123456
206+
-D BLE_DEBUG_LOGGING=1
207+
; -D ENABLE_PRIVATE_KEY_IMPORT=1
208+
; -D ENABLE_PRIVATE_KEY_EXPORT=1
209+
; -D MESH_PACKET_LOGGING=1
210+
; -D MESH_DEBUG=1
211+
build_src_filter = ${Heltec_lora32_v3.build_src_filter} +<helpers/esp32/*.cpp> +<../examples/companion_radio>
212+
lib_deps =
213+
${Heltec_lora32_v3.lib_deps}
214+
densaugeo/base64 @ ~1.4.0
215+
199216
[env:Heltec_v3_companion_radio_wifi]
200217
extends = Heltec_lora32_v3
201218
build_flags =

0 commit comments

Comments
 (0)