How priess0503/wxmqtt works
Project type and purpose
• This is a WeChat Mini Program (front-end client) for IoT device remote control and monitoring, built on the MQTT protocol.
• It supports multiple sensor/actuator types (temperature, humidity, switches, motors, WS2812b LED strips, soil, water quality, wind speed) and can integrate with Home Assistant.
File structure
• Top-level:
• app.js / app.json / app.wxss – global app configuration & styles
• pages/… – each page is an MVC triad: .wxml (view), .wxss (styles), .js (logic), .json (config)
• utils/mqtt.js – MQTT client wrapper (connect, subscribe, publish)
• utils/util.js, utils/wxcharts.js – helpers (formatting, chart rendering)
• images/, package-*, node_modules/ – assets & dependencies
• project.config*.json, jsconfig.json – IDE/build configs
• No backend code here: the Mini Program directly uses wss:// to connect to an external MQTT broker.
README for additional insights
• Describes supported device data formats (JSON payloads, command topics).
• Mentions prerequisites: WeChat appid, custom MQTT server over wss, domain备案.
• Shows sample UI flows and Home Assistant sync.
Main components
a. WeChat Mini Program (Client)
• UI Layer (pages/index, pages/device, pages/logs, pages/mqtt, pages/view)
• Business Logic (page controllers, util.js)
• MQTT Module (utils/mqtt.js)
b. External MQTT Broker (wss://)
c. IoT Devices
• Sensors (temp/humidity, water, soil, wind)
• Actuators (relays, motors, WS2812b LEDs, servos)
d. Third-Party Integration – Home Assistant (optional subscriber/publisher)
Relationships and interactions
• The client’s MQTT Module establishes a secure WebSocket (wss://) connection to the MQTT Broker.
• UI pages publish commands to device-specific topics; devices subscribe to those topics and act.
• Devices publish telemetry to topics; client subscribes and updates the UI (charts, logs).
• Home Assistant also subscribes/publishes to the same broker for cross-integration.
Architectural patterns & design principles
• MVC pattern in each Mini Program page (View: .wxml/.wxss, Controller: .js, Model: JSON data)
• Single responsibility: utils/mqtt.js encapsulates all MQTT logic; util.js for data formatting; wxcharts.js for visualization.
• Event-driven & pub/sub via MQTT topics.
Relevant technologies & libraries
• WeChat Mini Program framework (WXML, WXSS, JS)
• MQTT over Secure WebSockets (wss://)
• wxCharts for charting
• JSON for configuration & payloads