Go to file
Jens Weimann 03be46fabb Merge branch 'main' of https://github.com/jensweimann/esphome_ducky into main 2023-10-03 11:58:25 +02:00
esphome Init import 2022-01-09 17:13:48 +01:00
homeassistant Init import 2022-01-09 17:13:48 +01:00
include Init import 2022-01-09 17:13:48 +01:00
lib Init import 2022-01-09 17:13:48 +01:00
src improve mouse control, refactor 2023-10-03 11:58:18 +02:00
.gitignore Init import 2022-01-09 17:13:48 +01:00
LICENSE Initial commit 2022-01-07 13:30:57 +01:00
README.md Update README.md 2022-01-21 17:44:52 +01:00
esphome_ducky.jpg Init import 2022-01-09 17:13:48 +01:00
platformio.ini improve mouse control, refactor 2023-10-03 11:58:18 +02:00

README.md

ESPHome Ducky

What is it?

Control devices with a virtual usb keyboard/mouse from mqtt.

How does it work?

  • The arduino is emulating HIDs (Human Interface Devices) such as keyboard/mouse via USB
  • The ESPHome board is receiving commands via wifi/mqtt and writes them to the serial port
  • The commands are in Ducky Script syntax
  • The commands are read from the serial port by the arduino and executed as keyboard/mouse actions
  • Furthermore it's possible to get the host machine's power state from the USB state via the serial port

Credits:

Buy Me A Coffee

Community

https://community.home-assistant.io/t/esphome-ducky/377600

Get Started

1. You will need

1.1 Software

1.2 Hardware

2. Wiring

This is mostly taken from the wifi_ducky project:

Arduino Esp8266
TX RX
RX TX
GND GND
VCC (5V) Vin
RST (Optional) D4

Pay attention to not mix up 5V from Arduino and 3.3V of ESP8266. Also do not connect both boards simultaneously via USB since one board is passing power to the other.

Example: Arduino Pro Micro and NodeMCU

3. Flashing

3.1 Visual Studio Code

3.2 ESPHome

4. Usage

Send the ducky payload to the mqtt topic. For mqtt topic definition, see esphome/nodemcu.yaml

Ducky Script syntax: https://docs.hak5.org/hc/en-us/articles/360010555153-Ducky-Script-the-USB-Rubber-Ducky-language

4.1 Example Call from Home Assistant

service: mqtt.publish
data:
  topic: esphome/nodemcu/run
  payload: |
    GUI r
    DELAY 200
    STRING notepad.exe
    ENTER
    DELAY 200
    STRING Hello World

4.2 Home Assitant Examples

4.3 Sensors

  • host_state: Host/usb port power state (ON/OFF/SLEEP)
  • nodemcu_response: Ducky scripts execution feedback (ready/busy), usefull for observing long running scripts
  • usb_input: Receive messages from arduinos serial port, usefull for custom feedback messages from connected machine

Limitations:

  • I don't have much time to support this project
  • I don't have much experience in this topic so the code is improvable
  • The current implementation may be not 100% compatible with all possible ducky keywords, but most commands should be working.
  • It is possible that some machines won't recognize this device since it's emulating multiple HID devices. I never had such issues but your mileage may vary
  • One message is limited to 255 characters including line endings
  • Mouse movement is mostly untestet
  • Gamepad support is possible but currently not implemented, see https://github.com/NicoHood/HID/wiki/Gamepad-API