# 使用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)中）。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.petoi.com/chinese/tong-xin-mo-kuai/wifi-mo-kuai-esp8266/shi-yong-esp8266-+-python-jiao-ben-shi-xian-wu-xian-qun-kong.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
