// MQTT配置文件 export const MQTT_CONFIG = { // EMQX服务器地址 broker: 'ws://122.51.194.184:8083/mqtt', // WebSocket MQTT端口 // broker: 'mqtt://122.51.194.184:1883', // 标准MQTT端口 // 连接选项 options: { clientId: 'mobile-inspection-system-' + Math.random().toString(16).substr(2, 8), // 暂时不设置账号密码 // username: '', // password: '', keepalive: 60, clean: true, reconnectPeriod: 5000, connectTimeout: 30 * 1000, }, // 主题配置 topics: { // 设备数据主题 deviceData: 'hdydcj_01_UP', // 设备类型 deviceTypes: { WSD: '温湿度', // 温湿度传感器 AC: '空调', // 空调设备 PM: 'PM2.5', // PM2.5传感器 // 可以根据需要添加更多设备类型 } } } // 数据解析工具 export const DataParser = { // 解析设备数据 parseDeviceData(rawData) { try { const data = JSON.parse(rawData) if (Array.isArray(data) && data.length > 0) { return data[0] // 取第一个设备数据 } return null } catch (error) { console.error('解析设备数据失败:', error) return null } }, // 获取设备类型名称 getDeviceTypeName(deviceCode) { return MQTT_CONFIG.topics.deviceTypes[deviceCode] || deviceCode }, // 转换Unix时间戳为可读时间 formatTimestamp(timestamp) { return new Date(timestamp * 1000).toLocaleString('zh-CN') } }