| | |
| | | const appPath = process.pkg ? path.dirname(process.execPath) : __dirname; |
| | | const mqttConfigPath = path.join(appPath, 'mqtt.json'); |
| | | const aliyunConfigPath = path.join(appPath, 'aliyun.json'); |
| | | const httpConfigPath = path.join(appPath, 'httpConfig.json'); |
| | | |
| | | const mqttConfig = JSON.parse(fs.readFileSync(mqttConfigPath, 'utf8')); |
| | | const aliyunConfig=JSON.parse(fs.readFileSync(aliyunConfigPath, 'utf8')) |
| | | const httpConfig = JSON.parse(fs.readFileSync(httpConfigPath, 'utf8')); |
| | | |
| | | |
| | | console.log(aliyunConfig) |
| | |
| | | const aliyunIot = require('aliyun-iot-device-sdk'); |
| | | const { getAliyunDeviceSecret } = require('./api'); |
| | | const toModel = require('./Strholp'); |
| | | const dataCache = require('./dataCache'); |
| | | const HttpServer = require('./httpServer'); |
| | | |
| | | // 初始化 MQTT(独立于阿里云) |
| | | initMqtt(mqttConfig); |
| | |
| | | const masData = toModel(message); |
| | | deviceInfo.iotDeviceNo = masData.n; |
| | | deviceInfo.masData = masData; |
| | | |
| | | // ✅【新增】缓存数据到内存(按设备序号) |
| | | dataCache.setDeviceData(masData.n, masData); |
| | | |
| | | // ✅【核心改动】收到数据立即发 MQTT(不管阿里云) |
| | | if (mqttConfig.enabled) { |
| | | const topic = `${mqttConfig.defaultTopicPrefix}/${masData.n}`; |
| | |
| | | const PORT = process.env.PORT || 10961; |
| | | server.listen(PORT, () => { |
| | | logger.info(`Socket 服务已启动,监听超级端口: ${PORT}`); |
| | | }); |
| | | }); |
| | | |
| | | // ========== 启动 HTTP 服务 ========== |
| | | const HTTP_PORT = process.env.HTTP_PORT || httpConfig.port || 8080; |
| | | const httpServer = new HttpServer(HTTP_PORT, httpConfig); |
| | | httpServer.start(); |