# 使用ESP8266 + Python 脚本实现无线群控

### 准备环境

请参考说明文档[WiFi模块（ESP8266）](https://docs.petoi.com/v/chinese/tong-xin-mo-kuai/wifi-mo-kuai-esp8266)使用 [Arduino IDE](https://www.arduino.cc/en/software) 打开示例程序（ESP8266WiFiController.ino）为ESP8266上传WiFi控制固件。

安装Python3, 并下载控制机器人的[Python脚本](https://github.com/PetoiCamp/wifi_control)

### 脚本说明

Python 3. 8及以上版本，对于type 的定义，调用语法不同。此脚本对此已做兼容，但需要您根据自己所安装的Python版本，注释、取消注释脚本中几处相应语句，例如以下脚本支持3. 8以下版本的Python:

```python
"""
In Python 3.8 and earlier, the name of the collection type is
capitalized, and the type is imported from the 'typing' module
"""
# from typing import Union, Optional             # for Python 3.9+
from typing import Union, Dict, List, Optional   # for Python 3.7
```

此脚本既可以单独只控制一个机器人，也可以实现同时控制多个机器人，可以在example.py中修改以下语句实现：

```python
# ip = "192.168.0.108"                     # for only one robot
ip = ["192.168.0.110", "192.168.0.108"]    # for multiple robots
```

### 使用方法

参照WiFi模块（ESP8266）的[使用说明](https://docs.petoi.com/v/chinese/tong-xin-mo-kuai/wifi-mo-kuai-esp8266#shi-yong-shuo-ming-que-shou-ji-jie-tu)给ESP8266分配到的IP地址后，将其插在机器人的主板上。机器人正常上电开机后，即可使用python运行脚本example.py对机器人进行无线控制。您 可以根据自己的实际需要修改以下脚本语句（修改列表内容），让机器人做出各种动作：

```python
cmds = [
        Command.sit, Command.balance, Command.stepping, Command.pee,
        Command.stop
    ]
```

目前支持的技能动作命令请参考代码文件 actions.h（在[ESP8266WiFiController](https://github.com/PetoiCamp/OpenCat/tree/main/ModuleTests/ESP8266WiFiController)中）。
