Station2 - #12
Conversation
… sketches, and .gitignore.
feat: Add initial M5Paper activity selection UI, other M5Stack device…
ตอนนี้รอstickC เลยทำเป็นแบบกดechoแล้วส่งrequestไปcore2 แต่เขียนให้รับค่าrequestจากmatrixไว้แล้ว
ให้echo request to core2
There was a problem hiding this comment.
Pull request overview
This PR adds Station2 functionality to a Web3 Showcase IoT project, implementing an authentication system using M5Stack devices. The changes introduce communication between multiple ESP32-based devices (M5StickPlus2, Atom Matrix, Atom Echo, Core2) via WiFi, HTTP, ESP-NOW, and BLE protocols.
Key Changes:
- Implementation of Station2 authentication workflow across Matrix, Echo, and Core2 monitor devices
- Addition of M5StickPlus2 wearable device code for user identity and coin management
- Configuration of shared networking protocols and IP address mappings
- Integration of BLE-based proximity detection and ESP-NOW messaging
Reviewed changes
Copilot reviewed 31 out of 32 changed files in this pull request and generated 15 comments.
Show a summary per file
| File | Description |
|---|---|
| m5stickplus2/m5stickplus2.ino | StickPlus2 wearable device handling user registration, authentication status, and coin balance |
| Station2-Matrix/src/main.cpp | Atom Matrix sensor triggering authentication via button press and WiFi scanning |
| Station2-Matrix/src/main(matrix-2).cpp | Alternative Matrix implementation using BLE scanning and ESP-NOW communication |
| Station2-Echo/src/main.cpp | Atom Echo audio controller playing authentication and transaction sounds |
| Station2-Echo/echo1/echo1.ino | Alternative Echo implementation with ESP-NOW state machine for sound sequences |
| Station2-Core2/src/main.cpp | Core2 monitor displaying authentication status and user information |
| Station2-Matrix/lib/ProjectShared/config.h | Shared network configuration including IP addresses and endpoints |
| Station2-Matrix/include/ShowcaseProtocol.h | Protocol definitions for ESP-NOW messaging with checksums |
| Station2-Matrix/platformio.ini | PlatformIO configuration for Matrix with M5Atom dependencies |
| Station2-Echo/platformio.ini | PlatformIO configuration for Echo with M5Unified library |
| Station2-Core2/platformio.ini | PlatformIO configuration for Core2 with async web server |
| M5Paper/M5Paper.ino | E-paper interface for activity selection and coin earning |
| Atom_echo/Atom_echo.ino | Standalone Echo device with I2S audio and ESP-NOW trigger |
| Atom-matrix | Standalone Matrix with BLE scanning and proximity-based authentication |
| .gitignore | Standard macOS .DS_Store exclusion |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| String alertText = "Waiting for Identity..."; | ||
|
|
||
| // --- UI DATA --- | ||
| // ตัวแปรสำหรับเก็บ MAC Address ของตัวเอง (ใช้ในการอ้างอิงสำหรับ Atom Matrix ใน Station 2) |
There was a problem hiding this comment.
[nitpick] The comment uses inconsistent naming for M5Stack devices. Line 21 refers to "StickC-Plus2" but other parts of the codebase and the file structure use "StickPlus2" (without the hyphen). Consider using consistent naming throughout the codebase.
| server.on(ENDPOINT_PLAY_AUTH, HTTP_POST, handlePlayAuth); | ||
| server.on(ENDPOINT_PLAY_TX_SUCCESS, HTTP_POST, handlePlayTx); | ||
| server.on(ENDPOINT_RESET_USER, HTTP_POST, handleSystemReset); |
There was a problem hiding this comment.
The endpoints ENDPOINT_PLAY_TX_SUCCESS and ENDPOINT_RESET_USER are referenced but not defined in config.h. This will cause compilation errors. The config.h file only defines ENDPOINT_HEARTBEAT, ENDPOINT_SET_USER, ENDPOINT_SET_AUTH, ENDPOINT_RESET_GLOBAL, ENDPOINT_EARN_COIN, ENDPOINT_SPEND_COIN, and ENDPOINT_GET_ORDER.
| Serial.begin(115200); | ||
|
|
||
| // กำหนด Static IP | ||
| WiFi.config(IP_ATOM_ECHO, IP_CORE2, IPAddress(255, 255, 255, 0)); |
There was a problem hiding this comment.
Inconsistent IP address usage. Line 91 references IP_CORE2 which is not defined in config.h. According to the config.h file, the correct IP address constant for the Core2 station is IP_STATION1_AP. This will cause a compilation error.
| WiFi.config(IP_ATOM_ECHO, IP_CORE2, IPAddress(255, 255, 255, 0)); | |
| WiFi.config(IP_ATOM_ECHO, IP_STATION1_AP, IPAddress(255, 255, 255, 0)); |
|
|
||
| // 2. RSSI Trigger: ตรวจจับสัญญาณ StickC | ||
| static unsigned long lastScan = 0; | ||
| if (millis() - lastScan > 3000 && !isAuthInProgress) { // Scan ทุก 3 วิ |
There was a problem hiding this comment.
[nitpick] The comment on line 80 suggests this is a "3 วิ" (3 second) scan interval, but the actual code checks for a 3000ms (3 second) interval. The Thai comment is correct, but it would be clearer to note that "3 วิ" = "3000ms" for consistency.
| if (millis() - lastScan > 3000 && !isAuthInProgress) { // Scan ทุก 3 วิ | |
| if (millis() - lastScan > 3000 && !isAuthInProgress) { // Scan ทุก 3 วิ (3000ms) |
| http.setTimeout(2000); | ||
|
|
||
| // 1. สั่ง Atom Echo เล่นเสียง | ||
| http.begin("http://" + IP_ATOM_ECHO.toString() + ENDPOINT_PLAY_AUTH); |
There was a problem hiding this comment.
The endpoint ENDPOINT_PLAY_AUTH is referenced but not defined in config.h. This will cause a compilation error. The config.h file only defines ENDPOINT_HEARTBEAT, ENDPOINT_SET_USER, ENDPOINT_SET_AUTH, ENDPOINT_RESET_GLOBAL, ENDPOINT_EARN_COIN, ENDPOINT_SPEND_COIN, and ENDPOINT_GET_ORDER.
| } | ||
|
|
||
| void handleSystemReset(AsyncWebServerRequest *request) { | ||
| M5.Speaker.end(); // หยุดเสียงที่กำลังเล่น |
There was a problem hiding this comment.
The M5.Speaker.end() method is called to stop the speaker, but according to the M5Atom documentation, the correct method is M5.Speaker.stop(). This inconsistency with the proper API usage may cause unexpected behavior.
| M5.dis.drawpix(0, 0x000000); delay(200); | ||
| } | ||
| // เชื่อมต่อแล้ว (ไฟสีเขียวแวบหนึ่ง) | ||
| WiFi.config(IP_ATOM_MATRIX_S2, IP_STATION1_AP, NETMASK, IP_STATION1_AP); |
There was a problem hiding this comment.
The IP address mapping is inconsistent. Line 58 references IP_ATOM_MATRIX_S2 which is not defined in config.h. The config.h file defines IP_ATOM_MATRIX instead. This will cause a compilation error.
| WiFi.config(IP_ATOM_MATRIX_S2, IP_STATION1_AP, NETMASK, IP_STATION1_AP); | |
| WiFi.config(IP_ATOM_MATRIX, IP_STATION1_AP, NETMASK, IP_STATION1_AP); |
| #include <M5Atom.h> | ||
| #include <WiFi.h> | ||
| #include <HTTPClient.h> | ||
| #include <ESPAsyncWebServer.h> | ||
| #include "config.h" |
There was a problem hiding this comment.
Missing #include <HTTPClient.h> at the top of the file. The code uses HTTPClient class in lines 23-39 but doesn't include the necessary header file, which will cause compilation errors.
| HTTPClient http; | ||
| // Notify Core2 (Monitor) | ||
| http.begin(String("http://") + IP_CORE2.toString() + ENDPOINT_SET_AUTH); | ||
| http.POST("{}"); | ||
| http.end(); | ||
|
|
||
| // Notify StickC-Plus2 (Wearable) | ||
| http.begin(String("http://") + IP_STICKC.toString() + ENDPOINT_SET_AUTH); | ||
| http.POST("{}"); | ||
| http.end(); |
There was a problem hiding this comment.
The endpoint ENDPOINT_PLAY_AUTH is used but not defined in config.h. Additionally, the referenced IP addresses IP_CORE2 and IP_STICKC don't exist in config.h - the correct names are IP_STATION1_AP and IP_STICKC respectively. This will cause compilation errors.
| esp_wifi_set_channel(1, WIFI_SECOND_CHAN_NONE); | ||
|
|
||
| if (esp_now_init() != ESP_OK) { | ||
| Serial.println("ESR-NOW Init Failed"); |
There was a problem hiding this comment.
Typo in error message: "ESR-NOW" should be "ESP-NOW". This is inconsistent with the rest of the codebase which correctly uses "ESP-NOW".
| Serial.println("ESR-NOW Init Failed"); | |
| Serial.println("ESP-NOW Init Failed"); |
Refactor main.cpp to include ESP-NOW functionality and improve authentication display.
No description provided.