# MyBot API Cheat Sheet

This document lists the available HTTP GET endpoints to control your MyBot via its local web server. You can trigger these directly from your browser, via `curl`, using Python scripts, or using top-level links (`<a href="...">`).

**Base URL**: `http://mybot5.local:80` (Replace `5` with your specific bot's number).

---

## ⚡ Hardware Queue & Buffer Limits

MyBot has two hardware queue systems to prevent memory starvation and ensure smooth execution:

1. **API Schedule Queue (`/schedule`)**: Maximum **8 scheduled actions** (`MAX_SCHEDULED_ACTIONS` in `board_config.h`). If more than 8 actions are scheduled before the current ones execute, subsequent commands will be dropped.
2. **Internal Action Queue (`s_queue`)**: The background FreeRTOS task handles up to **4 concurrent actions/animations**. 

> **Best Practice**: Always add a `delay` or space out commands in loops to stay within queue limits.

---

## 🚀 Mission Script (MScript) Batch Execution

For running multi-step routines in a single browser click without CORS or HTTPS issues:

- **Endpoint**: `GET /api/mission?m=COMMAND1|COMMAND2|COMMAND3` (or `GET /mission?m=...`)
- **Example**: `http://mybot5.local/api/mission?m=l1on|delay:1000|servo:1:90|oled:Hello`
- **Supported Tokens**:
  - `l1on`, `l1off`, `toggle` — Status LED
  - `grnon`, `grnoff`, `redon`, `redoff` — External LEDs
  - `s1on`, `s1off`, `servo:num:angle` — Servo movements (e.g. `servo:1:90`)
  - `delay:ms` or `wait:ms` — Non-blocking pause (e.g. `delay:1000`)
  - `oled:text` or `msg:text` — Display text on OLED screen
  - `anim_mario`, `anim_fireworks`, `anim_matrix` — OLED Animations

---

## 💡 LED Control
- **Status LED Turn ON**: `GET /l1on` or `GET /led?state=on`
- **Status LED Turn OFF**: `GET /l1off` or `GET /led?state=off`
- **Status LED Toggle**: `GET /toggle` or `GET /led?state=toggle`

## 🔴🟢 External LED Control
- **Green LED**: `GET /grnon`, `GET /grnoff`, `GET /grntog`
- **Red LED**: `GET /redon`, `GET /redoff`, `GET /redtog`

## 🔧 Servo Control
- **Move to Angle**: `GET /servo?num=1&angle=90` (Hold position)
- **Quick Action (Stepped)**: `GET /s1on` (Moves to ON position at medium speed, then returns to neutral and detaches)
- **Manual Angle (URI style)**: `GET /s1_120` (Sets servo 1 to 120° and holds)
- **Quick Actions list**: `s1on`, `s1off`, `s2on`, `s2off`
- **Random Look Mode**: `GET /random_look?on=1` — Enables life-like random servo + OLED behaviors.

## 🕒 Scheduling (For Synchronized Events!)
You can queue an action to happen at an exact Unix timestamp across all bots simultaneously, or after a relative delay (Up to **8 max** scheduled at once).

- **Run after delay**: `GET /schedule?action=toggle&delay=5`
- **Run at exact time**: `GET /schedule?action=l1on&at=1714000000`
- **Schedule text-to-speech**: `GET /schedule?action=tts:Hello&delay=10`

## 🎵 Buzzer Control
- **Play Tone**: `GET /tone?f=1000&d=100`
- **Play Demo Melody**: `GET /demo?type=coin`

## ⏱️ System & Status
- **Get Status**: `GET /status`
- **Get Time**: `GET /time`

---

## 🕹️ Fun OLED Animations via API
- **Dancing Mario**: `GET /anim_mario`
- **Fireworks**: `GET /anim_fireworks`
- **Matrix Rain**: `GET /anim_matrix`
- **Space Invaders parade**: `GET /anim_invader`
- **Heartbeat/Love**: `GET /anim_heartbeat`
- **Return to Eyes**: `GET /game_off`
- **🥱 Big Yawn**: `GET /big_yawn`

---

*Tip: You can test any of these by just typing them into your browser's address bar! Example: `http://mybot5.local/anim_mario`*
