| | |
| | | * WEB服务器连接MQTT服务器函数 |
| | | * @param mqttConfig yml中MQTT的配置 |
| | | */ |
| | | public void connect(MQConfig mqttConfig) throws MqttException { |
| | | public void connect(DeviceMqttConfig mqttConfig) throws MqttException { |
| | | client = new MqttClient(mqttConfig.getUrl(), mqttConfig.getClientId(), new MemoryPersistence()); |
| | | MqttConnectOptions options = getOption(mqttConfig.getUsername(), mqttConfig.getPassword(), |
| | | mqttConfig.getTimeout(), mqttConfig.getKeepAlive()); |
| | | mqttConfig.getTimeout(), mqttConfig.getKeepalive()); |
| | | MQClient.setClient(client); |
| | | //连接失败调用回调函数,重新连接 |
| | | client.setCallback(new MQCallback<Object>(this, mqttConfig)); |
| | | client.setCallback(new MQCallback(this, mqttConfig)); |
| | | if (!client.isConnected()) { |
| | | client.connect(options); |
| | | // 订阅主题 |