#include <WiFi.h>
#include <BluetoothSerial.h>
BluetoothSerial SerialBT;
// Replace with your network credentials
const char* ssid = "your_SSID";
const char* password = "your_PASSWORD";
void setup() {
Serial.begin(115200);
SerialBT.begin("ESP32_AirTag"); // Bluetooth device name
Serial.println("The device started, now you can pair it with Bluetooth!");
// Connect to Wi-Fi
WiFi.begin(ssid, password);
Serial.print("Connecting to Wi-Fi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println();
Serial.println("Connected to Wi-Fi");
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());
}
void loop() {
// Check for Bluetooth data
if (SerialBT.available()) {
String btData = SerialBT.readString();
Serial.print("Received via Bluetooth: ");
Serial.println(btData);
// Example: If you receive "status", send back Wi-Fi status
if (btData == "status") {
SerialBT.print("Connected to Wi-Fi: ");
SerialBT.println(WiFi.SSID());
SerialBT.print("IP Address: ");
SerialBT.println(WiFi.localIP());
}
}
// Add your main code here
}