From 7886291759923c1a0be48048387f83c53053ff7e Mon Sep 17 00:00:00 2001 From: UA1ZBE Date: Wed, 22 Jul 2026 10:34:18 +0300 Subject: [PATCH] Revert BLE: restore working state without BLE --- src/main.cpp | 84 +--------------------------------------------------- 1 file changed, 1 insertion(+), 83 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index d862c9c..99e3f43 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -11,7 +11,6 @@ #include #include #include -#include #include "target.h" using namespace Adafruit_LittleFS_Namespace; @@ -50,70 +49,6 @@ static const unsigned long ALERT_COOLDOWN_MS = 600000; static unsigned long g_boot_time = 0; static bool g_startup_msg_sent = false; -static char g_channel_pass[32] = ""; - -bool saveChannelPass(const char* pass) { - File f = InternalFS.open(CHANNEL_FILE, FILE_O_WRITE); - if (!f) return false; - size_t len = strlen(pass); - if (len > 31) len = 31; - bool ok = f.write((const uint8_t*)pass, len) == len; - f.close(); return ok; -} - -bool loadChannelPass() { - File f = InternalFS.open(CHANNEL_FILE, FILE_O_READ); - if (!f) return false; - int len = f.read((uint8_t*)g_channel_pass, sizeof(g_channel_pass) - 1); - f.close(); - if (len > 0) { g_channel_pass[len] = 0; return true; } - return false; -} - -BLEUart bleuart; - -void ble_send(const char* text) { - bleuart.println(text); -} - -void setup_ble() { - Bluefruit.begin(1, 0); - Bluefruit.setName("Security-Mesh"); - Bluefruit.setTxPower(4); - bleuart.begin(); - Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE); - Bluefruit.Advertising.addTxPower(); - Bluefruit.Advertising.addService(bleuart); - Bluefruit.ScanResponse.addName(); - Bluefruit.Advertising.restartOnDisconnect(true); - Bluefruit.Advertising.setInterval(32, 244); - Bluefruit.Advertising.start(0); -} - -void process_ble_line(const char* line) { - if (strncmp(line, "channel ", 8) == 0) { - const char* pass = line + 8; - int len = strlen(pass); - if (len < 1 || len > 31) { ble_send("bad password length"); return; } - int digits = 0; - for (int i = 0; pass[i]; i++) if (pass[i] >= '0' && pass[i] <= '9') digits++; - if (digits != len) { ble_send("use digits only"); return; } - strncpy(g_channel_pass, pass, sizeof(g_channel_pass) - 1); - saveChannelPass(pass); - char r[64]; snprintf(r, sizeof(r), "channel %s saved, rebooting...", pass); - ble_send(r); - delay(100); - NVIC_SystemReset(); - } else if (strcmp(line, "status") == 0) { - char r[64]; snprintf(r, sizeof(r), "channel: %s", g_channel_pass[0] ? g_channel_pass : "1234"); - ble_send(r); - } else if (strcmp(line, "help") == 0) { - ble_send("commands: channel , status, help"); - } else { - ble_send("unknown. try help"); - } -} - struct SecurityConfig { uint32_t magic; uint8_t armed; uint8_t relay2; }; static const uint32_t CFG_MAGIC = 0x53454355; @@ -145,9 +80,8 @@ public: : Mesh(r, *new ArduinoMillis(), rng, clock, *new StaticPoolPacketManager(16), t) {} void setup_channel() { - const char* pass = g_channel_pass[0] ? g_channel_pass : "1234"; uint8_t key[32]; - SHA256 sha; sha.reset(); sha.update((const uint8_t*)pass, strlen(pass)); sha.finalize(key, 32); + SHA256 sha; sha.reset(); sha.update((const uint8_t*)"1234", 4); sha.finalize(key, 32); memset(mesh_channel.secret, 0, 32); memcpy(mesh_channel.secret, key, 16); mesh::Utils::sha256(mesh_channel.hash, sizeof(mesh_channel.hash), mesh_channel.secret, 16); @@ -283,12 +217,9 @@ void setup() { InternalFS.begin(); loadSecurityConfig(); - loadChannelPass(); if (g_armed) digitalWrite(PIN_RELAY_1, LOW); else digitalWrite(PIN_RELAY_1, HIGH); digitalWrite(PIN_RELAY_2, g_relay2_state ? LOW : HIGH); - setup_ble(); - if (!radio_init()) { Serial.println("RADIO FAIL"); while (1) { digitalWrite(PIN_LED_STATUS, HIGH); delay(100); digitalWrite(PIN_LED_STATUS, LOW); delay(100); } @@ -308,19 +239,6 @@ void loop() { the_mesh.flush_response(); rtc_clock.tick(); - static char ble_line[64]; - static int ble_pos = 0; - while (bleuart.available()) { - char c = bleuart.read(); - if (c == '\n' || c == '\r') { - ble_line[ble_pos] = 0; - if (ble_pos > 0) process_ble_line(ble_line); - ble_pos = 0; - } else if (ble_pos < (int)sizeof(ble_line) - 1) { - ble_line[ble_pos++] = c; - } - } - if (!g_startup_msg_sent && millis() - g_boot_time >= 10000) { g_startup_msg_sent = true; char m[80]; snprintf(m, sizeof(m), "poweron %s %s", __DATE__, __TIME__);