I can't figure out how to write a code that would make BlueTooth work when it's connected and if it's not connected, wifi is running ?
I understand that they can not work at the same time, but I want that either bluetooth worked if the client had time to connect to it, if at the end of the timeout there are no connections, then then run the connection on WiFi
I use ESP32, and exmaple below, but this only simple Bluetooth connected without WiFi can't figure where to finish the WiFi connection code for what would work either Bluetooth or Wifi:
> Blockquote
/*********
Rui Santos
Complete project details at https://randomnerdtutorials.com
*********/
// Load libraries
#include "BluetoothSerial.h"
#include <OneWire.h>
#include <DallasTemperature.h>
// Check if Bluetooth configs are enabled
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
// Bluetooth Serial object
BluetoothSerial SerialBT;
// GPIO where the DS18B20 is connected to
const int oneWireBus = 15;
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(oneWireBus);
// Pass our oneWire reference to Dallas Temperature sensor
DallasTemperature sensors(&oneWire);
// Handle received and sent messages
String message = "";
char incomingChar;
String temperatureString = "";
// Timer: auxiliar variables
unsigned long previousMillis = 0; // Stores last time temperature was published
const long interval = 1000; // interval at which to publish sensor readings
void setup() {
Serial.begin(9600);
// Bluetooth device name
SerialBT.begin("ESP32");
Serial.println("The device started, now you can pair it with bluetooth!");
}
void loop() {
unsigned long currentMillis = millis();
// Send temperature readings
if (currentMillis - previousMillis >= interval){
previousMillis = currentMillis;
sensors.requestTemperatures();
temperatureString = String (sensors.getTempCByIndex(0));
SerialBT.println(temperatureString);
}
delay(20);
}
> Blockquote