This is the Go server for the Mochi animatronics project. It brings expressive robot eyes and quirky sounds to life, inspired by Huy Vector's video. It optionally generates the emotions using GenAI (Gemini).
Inspired by: Huy Vector - Build Your Own Dasai Mochi Robot
-
Listens for a Trigger: The server runs on
localhost:5000and waits for aGETrequest on its/touchendpoint. This request is sent by the ESP32 client when its touch sensor is activated. -
Generates Animatronics Data: Upon receiving a request, the server generates data for an animation and a corresponding sound.
- Online Mode: If a
GEMINI_API_KEYis set as an environment variable, the server sends a creative prompt to the Gemini API to generate a unique, emotionally expressive animation and sound. - Offline Mode: If the API key is not available, it falls back to a
collection of pre-defined animations and sounds stored in
builtin.json.
- Online Mode: If a
-
Sends Data to Client: The server encodes the generated data into a compact hex format and sends it to the ESP32 client (expected at
http://localhost:5001) via twoPOSTrequests:/draw: Sends the eye animation data./play: Sends the sound data.
The generation and sending process runs in a background goroutine, allowing the server to respond instantly to the ESP32's touch request.
- Go (version 1.21 or newer).
- The Mochi ESP32 Client set up and running on your network.
- Server Port: The server runs on port
5000by default. - Client Address: The server sends data to the ESP32 client at
http://localhost:5001. - These values can be modified by changing the
serverPortandendpointBaseURLconstants inmain.go.
-
Clone the repository:
git clone https://github.com/dzonder/mochi-server.git cd mochi-server -
(Optional) Online Mode: To enable real-time AI generation, set your Gemini API key:
# For PowerShell $env:GEMINI_API_KEY="YOUR_API_KEY" # For Bash/Zsh export GEMINI_API_KEY="YOUR_API_KEY"
-
Run the server:
go run .
The server is now running and waiting for a trigger from the ESP32 client.
