Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: # Wireless Relay
- - Version: 003
- - Source Code NOT compiled for: Firebeetle 2 ESP32-S3
- - Source Code created on: 2026-03-12 12:35:36
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Receive radio station data on GPIO47/48 (115200 */
- /* baud) and transmit to active channel (Bluetooth or */
- /* LoRa). Device name DMR-Radio with random 4-digit */
- /* suffix. PIN 8800 required */
- /****** SYSTEM REQUIREMENT 2 *****/
- /* LoRa SX1262: 433 MHz, SF8, 250 kHz. Bidirectional */
- /* TX/RX. Receive LoRa data and transmit to radio and */
- /* Bluetooth */
- /****** SYSTEM REQUIREMENT 3 *****/
- /* GPIO0 long press (7000ms) toggles between */
- /* Bluetooth and LoRa modes. Display current mode on */
- /* Heltec built-in screen */
- /****** SYSTEM REQUIREMENT 4 *****/
- /* Bidirectional data flow: Radio ↔ Active Channel */
- /* (Bluetooth or LoRa). LoRa RX data → Radio and */
- /* Bluetooth. Bluetooth RX data → Radio and LoRa TX */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <BluetoothSerial.h>
- #include <SPI.h>
- #include <LoRa.h>
- #include <Wire.h>
- #include "heltec.h"
- /****** DEFINITION OF CONSTANTS *****/
- // Heltec ESP32-S3 Pin Definitions
- #define GPIO0_BUTTON_PIN 0 // GPIO0 button for mode toggle
- #define SERIAL2_RX_PIN 47 // GPIO47 for Serial2 RX (from radio station)
- #define SERIAL2_TX_PIN 48 // GPIO48 for Serial2 TX (to radio station)
- #define SERIAL2_BAUDRATE 115200
- // LoRa SX1262 Pin Configuration (Heltec ESP32-S3)
- #define LORA_CS_PIN 8 // Chip Select
- #define LORA_RST_PIN 12 // Reset
- #define LORA_IRQ_PIN 14 // Interrupt
- #define LORA_BUSY_PIN 13 // Busy
- #define LORA_MOSI_PIN 10 // MOSI
- #define LORA_MISO_PIN 9 // MISO
- #define LORA_SCK_PIN 11 // SCK
- // LoRa Configuration Constants
- #define LORA_FREQUENCY 433000000 // 433 MHz
- #define LORA_SPREADING_FACTOR 8 // SF8
- #define LORA_BANDWIDTH 250000 // 250 kHz (125000, 250000, or 500000)
- #define LORA_CODING_RATE 5 // 4/5
- #define LORA_PREAMBLE_LENGTH 8
- #define LORA_SYNC_WORD 0x34
- // Button and Mode Configuration
- #define BUTTON_LONG_PRESS_TIME 7000 // 7 seconds for long press (mode toggle)
- #define BUTTON_DEBOUNCE_TIME 50 // Debounce time in milliseconds
- #define DISPLAY_UPDATE_INTERVAL 500 // Update display every 500ms
- // Bluetooth Configuration
- #define BLUETOOTH_PIN_CODE "8800"
- #define BLUETOOTH_DEVICE_NAME_BASE "DMR-Radio"
- // LoRa Message Configuration
- #define LORA_RX_BUFFER_SIZE 256
- #define LORA_TX_TIMEOUT 3000
- /****** DEFINITION OF GLOBAL VARIABLES *****/
- // Bluetooth Serial object
- BluetoothSerial SerialBT;
- bool bluetoothPinSet = false;
- bool bluetoothConnected = false;
- // Mode selection: true = Bluetooth mode, false = LoRa mode
- volatile bool currentMode = true; // Start in Bluetooth mode
- bool previousMode = true;
- // Button state management
- volatile unsigned long buttonPressStartTime = 0;
- volatile bool buttonPressed = false;
- volatile bool buttonLongPressDetected = false;
- unsigned long lastButtonCheckTime = 0;
- bool previousButtonState = HIGH;
- // LoRa variables
- uint8_t loraRxBuffer[LORA_RX_BUFFER_SIZE];
- int loraRxLength = 0;
- bool loraPacketReceived = false;
- // Display and status variables
- unsigned long lastDisplayUpdate = 0;
- uint32_t packetsSentBluetooth = 0;
- uint32_t packetsReceivedBluetooth = 0;
- uint32_t packetsSentLoRa = 0;
- uint32_t packetsReceivedLoRa = 0;
- uint32_t packetsReceivedRadio = 0;
- uint32_t packetsSentRadio = 0;
- char bluetoothDeviceName[32];
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void initializeDisplay(void);
- void updateDisplay(void);
- void initializeLoRa(void);
- void initializeBluetooth(void);
- void checkButtonInput(void);
- void toggleMode(void);
- void setBluetoothPin(const char* pinCode);
- void handleSerialFromRadio(void);
- void handleBluetoothFromClient(void);
- void handleLoRaReceive(void);
- void sendDataToRadio(const uint8_t* data, size_t length);
- void sendDataToBluetooth(const uint8_t* data, size_t length);
- void sendDataViaLoRa(const uint8_t* data, size_t length);
- void loraOnReceive(int packetSize);
- void displayBluetoothMode(void);
- void displayLoRaMode(void);
- void generateRandomSuffix(void);
- /****** HELTEC DISPLAY FUNCTIONS *****/
- /**
- * initializeDisplay() - Initialize Heltec built-in display
- *
- * Sets up the OLED display connected to the Heltec ESP32-S3 board.
- * Initializes I2C communication and configures display parameters.
- */
- void initializeDisplay(void)
- {
- // Initialize Heltec board display (SSD1306 OLED)
- Heltec.begin(true /* DisplayEnable */, false /* LoRaEnable */);
- Heltec.display->setFont(ArialMT_Plain_10);
- Heltec.display->clear();
- Heltec.display->drawString(0, 0, "Wireless Bridge");
- Heltec.display->drawString(0, 12, "Initializing...");
- Heltec.display->display();
- Serial.println("Heltec display initialized");
- delay(500);
- }
- /**
- * generateRandomSuffix() - Generate a random 4-digit suffix for Bluetooth device name
- *
- * Creates a random 4-digit number and appends it to the Bluetooth device name base.
- * This ensures unique device names across multiple devices.
- */
- void generateRandomSuffix(void)
- {
- // Generate random 4-digit suffix (1000-9999)
- uint16_t randomSuffix = random(1000, 10000);
- sprintf(bluetoothDeviceName, "%s-%04d", BLUETOOTH_DEVICE_NAME_BASE, randomSuffix);
- Serial.print("Generated Bluetooth device name: ");
- Serial.println(bluetoothDeviceName);
- }
- /**
- * displayBluetoothMode() - Display Bluetooth mode information on screen
- *
- * Shows current mode status, connection state, and statistics on the OLED display.
- */
- void displayBluetoothMode(void)
- {
- Heltec.display->clear();
- Heltec.display->setFont(ArialMT_Plain_16);
- Heltec.display->drawString(0, 0, "MODE: BLUETOOTH");
- Heltec.display->setFont(ArialMT_Plain_10);
- // Display connection status
- if (bluetoothConnected && SerialBT.hasClient())
- {
- Heltec.display->drawString(0, 18, "Status: CONNECTED");
- }
- else
- {
- Heltec.display->drawString(0, 18, "Status: WAITING...");
- }
- // Display device name
- Heltec.display->drawString(0, 28, bluetoothDeviceName);
- // Display PIN requirement
- Heltec.display->drawString(0, 38, "PIN: 8800");
- // Display statistics
- char stats[32];
- sprintf(stats, "Sent: %lu", packetsSentBluetooth);
- Heltec.display->drawString(0, 48, stats);
- sprintf(stats, "Recv: %lu", packetsReceivedBluetooth);
- Heltec.display->drawString(64, 48, stats);
- Heltec.display->drawString(0, 58, "Press GPIO0 (7s) to switch");
- Heltec.display->display();
- }
- /**
- * displayLoRaMode() - Display LoRa mode information on screen
- *
- * Shows current mode status, LoRa configuration, and statistics on the OLED display.
- */
- void displayLoRaMode(void)
- {
- Heltec.display->clear();
- Heltec.display->setFont(ArialMT_Plain_16);
- Heltec.display->drawString(0, 0, "MODE: LORA");
- Heltec.display->setFont(ArialMT_Plain_10);
- // Display LoRa configuration
- Heltec.display->drawString(0, 18, "433MHz SF8 250kHz");
- Heltec.display->drawString(0, 28, "Listening...");
- // Display statistics
- char stats[32];
- sprintf(stats, "TX: %lu", packetsSentLoRa);
- Heltec.display->drawString(0, 38, stats);
- sprintf(stats, "RX: %lu", packetsReceivedLoRa);
- Heltec.display->drawString(64, 38, stats);
- sprintf(stats, "Radio: %lu", packetsReceivedRadio);
- Heltec.display->drawString(0, 48, stats);
- sprintf(stats, "Sent: %lu", packetsSentRadio);
- Heltec.display->drawString(64, 48, stats);
- Heltec.display->drawString(0, 58, "Press GPIO0 (7s) to switch");
- Heltec.display->display();
- }
- /**
- * updateDisplay() - Update display based on current mode
- *
- * Periodically refreshes the OLED display with current mode information
- * and statistics. Called from main loop at regular intervals.
- */
- void updateDisplay(void)
- {
- unsigned long currentTime = millis();
- // Update display at defined interval
- if ((currentTime - lastDisplayUpdate) >= DISPLAY_UPDATE_INTERVAL)
- {
- lastDisplayUpdate = currentTime;
- if (currentMode)
- {
- displayBluetoothMode();
- }
- else
- {
- displayLoRaMode();
- }
- }
- }
- /****** LORA FUNCTIONS *****/
- /**
- * initializeLoRa() - Initialize LoRa SX1262 module
- *
- * Configures SPI pins, initializes LoRa library, and sets up parameters
- * for 433 MHz operation with SF8 spreading factor and 250 kHz bandwidth.
- */
- void initializeLoRa(void)
- {
- Serial.println("Initializing LoRa SX1262...");
- // Configure SPI pins for LoRa module
- SPI.begin(LORA_SCK_PIN, LORA_MISO_PIN, LORA_MOSI_PIN, LORA_CS_PIN);
- // Initialize LoRa with appropriate pins for SX1262
- LoRa.setPins(LORA_CS_PIN, LORA_RST_PIN, LORA_IRQ_PIN);
- LoRa.setSPI(SPI);
- // Begin LoRa with 433 MHz frequency
- if (!LoRa.begin(LORA_FREQUENCY))
- {
- Serial.println("ERROR: Failed to initialize LoRa module!");
- Heltec.display->clear();
- Heltec.display->drawString(0, 20, "LoRa Init Failed!");
- Heltec.display->display();
- return;
- }
- // Configure LoRa parameters
- LoRa.setSpreadingFactor(LORA_SPREADING_FACTOR);
- LoRa.setSignalBandwidth(LORA_BANDWIDTH);
- LoRa.setCodingRate4(LORA_CODING_RATE);
- LoRa.setPreambleLength(LORA_PREAMBLE_LENGTH);
- LoRa.setSyncWord(LORA_SYNC_WORD);
- LoRa.enableCrc();
- // Set receiver gain
- LoRa.setGain(6);
- // Register callback for incoming packets
- LoRa.onReceive(loraOnReceive);
- // Start receiving
- LoRa.receive();
- Serial.println("LoRa initialized successfully:");
- Serial.println(" Frequency: 433 MHz");
- Serial.println(" Spreading Factor: SF8");
- Serial.println(" Bandwidth: 250 kHz");
- Serial.println(" Coding Rate: 4/5");
- Serial.println(" Preamble Length: 8");
- Serial.println(" Sync Word: 0x34");
- Serial.println(" CRC: Enabled");
- }
- /**
- * loraOnReceive() - LoRa interrupt callback for packet reception
- *
- * Called when LoRa module detects an incoming packet. Reads packet data
- * into buffer and sets flag for main loop processing.
- *
- * @param packetSize - Number of bytes in the received packet
- */
- void loraOnReceive(int packetSize)
- {
- if (packetSize <= 0) return;
- // Limit packet size to buffer capacity
- if (packetSize > LORA_RX_BUFFER_SIZE)
- {
- packetSize = LORA_RX_BUFFER_SIZE;
- }
- // Read packet into buffer
- loraRxLength = 0;
- while (LoRa.available() && loraRxLength < packetSize)
- {
- loraRxBuffer[loraRxLength++] = LoRa.read();
- }
- // Set flag to indicate packet received
- loraPacketReceived = true;
- packetsReceivedLoRa++;
- Serial.print("LoRa packet received: ");
- Serial.print(loraRxLength);
- Serial.println(" bytes");
- // Resume receiving
- LoRa.receive();
- }
- /**
- * sendDataViaLoRa() - Transmit data via LoRa
- *
- * Sends a buffer of data through the LoRa SX1262 module. Includes error
- * handling and transmission status feedback.
- *
- * @param data - Pointer to data buffer to send
- * @param length - Number of bytes to send
- */
- void sendDataViaLoRa(const uint8_t* data, size_t length)
- {
- if (data == NULL || length == 0)
- {
- Serial.println("ERROR: Invalid LoRa TX data (NULL or zero length)");
- return;
- }
- if (length > LORA_RX_BUFFER_SIZE)
- {
- Serial.println("ERROR: LoRa TX data too large");
- return;
- }
- // Begin LoRa packet transmission
- LoRa.beginPacket();
- // Write data to packet
- LoRa.write(data, length);
- // End packet and wait for transmission
- if (LoRa.endPacket(true)) // true = wait for transmission
- {
- packetsSentLoRa++;
- Serial.print("LoRa TX success: ");
- Serial.print(length);
- Serial.println(" bytes");
- }
- else
- {
- Serial.println("ERROR: LoRa transmission failed");
- }
- // Resume receiving after transmission
- LoRa.receive();
- }
- /**
- * handleLoRaReceive() - Process received LoRa packets
- *
- * Checks if a LoRa packet was received, and forwards it to both
- * the radio station (Serial2) and Bluetooth client (if connected).
- */
- void handleLoRaReceive(void)
- {
- // Check if a LoRa packet was received
- if (!loraPacketReceived) return;
- loraPacketReceived = false;
- // Forward LoRa data to radio station via Serial2
- for (int i = 0; i < loraRxLength; i++)
- {
- Serial2.write(loraRxBuffer[i]);
- }
- packetsReceivedRadio++;
- // Forward LoRa data to Bluetooth client if connected
- if (SerialBT.hasClient())
- {
- for (int i = 0; i < loraRxLength; i++)
- {
- SerialBT.write(loraRxBuffer[i]);
- }
- packetsReceivedBluetooth++;
- }
- Serial.print("LoRa->Radio+BT: ");
- Serial.print(loraRxLength);
- Serial.println(" bytes");
- }
- /****** BLUETOOTH FUNCTIONS *****/
- /**
- * initializeBluetooth() - Initialize Bluetooth Classic SPP
- *
- * Sets up Bluetooth Serial with generated device name and PIN authentication.
- */
- void initializeBluetooth(void)
- {
- Serial.println("Initializing Bluetooth Classic SPP...");
- // Generate random suffix for device name
- generateRandomSuffix();
- // Initialize Bluetooth with generated device name
- if (SerialBT.begin(bluetoothDeviceName))
- {
- Serial.print("Bluetooth initialized as: ");
- Serial.println(bluetoothDeviceName);
- }
- else
- {
- Serial.println("ERROR: Failed to initialize Bluetooth");
- return;
- }
- // Set PIN code for authentication
- setBluetoothPin(BLUETOOTH_PIN_CODE);
- Serial.println("Bluetooth waiting for authenticated connections...");
- }
- /**
- * setBluetoothPin() - Set PIN code for Bluetooth authentication
- *
- * Configures the PIN (8800) that clients must provide during pairing
- * to connect to this device.
- *
- * @param pinCode - PIN code string (e.g., "8800")
- */
- void setBluetoothPin(const char* pinCode)
- {
- if (pinCode == NULL)
- {
- Serial.println("ERROR: PIN code is NULL");
- return;
- }
- if (strlen(pinCode) < 4 || strlen(pinCode) > 16)
- {
- Serial.print("ERROR: Invalid PIN code length: ");
- Serial.println(strlen(pinCode));
- return;
- }
- if (SerialBT.setPin(pinCode))
- {
- bluetoothPinSet = true;
- Serial.print("Bluetooth PIN set to: ");
- Serial.println(pinCode);
- }
- else
- {
- bluetoothPinSet = false;
- Serial.print("ERROR: Failed to set Bluetooth PIN: ");
- Serial.println(pinCode);
- }
- }
- /**
- * sendDataToBluetooth() - Send data to Bluetooth client
- *
- * Transmits data to connected Bluetooth client (SPP mode).
- *
- * @param data - Pointer to data buffer
- * @param length - Number of bytes to send
- */
- void sendDataToBluetooth(const uint8_t* data, size_t length)
- {
- if (data == NULL || length == 0) return;
- // Only send if client is connected
- if (SerialBT.hasClient())
- {
- SerialBT.write(data, length);
- packetsSentBluetooth++;
- }
- }
- /**
- * handleBluetoothFromClient() - Process data from Bluetooth client
- *
- * Reads incoming data from Bluetooth client and forwards it to:
- * - Radio station (Serial2) in both Bluetooth and LoRa modes
- * - LoRa module (if in LoRa mode)
- */
- void handleBluetoothFromClient(void)
- {
- // Check if data is available from Bluetooth client
- while (SerialBT.available() > 0)
- {
- uint8_t byteBT = SerialBT.read();
- // Forward to radio station
- Serial2.write(byteBT);
- packetsReceivedRadio++;
- // Forward to LoRa if in LoRa mode
- if (!currentMode)
- {
- // In LoRa mode, accumulate bytes into a packet
- // For simplicity, send immediately (can be optimized with buffering)
- uint8_t loraPacket[1] = {byteBT};
- sendDataViaLoRa(loraPacket, 1);
- }
- Serial.print("BT->Radio");
- if (!currentMode) Serial.print("+LoRa");
- Serial.print(": 0x");
- Serial.println(byteBT, HEX);
- }
- // Update Bluetooth connection status
- bluetoothConnected = SerialBT.hasClient();
- }
- /****** BUTTON FUNCTIONS *****/
- /**
- * checkButtonInput() - Monitor GPIO0 button for long press (mode toggle)
- *
- * Detects 7-second long press on GPIO0 to toggle between Bluetooth and LoRa modes.
- * Includes debounce logic to prevent false triggers.
- */
- void checkButtonInput(void)
- {
- unsigned long currentTime = millis();
- // Debounce check
- if ((currentTime - lastButtonCheckTime) < BUTTON_DEBOUNCE_TIME) return;
- lastButtonCheckTime = currentTime;
- // Read current button state (active LOW on GPIO0)
- bool currentButtonState = digitalRead(GPIO0_BUTTON_PIN);
- // Detect button press (transition from HIGH to LOW)
- if (previousButtonState == HIGH && currentButtonState == LOW)
- {
- buttonPressed = true;
- buttonPressStartTime = currentTime;
- Serial.println("Button pressed (GPIO0)");
- }
- // Detect button release (transition from LOW to HIGH)
- if (previousButtonState == LOW && currentButtonState == HIGH)
- {
- if (buttonPressed)
- {
- unsigned long pressDuration = currentTime - buttonPressStartTime;
- // Check for long press (>= 7 seconds)
- if (pressDuration >= BUTTON_LONG_PRESS_TIME)
- {
- if (!buttonLongPressDetected)
- {
- buttonLongPressDetected = true;
- toggleMode();
- }
- }
- buttonPressed = false;
- buttonLongPressDetected = false;
- }
- }
- previousButtonState = currentButtonState;
- }
- /**
- * toggleMode() - Toggle between Bluetooth and LoRa modes
- *
- * Switches active communication mode between Bluetooth Classic SPP
- * and LoRa SX1262. Updates mode indicator and reinitializes relevant
- * peripherals.
- */
- void toggleMode(void)
- {
- currentMode = !currentMode;
- Serial.println("\n=== MODE TOGGLE ===");
- Serial.print("New Mode: ");
- Serial.println(currentMode ? "BLUETOOTH" : "LORA");
- if (currentMode)
- {
- // Switched to Bluetooth mode
- Serial.println("Bluetooth mode active - ready for client connections");
- // Resume LoRa receiver if switching away from it
- LoRa.receive();
- }
- else
- {
- // Switched to LoRa mode
- Serial.println("LoRa mode active - 433MHz SF8 250kHz listening");
- // Ensure LoRa is initialized and receiving
- LoRa.receive();
- }
- // Update display
- updateDisplay();
- }
- /****** RADIO SERIAL FUNCTIONS *****/
- /**
- * sendDataToRadio() - Send data to radio station via Serial2
- *
- * Transmits data to the connected radio station on GPIO47/48 at 115200 baud.
- *
- * @param data - Pointer to data buffer
- * @param length - Number of bytes to send
- */
- void sendDataToRadio(const uint8_t* data, size_t length)
- {
- if (data == NULL || length == 0) return;
- for (size_t i = 0; i < length; i++)
- {
- Serial2.write(data[i]);
- }
- packetsSentRadio++;
- }
- /**
- * handleSerialFromRadio() - Process data from radio station
- *
- * Reads incoming data from radio station (Serial2) and forwards it to:
- * - Bluetooth client (if connected and in Bluetooth mode)
- * - LoRa module (if in LoRa mode)
- */
- void handleSerialFromRadio(void)
- {
- // Check if data is available from radio station on Serial2
- while (Serial2.available() > 0)
- {
- uint8_t byteRadio = Serial2.read();
- packetsReceivedRadio++;
- // Forward to active channel based on current mode
- if (currentMode)
- {
- // Bluetooth mode: forward to Bluetooth client
- if (SerialBT.hasClient())
- {
- SerialBT.write(byteRadio);
- packetsSentBluetooth++;
- }
- }
- else
- {
- // LoRa mode: accumulate for LoRa transmission
- // For simplicity, send single bytes (can be optimized with buffering)
- uint8_t loraPacket[1] = {byteRadio};
- sendDataViaLoRa(loraPacket, 1);
- }
- Serial.print("Radio->");
- Serial.println(currentMode ? "BT" : "LoRa");
- }
- }
- /****** SETUP FUNCTION *****/
- /**
- * setup() - Initialize all peripherals and subsystems
- *
- * Performs complete initialization of:
- * - Serial communication (USB debug)
- * - Heltec display
- * - GPIO0 button
- * - Serial2 for radio station communication
- * - Bluetooth Classic SPP
- * - LoRa SX1262 module
- */
- void setup(void)
- {
- // Initialize USB serial for debug output
- Serial.begin(115200);
- delay(1000);
- Serial.println("\n\n=== Heltec ESP32-S3 Wireless Bridge ===");
- Serial.println("LoRa SX1262 + Bluetooth + Radio Station");
- Serial.println("433MHz LoRa, Bluetooth Classic SPP, GPIO0 Mode Toggle");
- // Initialize Heltec display (I2C: GPIO21=SDA, GPIO22=SCL by default)
- initializeDisplay();
- // Configure GPIO0 as input (button)
- pinMode(GPIO0_BUTTON_PIN, INPUT_PULLUP);
- Serial.println("GPIO0 button configured (7s long press to toggle mode)");
- // Initialize Serial2 for radio station communication (GPIO47=RX, GPIO48=TX)
- Serial2.begin(SERIAL2_BAUDRATE, SERIAL_8N1, SERIAL2_RX_PIN, SERIAL2_TX_PIN);
- Serial.println("Serial2 initialized for radio station");
- Serial.print(" RX Pin: GPIO");
- Serial.print(SERIAL2_RX_PIN);
- Serial.print(", TX Pin: GPIO");
- Serial.print(SERIAL2_TX_PIN);
- Serial.print(", Baud: ");
- Serial.println(SERIAL2_BAUDRATE);
- // Initialize Bluetooth Classic SPP
- initializeBluetooth();
- // Initialize LoRa SX1262
- initializeLoRa();
- Serial.println("\n=== Initialization Complete ===");
- Serial.println("Starting in Bluetooth mode");
- Serial.println("Current mode: BLUETOOTH");
- Serial.println("Button (GPIO0): 7s long press to toggle to LoRa mode\n");
- // Initial display update
- lastDisplayUpdate = 0;
- updateDisplay();
- }
- /****** MAIN LOOP FUNCTION *****/
- /**
- * loop() - Main processing loop
- *
- * Continuously processes:
- * - GPIO0 button input for mode toggle
- * - Radio station data (Serial2)
- * - Bluetooth client data
- * - LoRa received packets
- * - Display updates
- *
- * Implements bidirectional data flow between radio, Bluetooth, and LoRa.
- */
- void loop(void)
- {
- // Monitor GPIO0 button for 7-second long press (mode toggle)
- checkButtonInput();
- // Process radio station data (forward to active channel)
- handleSerialFromRadio();
- // Process Bluetooth client data (forward to radio and LoRa)
- handleBluetoothFromClient();
- // Process LoRa received packets (forward to radio and Bluetooth)
- handleLoRaReceive();
- // Update display with current mode and statistics
- updateDisplay();
- // Small delay to prevent overwhelming processor
- delay(10);
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment