Skip to content

Commit

Permalink
fix: 修复app打开后即使连接了mqtt也会通过udp与设备通信一次
Browse files Browse the repository at this point in the history
fix: 优化设备离线时app log中信息提示内容
fix: 修复zM1设备log中无显示设备在线/离线状态的问题
  • Loading branch information
a2633063 committed Dec 16, 2020
1 parent 1abd614 commit 1addb49
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public void Receive(String ip, int port, String topic, String message) {
String device_mac = matcher.group(2);
if (device_mac.equals(device.getMac())) {
device.setOnline(message.equals("1"));
Log(device.isOnline() ? "设备在线" : "设备离线" + "(功能调试中)");
Log(device.isOnline() ? "设备在线" : "设备离线" + "(请确认设备是否有连接mqtt服务器)");
}
return;
}
Expand Down Expand Up @@ -253,7 +253,7 @@ public void Receive(String ip, int port, String topic, String message) {
//region 事件监听调用函数,主要为在子类中重写此函数实现在service建立成功/mqtt连接成功/失败时执行功能
//Service建立成功时调用 此函数需要时在子类中重写
public void ServiceConnected() {
handler.sendEmptyMessageDelayed(1, 0);
handler.sendEmptyMessageDelayed(1, 300);
}

//mqtt连接成功时调用 此函数需要时在子类中重写
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public void Receive(String ip, int port, String topic, String message) {
String device_mac = matcher.group(2);
if (device_mac.equals(device.getMac())) {
device.setOnline(message.equals("1"));
Log(device.isOnline() ? "设备在线" : "设备离线" + "(功能调试中)");
Log(device.isOnline() ? "设备在线" : "设备离线" + "(请确认设备是否有连接mqtt服务器)");
}
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public void Receive(String ip, int port, String topic, String message) {
String device_mac = matcher.group(2);
if (device_mac.equals(device.getMac())) {
device.setOnline(message.equals("1"));
Log(device.isOnline() ? "设备在线" : "设备离线" + "(功能调试中)");
Log(device.isOnline() ? "设备在线" : "设备离线" + "(请确认设备是否有连接mqtt服务器)");
}
return;
}
Expand Down Expand Up @@ -245,7 +245,7 @@ public void Receive(String ip, int port, String topic, String message) {
//region 事件监听调用函数,主要为在子类中重写此函数实现在service建立成功/mqtt连接成功/失败时执行功能
//Service建立成功时调用 此函数需要时在子类中重写
public void ServiceConnected() {
handler.sendEmptyMessageDelayed(1, 0);
handler.sendEmptyMessageDelayed(1, 300);
}

//mqtt连接成功时调用 此函数需要时在子类中重写
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public void Receive(String ip, int port, String topic, String message) {
String device_mac = matcher.group(2);
if (device_mac.equals(device.getMac())) {
device.setOnline(message.equals("1"));
Log(device.isOnline() ? "设备在线" : "设备离线" + "(功能调试中)");
Log(device.isOnline() ? "设备在线" : "设备离线" + "(请确认设备是否有连接mqtt服务器)");
}
return;
}
Expand Down Expand Up @@ -247,7 +247,7 @@ public void Receive(String ip, int port, String topic, String message) {
//region 事件监听调用函数,主要为在子类中重写此函数实现在service建立成功/mqtt连接成功/失败时执行功能
//Service建立成功时调用 此函数需要时在子类中重写
public void ServiceConnected() {
handler.sendEmptyMessageDelayed(1, 0);
handler.sendEmptyMessageDelayed(1, 300);
}

//mqtt连接成功时调用 此函数需要时在子类中重写
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public void Receive(String ip, int port, String topic, String message) {
String device_mac = matcher.group(2);
if (device_mac.equals(device.getMac())) {
device.setOnline(message.equals("1"));
Log(device.isOnline() ? "设备在线" : "设备离线" + "(功能调试中)");
Log(device.isOnline() ? "设备在线" : "设备离线" + "(请确认设备是否有连接mqtt服务器)");
}
return;
}
Expand Down Expand Up @@ -272,7 +272,7 @@ public void Receive(String ip, int port, String topic, String message) {
//region 事件监听调用函数,主要为在子类中重写此函数实现在service建立成功/mqtt连接成功/失败时执行功能
//Service建立成功时调用 此函数需要时在子类中重写
public void ServiceConnected() {
handler.sendEmptyMessageDelayed(1, 0);
handler.sendEmptyMessageDelayed(1, 300);
}

//mqtt连接成功时调用 此函数需要时在子类中重写
Expand Down
20 changes: 18 additions & 2 deletions app/src/main/java/com/zyc/zcontrol/deviceItem/m1/M1Fragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* A simple {@link Fragment} subclass.
Expand Down Expand Up @@ -183,7 +185,21 @@ void Send(String message) {
//数据接收处理更新函数
public void Receive(String ip, int port, String topic, String message) {
super.Receive(ip, port, topic, message);

//region 接收availability数据,非Json,单独处理
if (topic != null && topic.endsWith("availability")) {
String regexp = "device/(.*?)/([0123456789abcdef]{12})/(.*)";
Pattern pattern = Pattern.compile(regexp);
Matcher matcher = pattern.matcher(topic);
if (matcher.find() && matcher.groupCount() == 3) {
String device_mac = matcher.group(2);
if (device_mac.equals(device.getMac())) {
device.setOnline(message.equals("1"));
Log(device.isOnline() ? "设备在线" : "设备离线" + "(请确认设备是否有连接mqtt服务器)");
}
return;
}
}
//endregion
try {
JSONObject jsonObject = new JSONObject(message);
if (!jsonObject.has("mac") || !jsonObject.getString("mac").equals(device.getMac())) {
Expand Down Expand Up @@ -248,7 +264,7 @@ public void Receive(String ip, int port, String topic, String message) {
//region 事件监听调用函数,主要为在子类中重写此函数实现在service建立成功/mqtt连接成功/失败时执行功能
//Service建立成功时调用 此函数需要时在子类中重写
public void ServiceConnected() {
handler.sendEmptyMessageDelayed(1, 0);
handler.sendEmptyMessageDelayed(1, 300);
}

//mqtt连接成功时调用 此函数需要时在子类中重写
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ public void Receive(String ip, int port, String topic, String message) {
String device_mac = matcher.group(2);
if (device_mac.equals(device.getMac())) {
device.setOnline(message.equals("1"));
Log(device.isOnline() ? "设备在线" : "设备离线");
Log(device.isOnline() ? "设备在线" : "设备离线"+ "(请确认设备是否有连接mqtt服务器)");
if (device.isOnline()) {
handler.sendEmptyMessageDelayed(1, 0);
}
Expand Down Expand Up @@ -514,7 +514,7 @@ public void Receive(String ip, int port, String topic, String message) {
//region 事件监听调用函数,主要为在子类中重写此函数实现在service建立成功/mqtt连接成功/失败时执行功能
//Service建立成功时调用 此函数需要时在子类中重写
public void ServiceConnected() {
handler.sendEmptyMessageDelayed(1, 0);
handler.sendEmptyMessageDelayed(1, 300);
}

//mqtt连接成功时调用 此函数需要时在子类中重写
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public void Receive(String ip, int port, String topic, String message) {
String device_mac = matcher.group(2);
if (device_mac.equals(device.getMac())) {
device.setOnline(message.equals("1"));
Log(device.isOnline() ? "设备在线" : "设备离线" + "(功能调试中)");
Log(device.isOnline() ? "设备在线" : "设备离线" + "(请确认设备是否有连接mqtt服务器)");
}
return;
}
Expand Down Expand Up @@ -226,7 +226,7 @@ public void Receive(String ip, int port, String topic, String message) {
//region 事件监听调用函数,主要为在子类中重写此函数实现在service建立成功/mqtt连接成功/失败时执行功能
//Service建立成功时调用 此函数需要时在子类中重写
public void ServiceConnected() {
handler.sendEmptyMessageDelayed(1, 0);
handler.sendEmptyMessageDelayed(1, 300);
}

//mqtt连接成功时调用 此函数需要时在子类中重写
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ else if (bat_level < battery_res.length / 2)
//region 事件监听调用函数,主要为在子类中重写此函数实现在service建立成功/mqtt连接成功/失败时执行功能
//Service建立成功时调用 此函数需要时在子类中重写
public void ServiceConnected() {
handler.sendEmptyMessageDelayed(1, 0);
handler.sendEmptyMessageDelayed(1, 300);
}

//mqtt连接成功时调用 此函数需要时在子类中重写
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ public void Receive(String ip, int port, String topic, String message) {
String device_mac = matcher.group(2);
if (device_mac.equals(device.getMac())) {
device.setOnline(message.equals("1"));
Log(device.isOnline() ? "设备在线" : "设备离线" + "(功能调试中)");
Log(device.isOnline() ? "设备在线" : "设备离线" + "(请确认设备是否有连接mqtt服务器)");
}
return;
}
Expand Down Expand Up @@ -461,7 +461,7 @@ public void Receive(String ip, int port, String topic, String message) {
//region 事件监听调用函数,主要为在子类中重写此函数实现在service建立成功/mqtt连接成功/失败时执行功能
//Service建立成功时调用 此函数需要时在子类中重写
public void ServiceConnected() {
handler.sendEmptyMessageDelayed(1, 0);
handler.sendEmptyMessageDelayed(1, 300);
}

//mqtt连接成功时调用 此函数需要时在子类中重写
Expand Down

0 comments on commit 1addb49

Please sign in to comment.