iPad - Wake und Sleep via ESP32 bluetooth Keyboard & http-command

Einklappen
X
 
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge
  • MarkusCosi
    LoxBus Spammer
    • 28.09.2023
    • 222

    #1

    iPad - Wake und Sleep via ESP32 bluetooth Keyboard & http-command

    Hallo zusammen,

    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.begin(9600);

    Serial.println("\nConnecting");
    WiFi.mode(WIFI_STA);
    WiFi.begin(ssid, password);
    while(WiFi.status() != WL_CONNECTED){
    Serial.print(".");
    delay(100);
    }
    Serial.println("\nConnected to the WiFi network");
    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() {
    // if WiFi is down, try reconnecting every CHECK_WIFI_TIME seconds
    unsigned long currentMillis = millis();
    if ((WiFi.status() != WL_CONNECTED) && (currentMillis - previousMillis >=interval)) {
    Serial.print(millis());
    Serial.println("Reconnecting to WiFi...");
    WiFi.disconnect();
    WiFi.reconnect();
    previousMillis = currentMillis;
    }

    //get command
    WiFiClient client = server.available();
    if (client) {
    Serial.println("New Client.");
    String currentLine = "";
    while (client.connected()) {
    if (client.available()) {
    char c = client.read();
    Serial.write(c);
    currentLine += c;
    if (currentLine.endsWith("GET /H")) {
    Serial.println("Wake Up connected Apple Device");
    if(bleKeyboard.isConnected()) {
    Serial.println("Power ON: send Space");
    bleKeyboard.print(" ");
    }
    }
    if (currentLine.endsWith("GET /L")) {
    Serial.println("Put connected Apple Device to sleep");
    if(bleKeyboard.isConnected()) {
    Serial.println("Power OFF: Sending CTRL+CMD+h key...");
    bleKeyboard.press(KEY_LEFT_GUI);
    bleKeyboard.press(KEY_LEFT_CTRL);
    bleKeyboard.press('q');
    bleKeyboard.releaseAll();
    }
    }
    }
    }
    client.stop();
    Serial.println("Client Disconnected.");
    }
    }​
  • hismastersvoice
    Supermoderator
    • 25.08.2015
    • 7319

    #2
    ...und warum nicht managed Tablets in der Config nutzen?

    Da geht das doch ohne andere Hardware.
    Kein Support per PN!

    Kommentar

    • MarkusCosi
      LoxBus Spammer
      • 28.09.2023
      • 222

      #3
      ...das hat bei mir den Bildschirm nicht ganz dunkel gemacht...

      Kommentar

      Lädt...