diff --git a/elrs-boards/main.cpp b/elrs-boards/main.cpp index 9690d31..8d889e6 100644 --- a/elrs-boards/main.cpp +++ b/elrs-boards/main.cpp @@ -453,6 +453,7 @@ void SetDioAsRfSwitch() void initRadio(float freq) { int state, state2; + radio.begin(); state = radio.beginGFSK(freq, 4.8F, 5.0F, 156.2F, 10, 16U, 1.6F); state2 = radio2.beginGFSK(freq, 4.8F, 5.0F, 156.2F, 10, 16U, 1.6F); if (state != RADIOLIB_ERR_NONE) diff --git a/include/WIFI_SERVER.h b/include/WIFI_SERVER.h index 93a715d..8fc24ad 100644 --- a/include/WIFI_SERVER.h +++ b/include/WIFI_SERVER.h @@ -1,11 +1,3 @@ -#include -#include -#include -#include - -// Create AsyncWebServer object on port 80 -AsyncWebServer server(80); - // Search for parameter in HTTP POST request const String SSID = "ssid"; const String PASS = "pass"; @@ -21,6 +13,15 @@ const String FEND = "fend"; String ssid = "LoraSA", pass = "1234567890", ip = "192.168.1.100", gateway = "192.168.1.1", fstart = "", fend = "", smpls = ""; +#ifdef WEB_SERVER +#include +#include +#include +#include + +// Create AsyncWebServer object on port 80 +AsyncWebServer server(80); + IPAddress localIP; // Set your Gateway IP address IPAddress localGateway; @@ -73,25 +74,6 @@ bool initWiFi() return true; } -void writeParameterToFile(String value, String file) -{ - // Write file to save value - writeFile(LittleFS, file.c_str(), value.c_str()); -} - -void writeParameterToParameterFile(String param, String value) -{ - String file = String("/" + param + ".txt"); - // Write file to save value - writeParameterToFile(value, file.c_str()); -} - -String readParameterFromParameterFile(String param) -{ - String file = String("/" + param + ".txt"); - return readFile(LittleFS, file.c_str()); -} - void serverServer() { // Route for root / web page @@ -203,3 +185,23 @@ void serverStart() serverServer(); } } +#endif + +void writeParameterToFile(String value, String file) +{ + // Write file to save value + writeFile(LittleFS, file.c_str(), value.c_str()); +} + +void writeParameterToParameterFile(String param, String value) +{ + String file = String("/" + param + ".txt"); + // Write file to save value + writeParameterToFile(value, file.c_str()); +} + +String readParameterFromParameterFile(String param) +{ + String file = String("/" + param + ".txt"); + return readFile(LittleFS, file.c_str()); +} diff --git a/platformio.ini b/platformio.ini index a900e99..61b83c2 100644 --- a/platformio.ini +++ b/platformio.ini @@ -263,9 +263,10 @@ lib_deps = RadioLib U8g2 XPowersLib - ESP Async WebServer + h2zero/NimBLE-Arduino https://github.com/Genaker/Adafruit_HMC5883_Unified -build_flags = +build_flags = + -lbt -DLILYGO -DT3_S3_V1_2_LR1121 -DARDUINO_LILYGO_T3S3_LR1121 @@ -285,6 +286,7 @@ build_flags = -DCOMPASS_FREQ=915 -DCOMPASS_DEBUG -DCOMPASS_RSSI + -DBT_MOBILE [env:lilygo-T3S3-v1-2-sx1280] platform = espressif32 diff --git a/src/main.cpp b/src/main.cpp index 5f27816..ba25bbb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -23,10 +23,70 @@ // #define HELTEC_NO_DISPLAY +#ifdef BT_MOBILE +#include + +#define SERVICE_UUID "00001234-0000-1000-8000-00805f9b34fb" +#define CHARACTERISTIC_UUID "00001234-0000-1000-8000-00805f9b34ac" + +NimBLEServer *pServer = nullptr; +NimBLECharacteristic *pCharacteristic = nullptr; +NimBLEAdvertising *pAdvertising = nullptr; + +void initBT() +{ + // Initialize BLE device + NimBLEDevice::init("RSSI_Radar"); + + // Get and print the MAC address + String macAddress = NimBLEDevice::getAddress().toString().c_str(); + Serial.println("Bluetooth MAC Address: " + macAddress); + + // Create BLE server + pServer = NimBLEDevice::createServer(); + + // Create a BLE service + NimBLEService *pService = pServer->createService(SERVICE_UUID); + + // Create a BLE characteristic + pCharacteristic = pService->createCharacteristic( + CHARACTERISTIC_UUID, NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::NOTIFY); + + // Start the service + pService->start(); + + // Start advertising + + pAdvertising = NimBLEDevice::getAdvertising(); + pAdvertising->addServiceUUID(SERVICE_UUID); + pAdvertising->setName("ESP32_RSSI_Radar"); // Set the device name + pAdvertising->setMinInterval(300); + pAdvertising->setMaxInterval(350); + // pAdvertising->setScanResponse(true); // Allow scan responses + + pAdvertising->start(); + + Serial.println("BLE server started."); +} + +// Function to send RSSI and Heading Data +void sendBTData(float heading, float rssi) +{ + String data = + "RSSI_HEADING: '{H:" + String(heading) + ",RSSI:-" + String(rssi) + "}'"; + Serial.println("Sending data: " + data); + pCharacteristic->setValue(data.c_str()); // Set BLE characteristic value + pCharacteristic->notify(); // Notify connected client +} + +#endif + #include "FS.h" #include +#ifdef WEB_SERVER #include #include +#endif #include #include #include @@ -1416,6 +1476,10 @@ void setup(void) readConfigFile(); #endif +#ifdef BT_MOBILE + initBT(); +#endif + #ifndef WEB_SERVER if (config.scan_ranges_sz == 0 && SCAN_RANGES.length() > 0) { @@ -2414,6 +2478,9 @@ void loop(void) // DEBUG STUFF /*String((int)headingDegrees) + "x:" + String(newX) + "c:" + String(xResolution) + "l:" + String(length)*/); +#ifdef BT_MOBILE + sendBTData(headingDegrees, rssiMax); // Send data to BLE client +#endif display.display(); compassCounter++; @@ -2429,6 +2496,9 @@ void loop(void) { historicalCompassRssi[i] = 999; } + initForScan(FREQ_BEGIN); + // Restart BT advert + pAdvertising->start(); maxRssiHist = 9999; maxRssiHistX = 130; maxRssiHeading = 0; diff --git a/web_app/compass/index.html b/web_app/compass/index.html new file mode 100644 index 0000000..65b23af --- /dev/null +++ b/web_app/compass/index.html @@ -0,0 +1,438 @@ + + + + + + + RSSI Radar + + + + +

RSSI Radar

+ + +
+

Heading:

+

RSSI: -70 dBm

+
+ +
+

Heading MAX:

+

RSSI MAX: -70 dBm

+
+

Status: Disconnected

+ + + + + + + +