diff --git a/examples/companion_radio/UITask.cpp b/examples/companion_radio/UITask.cpp index f003aa52..8ffb2c1f 100644 --- a/examples/companion_radio/UITask.cpp +++ b/examples/companion_radio/UITask.cpp @@ -78,7 +78,7 @@ void UITask::renderCurrScreen() { if (_connected) { //_display->printf("freq : %03.2f sf %d\n", _prefs.freq, _prefs.sf); //_display->printf("bw : %03.2f cr %d\n", _prefs.bw, _prefs.cr); - } else { + } else if (_pin_code != 0) { _display->setTextSize(2); _display->setCursor(0, 43); sprintf(tmp, "Pin:%d", _pin_code); diff --git a/examples/companion_radio/main.cpp b/examples/companion_radio/main.cpp index 1f528439..7eba79c9 100644 --- a/examples/companion_radio/main.cpp +++ b/examples/companion_radio/main.cpp @@ -204,6 +204,7 @@ class MyMesh : public BaseChatMesh { ContactsIterator _iter; uint32_t _iter_filter_since; uint32_t _most_recent_lastmod; + uint32_t _active_ble_pin; bool _iter_started; uint8_t app_target_ver; uint8_t cmd_frame[MAX_FRAME_SIZE+1]; @@ -220,11 +221,6 @@ class MyMesh : public BaseChatMesh { if (!_identity_store->load("_main", self_id)) { self_id = mesh::LocalIdentity(&trng); // create new random identity saveMainIdentity(self_id); - - #if defined(BLE_PIN_CODE) && defined(DISPLAY_CLASS) - // start with randomly assigned BLE pin - _prefs.ble_pin = trng.nextInt(100000, 999999); - #endif } } @@ -617,9 +613,6 @@ public: _prefs.bw = LORA_BW; _prefs.cr = LORA_CR; _prefs.tx_power_dbm = LORA_TX_POWER; - #ifdef BLE_PIN_CODE - _prefs.ble_pin = BLE_PIN_CODE; - #endif //_prefs.rx_delay_base = 10.0f; enable once new algo fixed } @@ -672,6 +665,20 @@ public: } } + #ifdef BLE_PIN_CODE + if (_prefs.ble_pin == 0) { + #ifdef DISPLAY_CLASS + _active_ble_pin = trng.nextInt(100000, 999999); // random pin each session + #else + _active_ble_pin = BLE_PIN_CODE; // otherwise static pin + #endif + } else { + _active_ble_pin = _prefs.ble_pin; + } + #else + _active_ble_pin = 0; + #endif + // init 'blob store' support _fs->mkdir("/bl"); @@ -686,7 +693,7 @@ public: } const char* getNodeName() { return _prefs.node_name; } - uint32_t getBLEPin() { return _prefs.ble_pin; } + uint32_t getBLEPin() { return _active_ble_pin; } void startInterface(BaseSerialInterface& serial) { _serial = &serial; diff --git a/platformio.ini b/platformio.ini index 2457a306..17a699d4 100644 --- a/platformio.ini +++ b/platformio.ini @@ -185,7 +185,7 @@ build_flags = -D MAX_CONTACTS=100 -D MAX_GROUP_CHANNELS=1 -D DISPLAY_CLASS=SSD1306Display - -D BLE_PIN_CODE=123456 + -D BLE_PIN_CODE=0 ; dynamic, random PIN -D BLE_DEBUG_LOGGING=1 ; -D ENABLE_PRIVATE_KEY_IMPORT=1 ; -D ENABLE_PRIVATE_KEY_EXPORT=1 @@ -196,6 +196,23 @@ lib_deps = ${Heltec_lora32_v3.lib_deps} densaugeo/base64 @ ~1.4.0 +[env:Heltec_WSL3_companion_radio_ble] +extends = Heltec_lora32_v3 +build_flags = + ${Heltec_lora32_v3.build_flags} + -D MAX_CONTACTS=100 + -D MAX_GROUP_CHANNELS=1 + -D BLE_PIN_CODE=123456 + -D BLE_DEBUG_LOGGING=1 +; -D ENABLE_PRIVATE_KEY_IMPORT=1 +; -D ENABLE_PRIVATE_KEY_EXPORT=1 +; -D MESH_PACKET_LOGGING=1 +; -D MESH_DEBUG=1 +build_src_filter = ${Heltec_lora32_v3.build_src_filter} + +<../examples/companion_radio> +lib_deps = + ${Heltec_lora32_v3.lib_deps} + densaugeo/base64 @ ~1.4.0 + [env:Heltec_v3_companion_radio_wifi] extends = Heltec_lora32_v3 build_flags =