|
@@ -14,6 +14,8 @@ import com.welampiot.dto.*;
|
|
import com.welampiot.handle.MqttHandler;
|
|
import com.welampiot.handle.MqttHandler;
|
|
import com.welampiot.service.*;
|
|
import com.welampiot.service.*;
|
|
import com.welampiot.vo.DevEnumVO;
|
|
import com.welampiot.vo.DevEnumVO;
|
|
|
|
+import com.welampiot.vo.EventVO;
|
|
|
|
+import com.welampiot.vo.InductionConfigVO;
|
|
import com.welampiot.vo.PanelConfigVO;
|
|
import com.welampiot.vo.PanelConfigVO;
|
|
import io.ipdata.client.Ipdata;
|
|
import io.ipdata.client.Ipdata;
|
|
import io.ipdata.client.error.IpdataException;
|
|
import io.ipdata.client.error.IpdataException;
|
|
@@ -2445,6 +2447,149 @@ System.out.println(res);
|
|
return 16;
|
|
return 16;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 设置事件
|
|
|
|
+ * @param netAddr 网关地址
|
|
|
|
+ * @param macAddr 设备mac地址
|
|
|
|
+ * @param eventType 事件类型( 1:串口雷达, 2: 高电平触发)
|
|
|
|
+ * @param eventID 事件ID,0-15
|
|
|
|
+ * @param perTimes 事件间隔,每几秒上报一次数据(s)
|
|
|
|
+ * @param addSpeed 偏移量
|
|
|
|
+ * @param groupAddr 分组地址,事件触发时,发送的分组地址
|
|
|
|
+ */
|
|
|
|
+ public boolean setEventData(String netAddr, String macAddr, Integer eventType, Integer eventID,
|
|
|
|
+ Integer perTimes, Integer addSpeed, Integer groupAddr)
|
|
|
|
+ {
|
|
|
|
+ int seq = getSeq();
|
|
|
|
+ String cmd = "{\"Seq\":" + seq + ",\"CmdType\":\"SetTrigEvent\",\"DateTime\":\"" + getNowTime()
|
|
|
|
+ + "\",\"CmdData\":{\"Mac\":\"" + macAddr + "\",\"EventType\":" + eventType +
|
|
|
|
+ ",\"EventID\":" + eventID + ",\"PerTimes\":" + perTimes + ",\"AddSpeed\":" +
|
|
|
|
+ addSpeed + ",\"GroupAddr\":" + groupAddr + ",\"StartTime\":0,\"EndTime\":1440}}";
|
|
|
|
+ String sendTopic = "/MESHGW/commandIn/" + netAddr;
|
|
|
|
+ String backTopic = "/MESHGW/commandOut/" + netAddr;
|
|
|
|
+ String backResult = sendMqttCmd(sendTopic, cmd, backTopic);
|
|
|
|
+ return check2p4BackResult(backResult);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取事件配置
|
|
|
|
+ */
|
|
|
|
+ public EventVO getEventData(String netAddr, String macAddr) {
|
|
|
|
+ int seq = getSeq();
|
|
|
|
+ String cmd = "{\"Seq\":" + seq + ",\"CmdType\":\"GetTrigEvent\",\"DateTime\":\"" + getNowTime()
|
|
|
|
+ + "\",\"CmdData\":{\"Mac\":\"" + macAddr + "\"}}";
|
|
|
|
+ String sendTopic = "/MESHGW/commandIn/" + netAddr;
|
|
|
|
+ String backTopic = "/MESHGW/commandOut/" + netAddr;
|
|
|
|
+ String backResult = sendMqttCmd(sendTopic, cmd, backTopic);
|
|
|
|
+
|
|
|
|
+ EventVO eventVO = new EventVO();
|
|
|
|
+ eventVO.setEventType(1);
|
|
|
|
+ eventVO.setEventID(0);
|
|
|
|
+ eventVO.setPerTimes(0);
|
|
|
|
+ eventVO.setAddSpeed(0);
|
|
|
|
+ eventVO.setGroupAddr(0);
|
|
|
|
+ eventVO.setStartTime("00:00");
|
|
|
|
+ eventVO.setEndTime("24:00");
|
|
|
|
+
|
|
|
|
+ if (backResult.isEmpty()) return eventVO;
|
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(backResult);
|
|
|
|
+ if (!jsonObject.containsKey("CmdRsp")) return eventVO;
|
|
|
|
+ JSONObject cmdRsp = (JSONObject) jsonObject.get("CmdRsp");
|
|
|
|
+ if (cmdRsp.isEmpty()) return eventVO;
|
|
|
|
+ Integer eventType = cmdRsp.getInteger("EventType");
|
|
|
|
+ if (eventType != null) eventVO.setEventType(eventType);
|
|
|
|
+ Integer eventID = cmdRsp.getInteger("EventID");
|
|
|
|
+ if (eventID != null) eventVO.setEventID(eventID);
|
|
|
|
+ Integer perTimes = cmdRsp.getInteger("PerTimes");
|
|
|
|
+ if (perTimes != null) eventVO.setPerTimes(perTimes);
|
|
|
|
+ Integer addSpeed = cmdRsp.getInteger("AddSpeed");
|
|
|
|
+ if (addSpeed != null) eventVO.setAddSpeed(addSpeed);
|
|
|
|
+ Integer groupAddr = cmdRsp.getInteger("GroupAddr");
|
|
|
|
+ if (groupAddr != null) eventVO.setGroupAddr(groupAddr);
|
|
|
|
+ return eventVO;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取感应配置
|
|
|
|
+ */
|
|
|
|
+ public InductionConfigVO getInductionConfig(String netAddr, String macAddr) {
|
|
|
|
+ int seq = getSeq();
|
|
|
|
+ String cmd = "{\"Seq\":" + seq + ",\"CmdType\":\"GetMicroWave\",\"DateTime\":\"" + getNowTime()
|
|
|
|
+ + "\",\"CmdData\":{\"Mac\":\"" + macAddr + "\"}}";
|
|
|
|
+ String sendTopic = "/MESHGW/commandIn/" + netAddr;
|
|
|
|
+ String backTopic = "/MESHGW/commandOut/" + netAddr;
|
|
|
|
+ String backResult = sendMqttCmd(sendTopic, cmd, backTopic);
|
|
|
|
+
|
|
|
|
+ InductionConfigVO inductionConfigVO = new InductionConfigVO();
|
|
|
|
+ inductionConfigVO.setEnable(0);
|
|
|
|
+ inductionConfigVO.setSensitivity(1);
|
|
|
|
+ inductionConfigVO.setOnLight(0);
|
|
|
|
+ inductionConfigVO.setOffLight(0);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if (backResult.isEmpty()) return inductionConfigVO;
|
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(backResult);
|
|
|
|
+ if (!jsonObject.containsKey("CmdRsp")) return inductionConfigVO;
|
|
|
|
+ JSONObject cmdRsp = (JSONObject) jsonObject.get("CmdRsp");
|
|
|
|
+ if (cmdRsp.isEmpty()) return inductionConfigVO;
|
|
|
|
+ Integer enable = cmdRsp.getInteger("Enable");
|
|
|
|
+ if (enable != null) inductionConfigVO.setEnable(enable);
|
|
|
|
+ Integer sensitivity = cmdRsp.getInteger("Sensitivity");
|
|
|
|
+ if (sensitivity != null) inductionConfigVO.setSensitivity(sensitivity);
|
|
|
|
+ Integer onLight = cmdRsp.getInteger("OnLight");
|
|
|
|
+ if (onLight != null) inductionConfigVO.setOnLight(onLight);
|
|
|
|
+ Integer offLight = cmdRsp.getInteger("OffLight");
|
|
|
|
+ if (offLight != null) inductionConfigVO.setOffLight(offLight);
|
|
|
|
+ return inductionConfigVO;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 设置感应配置
|
|
|
|
+ */
|
|
|
|
+ public boolean setInductionConfig(String netAddr, String macAddr, Integer enable, Integer sensitivity,
|
|
|
|
+ Integer onLight, Integer offLight)
|
|
|
|
+ {
|
|
|
|
+ int seq = getSeq();
|
|
|
|
+ String cmd = "{\"Seq\":" + seq + ",\"CmdType\":\"SetMicroWave\",\"DateTime\":\"" + getNowTime()
|
|
|
|
+ + "\",\"CmdData\":{\"Mac\":\"" + macAddr + "\",\"Enable\":" + enable + ",\"Sensitivity\":" + sensitivity
|
|
|
|
+ + ",\"Onlight\":" + onLight + ",\"Offlight\":" + offLight + "}}";
|
|
|
|
+ String sendTopic = "/MESHGW/commandIn/" + netAddr;
|
|
|
|
+ String backTopic = "/MESHGW/commandOut/" + netAddr;
|
|
|
|
+ String backResult = sendMqttCmd(sendTopic, cmd, backTopic);
|
|
|
|
+ return check2p4BackResult(backResult);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 刷新数据
|
|
|
|
+ */
|
|
|
|
+ public boolean refreshData(String netAddr, String macAddr) {
|
|
|
|
+ int seq = getSeq();
|
|
|
|
+ String cmd = "{\"Seq\":" + seq + ",\"CmdType\":\"RealReport\",\"DateTime\":\"" + getNowTime() +
|
|
|
|
+ "\",\"CmdData\":{\"Mac\":\""+ macAddr +"\"}}";
|
|
|
|
+ String sendTopic = "/MESHGW/commandIn/" + netAddr;
|
|
|
|
+ String backTopic = "/MESHGW/commandOut/" + netAddr;
|
|
|
|
+ String backResult = sendMqttCmd(sendTopic, cmd, backTopic);
|
|
|
|
+ return check2p4BackResult(backResult);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 获取光照度
|
|
|
|
+ */
|
|
|
|
+ public Integer getIlluminanceValue(String netAddr, String macAddr) {
|
|
|
|
+ int seq = getSeq();
|
|
|
|
+ String cmd = "{\"Seq\":" + seq + ",\"CmdType\":\"GetIlluValue\",\"DateTime\":\"" + getNowTime() +
|
|
|
|
+ "\",\"CmdData\":{\"Mac\":\""+ macAddr +"\"}}";
|
|
|
|
+ String sendTopic = "/MESHGW/commandIn/" + netAddr;
|
|
|
|
+ String backTopic = "/MESHGW/commandOut/" + netAddr;
|
|
|
|
+ String backResult = sendMqttCmd(sendTopic, cmd, backTopic);
|
|
|
|
+ if (backResult.isEmpty()) return -1;
|
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(backResult);
|
|
|
|
+ if (!jsonObject.containsKey("CmdRsp")) return -1;
|
|
|
|
+ JSONObject cmdRsp = jsonObject.getJSONObject("CmdRsp");
|
|
|
|
+ if (cmdRsp.isEmpty() || !cmdRsp.containsKey("Illu")) return -1;
|
|
|
|
+ return cmdRsp.getInteger("Illu");
|
|
|
|
+ }
|
|
|
|
+
|
|
public static void main(String[] args) {
|
|
public static void main(String[] args) {
|
|
System.out.println(getPublicIp());
|
|
System.out.println(getPublicIp());
|
|
System.out.println(formatNumber(0.0));
|
|
System.out.println(formatNumber(0.0));
|