Skip to content

Commit

Permalink
🐛 the mqtt connection configuration is lost
Browse files Browse the repository at this point in the history
  • Loading branch information
sanshengshui committed Oct 15, 2023
1 parent 099906a commit 478b284
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,15 @@ public static boolean notExistOrContents(String fileName) {

public static void updateAllFileContents(String fileName, List<String> bodyList) {
try {
Files.write(Paths.get(fileName), bodyList, StandardCharsets.UTF_8);
StringBuilder content = new StringBuilder();
if (!bodyList.isEmpty()) {
bodyList.forEach(body -> {
content.append(body).append(System.lineSeparator());
});
}
//overlay update
Files.write(Path.of(fileName), content.toString().getBytes());

} catch (IOException e) {
System.out.format("fileName updateAllFileContents failed!!!");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public boolean mqttProcessorAfterLogic(String code, MqttConfigSettingsDomain dom
domain.setClient(mqttClientService);
//write settings to file
MqttSettings settings = domain.convertMqttSettingsJsonString();
settings.setUsage(0);
settings.setUsage(1);
FileUtils.writeDataToFile(SystemConfigConst.MQTT_SETTINGS_FILE_NAME, JsonUtils.object2Json(settings));

// add settings config, not enter into sub terminal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void updateAllMqttConfigsByUsage(MqttSettings waitUpdateSettings, Integer
waitUpdateSettings.setSettingTime(System.currentTimeMillis());
}
settingsList.add(waitUpdateSettings);
settingsList.stream().forEach(st -> {
settingsList.forEach(st -> {
if (st.getSettingTime() == null) {
st.setSettingTime(System.currentTimeMillis());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ public boolean call(MqttShellModeDomain domain, Terminal terminal) {
MqttClientCallback clientCallback = new MqttClientCallback() {
@Override
public void connectionLost(DisReason reason) {
mqttSettingService.updateAllMqttConfigsByUsage(domain.getSettings(), 0);
if (reason.getActionType().equals(0)) {
mqttSettingService.updateAllMqttConfigsByUsage(domain.getSettings(), 0);
StringBuilder sb = new StringBuilder();
sb.append(StringUtils.lineSeparator);
sb.append("Server Unavailable" + String.format(EmojiEnum.disconnectEmoji));
Expand All @@ -110,6 +110,7 @@ public void onSuccessfulReconnect() {
String data = reader.readLine(prompt);
context.setData(data);
if (data.equals("exit")) {
isEnd = false;
mqttSettingService.updateAllMqttConfigsByUsage(domain.getSettings(), 0);
domain.getClient().disconnect(1);
return false;
Expand Down

0 comments on commit 478b284

Please sign in to comment.