star-cloud/simulate-heartbeat.sh
sky121113 bf43a33df3 [FEAT] 整合 MQTT 資料流自動化與環境埠號修復
1. 整合 MQTT Gateway 並支援動態 Redis Key 前綴隔離,解決多環境衝突。
2. 修正本地開發環境與 Demo 環境的埠號映射 (80/8080) 與 Vite HMR (5175) 設定。
3. 更新 CI/CD 部署流程,新增自動同步程式碼至 MQTT Worker 與 Queue 容器。
4. 擴充 .env.example 以提供完整的 MQTT/EMQX 相關變數範本。
5. 更新模擬腳本以符合現有測試資料。
2026-04-17 13:22:46 +08:00

41 lines
1.4 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# =================================================================
# Star Cloud MQTT Heartbeat Simulator
# =================================================================
# 用於模擬機台每 10 秒發送一次心跳包。
# 依賴Docker (使用 eclipse-mosquitto 鏡像進行發送)
# =================================================================
SERIAL_NO="M000001"
API_TOKEN="VfFFb0DIUqtLTPF4jyCsB2h5fWsMcVxCPboNHpKc3XzRComLEK07xFYRUzBJ"
TOPIC="machine/${SERIAL_NO}/heartbeat"
NETWORK="star-cloud_sail"
BROKER_HOST="emqx"
echo "🚀 開始模擬心跳發報 [${SERIAL_NO}]..."
echo "📡 頻率:每 10 秒一次"
echo "📝 Topic: ${TOPIC}"
echo "-------------------------------------------------"
while true; do
TIMESTAMP=$(date +"%Y-%m-%dT%H:%M:%S+08:00")
PAYLOAD="{\"current_page\":2,\"firmware_version\":\"1.0.6\",\"temperature\":$(awk "BEGIN {srand(); print 20+rand()*10}")}"
echo "[${TIMESTAMP}] 正在發送心跳..."
docker run --rm --network ${NETWORK} eclipse-mosquitto \
mosquitto_pub -h ${BROKER_HOST} -p 1883 \
-u "${SERIAL_NO}" -P "${API_TOKEN}" \
-t "${TOPIC}" -m "${PAYLOAD}"
if [ $? -eq 0 ]; then
echo "✅ 發送成功"
else
echo "❌ 發送失敗,請檢查 Docker 網路或 EMQX 狀態"
fi
echo "💤 等待 10 秒..."
sleep 10
done