Folgende Methode erlaubt es per http-Befehl ein iPad (oder auch ein iPhone) über einen ESP32 der per bluetooth mit dem iPad gepaired wird zu steuern:
Die Idee stammt von hier: https://github.com/satoer/HomeyESP32BluetoothKeyboard. d.h., der ESP32 bekommt einen Bluetooth-Keyboard-Treiber installiert und eine minimal-Steuerung per Wifi.
Hardware:
Benutzt habe ich dafür ein "diymore ESP32 NodeMCU ESP32 WROOM 32"
Software:
Dazu das aktuelle Arduino IDE installiert: https://www.arduino.cc/en/software
Dann den ESP32 support installiert: - instal ESP32 support (hier)
BLE Keyboard / Library installieren: https://github.com/T-vK/ESP32-BLE-Keyboard
Dann im Arduino IDE unter Tools → Board → "ESP32 Dev Module" eingestellt.
Weiter unter Tools → Upload Speed → 115200 eingestellt.
Nach Fehlermeldung: "Compilation error: text section exceeds available space in board" folgende Einstellung vorgenommen: Tools → Partition Scheme: Huge APP. (Platz schaffen für die Libraries!)
Ich musste nach jedem Upload das Programm manuell über den Knopf am ESP32 starten ("EN" steht dran, nicht der andere mit "boot") → der "Serial Monitor" (muss aktiviert werden) zeigt dann den Wifi Verbindungsaufbau. etc.
Dann hier geschaut: https://medium.com/@zsuperxtreme/eas...i-c84f9ea87830 um eine http-Kontrolle hinzubekommen.
Nachdem der Code unten auf den ESP32 aufgespielt wurde (upload), kann man sich am iPad mit über das Bluetooth-Menü mit dem ESP verbinden.
Danach kann man über folgende http-Befehle das iPad zum schlafen (screen off) schicken bzw. es wieder aufwecken:
http://<<IP_ESP32>>/L → sleep
http://<<IP_ESP32>>/H → wake up
Arduino-Code:
#include <BleKeyboard.h>
#include <WiFi.h>
#include <WiFiClient.h>
BleKeyboard bleKeyboard;
const char* ssid = "YourSSID";
const char* password = "YourPW";
unsigned long previousMillis = 0;
unsigned long interval = 30000;
WiFiServer server(80);
void setup() {
Serial.println("\nConnecting");
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while(WiFi.status() != WL_CONNECTED){
delay(100);
Serial.print("Local ESP32 IP: ");
Serial.println(WiFi.localIP());
Serial.print("RSSI: ");
Serial.println(WiFi.RSSI());
Serial.println("Starting BLE work!");
bleKeyboard.begin();
server.begin();
void loop() {
unsigned long currentMillis = millis();
if ((WiFi.status() != WL_CONNECTED) && (currentMillis - previousMillis >=interval)) {
Serial.println("Reconnecting to WiFi...");
WiFi.disconnect();
WiFi.reconnect();
previousMillis = currentMillis;
//get command
WiFiClient client = server.available();
if (client) {
String currentLine = "";
while (client.connected()) {
Serial.write(c);
currentLine += c;
if (currentLine.endsWith("GET /H")) {
if(bleKeyboard.isConnected()) {
bleKeyboard.print(" ");
if (currentLine.endsWith("GET /L")) {
if(bleKeyboard.isConnected()) {
bleKeyboard.press(KEY_LEFT_GUI);
bleKeyboard.press(KEY_LEFT_CTRL);
bleKeyboard.press('q');
bleKeyboard.releaseAll();
client.stop();
Serial.println("Client Disconnected.");
Kommentar