> For the complete documentation index, see [llms.txt](https://docs.petoi.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.petoi.com/thai/communication-modules/wifi-esp8266/esp8266-+-python-scripts-implement-wireless-crowd-control.md).

# ESP8266 + Python Scripts Implement wireless crowd control

### Setup environment

โปรดอ้างอิงคำแนะนำของ [WiFi ESP8266](https://docs.petoi.com/communication-modules/wifi-esp8266) และใช้ [Arduino IDE](https://www.arduino.cc/en/software) เพื่อเปิดโปรแกรมตัวอย่าง (ESP8266WiFiController.ino) เพื่ออัปโหลดเฟิร์มแวร์ควบคุม WiFi สำหรับโมดูล ESP8266

Install Python3, and download [the Python scripts](https://github.com/PetoiCamp/wifi_control) to control the robot.

### Script introduction

สำหรับ Python เวอร์ชัน 3.8 ขึ้นไป มีการเปลี่ยนแปลง Syntax ในการกำหนด Type ของตัวแปร สคริปต์นี้สามารถใช้งานได้แต่ต้อง comment และ uncomment หลายคำสั่งที่เกี่ยวข้องตามรุ่นของ Python ที่คุณได้ติดตั้งไว้ ตัวอย่างเช่นสคริปต์ด้านล่างนี้รองรับ Python เวอร์ชันต่ำกว่า 3.8:

```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
```

### How to Use

อ้างอิงถึง [the instruction](https://docs.petoi.com/communication-modules/wifi-esp8266#how-to-use) ให้กำหนด IP address ของโมดูล ESP8266 ผ่าน WiFi และนำมาต่อกับบอร์ดหลักของหุ่นยนต์ หลังจากนั้นเมื่อเปิดเครื่องหุ่นยนต์แล้ว คุณสามารถใช้ python เพื่อรันสคริปต์ example.py เพื่อควบคุมหุ่นยนต์ได้ผ่านวิธีไร้สาย คุณสามารถปรับแต่งคำสั่งในสคริปต์ต่อไปนี้ (แก้ไขเนื้อหาของ list) ตามความต้องการจริงของคุณ เพื่อให้หุ่นยนต์ทำการแสดงพฤติกรรมต่างๆ ได้:

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

สำหรับคำสั่งการกระทำที่รองรับในปัจจุบันโปรดดูที่ไฟล์โค้ด actions.h(in [ESP8266WiFiController](https://github.com/PetoiCamp/OpenCat/tree/main/ModuleTests/ESP8266WiFiController)).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.petoi.com/thai/communication-modules/wifi-esp8266/esp8266-+-python-scripts-implement-wireless-crowd-control.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
