| | |
| | | String url = DEFAULT_URL; |
| | | url = url.replace("{appId}", DEFAULT_APP_ID).replace("{appsecret}", DEFAULT_APP_SECRET).replace("{cityid}", DEFAULT_CITYID); |
| | | |
| | | |
| | | log.debug("------æ°è±¡URL---{}",url); |
| | | String result = GatewayHttpUtil.doGet(url, null); |
| | | |
| | | if (null == result) { |
| | |
| | | |
| | | |
| | | public static int CODE_200 = 200; |
| | | |
| | | /** |
| | | * ä¸åæä»¤å夿¥ætopic |
| | | */ |
| | | public static String TOPIC_REPORT = "/${productId}/${deviceId}/properties/report"; |
| | | |
| | | } |
| | |
| | | import com.fzzy.gateway.hx2023.data.CloudSendData; |
| | | import com.fzzy.gateway.hx2023.data.SyncReqData; |
| | | import com.fzzy.mqtt.MqttProviderConfig; |
| | | import com.fzzy.mqtt.MqttPublishService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | |
| | | @Resource |
| | | private GatewayRemoteManager gatewayRemoteManager; |
| | | @Resource |
| | | private MqttProviderConfig providerClient; |
| | | private MqttPublishService publishService; |
| | | |
| | | |
| | | /** |
| | |
| | | |
| | | //èªå¨æ¨é |
| | | if (200 == resp.getCode() && syncReqData.isAutoReplay()) { |
| | | String topic = "/${productId}/${deviceId}/properties/report"; |
| | | String topic = ScConstant.TOPIC_REPORT; |
| | | |
| | | topic = topic.replace("${productId}", device.getProductId()).replace("${deviceId}", device.getDeviceId()); |
| | | |
| | | providerClient.publish(topic, resp.getData()); |
| | | publishService.publishMsg(topic, resp.getData()); |
| | | |
| | | log.info("=======ç²®æ
æ¨é==========={}", resp.getData()); |
| | | } |
| | |
| | | import com.fzzy.gateway.GatewayUtils; |
| | | import com.fzzy.gateway.api.DeviceReportService; |
| | | import com.fzzy.gateway.api.GatewayRemoteManager; |
| | | import com.fzzy.gateway.data.BaseResp; |
| | | import com.fzzy.gateway.entity.GatewayDevice; |
| | | import com.fzzy.gateway.hx2023.ScConstant; |
| | | import com.fzzy.gateway.hx2023.data.*; |
| | | import com.fzzy.gateway.service.repository.GatewayDeviceRep; |
| | | |
| | | import com.fzzy.mqtt.MqttProviderConfig; |
| | | import com.fzzy.mqtt.MqttPublishService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import org.apache.commons.lang.StringUtils; |
| | | import org.apache.commons.lang.time.DateFormatUtils; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.domain.Sort; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | |
| | | private GatewayRemoteManager gatewayRemoteManager; |
| | | @Resource |
| | | private MqttPublishService mqttPublishService; |
| | | @Resource |
| | | private MqttProviderConfig providerClient; |
| | | |
| | | /** |
| | | * gatewayDeviceService#listAll |
| | | * |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * gatewayDeviceService#ajaxTestWeight |
| | | * å°ç£
æ¨éæµè¯ |
| | |
| | | /** |
| | | * gatewayDeviceService#ajaxTestLpr |
| | | * å°ç£
æ¨éæµè¯ |
| | | * |
| | | * @return |
| | | */ |
| | | @Expose |
| | |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | private String pushByV40(List<GatewayDevice> list, Date start, Date end) { |
| | | |
| | | String depotIdSys; |
| | |
| | | package com.fzzy.gateway.service; |
| | | |
| | | import com.bstek.dorado.annotation.DataResolver; |
| | | import com.bstek.dorado.annotation.Expose; |
| | | import com.fzzy.api.data.GatewayDeviceType; |
| | | import com.fzzy.api.utils.ContextUtil; |
| | | import com.fzzy.gateway.GatewayUtils; |
| | | import com.fzzy.gateway.api.GatewayRemoteManager; |
| | | import com.fzzy.gateway.data.BaseResp; |
| | | import com.fzzy.gateway.entity.GatewayDevice; |
| | | import com.fzzy.gateway.hx2023.ScConstant; |
| | | import com.fzzy.gateway.hx2023.data.SyncReqData; |
| | | import com.fzzy.gateway.service.repository.GatewayDeviceRep; |
| | | import com.fzzy.mqtt.MqttProviderConfig; |
| | | import com.fzzy.mqtt.MqttPublishService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.data.domain.Sort; |
| | | import org.springframework.stereotype.Component; |
| | |
| | | import javax.annotation.Resource; |
| | | import java.util.List; |
| | | |
| | | @Slf4j |
| | | @Component |
| | | public class GatewayDeviceService2 { |
| | | |
| | | @Resource |
| | | private GatewayDeviceRep gatewayDeviceRep; |
| | | |
| | | @Resource |
| | | private GatewayRemoteManager gatewayRemoteManager; |
| | | @Resource |
| | | private MqttPublishService publishService; |
| | | |
| | | public List<GatewayDevice> listAll() { |
| | | Sort sort = new Sort(Sort.Direction.ASC, "deviceId"); |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * æµè¯MQTTç²®æ
æ£æµ |
| | | * gatewayDeviceService#ajaxTestGrain2 |
| | | * ç²®æ
æ¨éæµè¯ |
| | | * |
| | | * @param data |
| | | * @return |
| | | */ |
| | | @Expose |
| | | public String ajaxTestGrain2(GatewayDevice data) { |
| | | |
| | | SyncReqData reqData = new SyncReqData(); |
| | | reqData.setDevice(data); |
| | | reqData.setAutoReplay(true); |
| | | reqData.setMessageType(ScConstant.MESSAGE_TYPE_INVOKE_FUNCTION); |
| | | reqData.setMessageId(ScConstant.getMessageId()); |
| | | reqData.setFunctionId(ScConstant.FUNCTION_getTAndRHInfo); |
| | | |
| | | |
| | | if (!GatewayDeviceType.TYPE_07.getCode().equals(data.getType())) { |
| | | return "ERRORï¼å½å设å¤éç²®æ
设å¤ä¸æ¯æå½åæä½"; |
| | | } |
| | | |
| | | BaseResp resp = gatewayRemoteManager.getSyncGrainService(data.getSyncProtocol()).syncGrain2(reqData); |
| | | |
| | | //èªå¨æ¨é |
| | | if (200 == resp.getCode() && reqData.isAutoReplay()) { |
| | | String topic = ScConstant.TOPIC_REPORT; |
| | | topic = topic.replace("${productId}", data.getProductId()).replace("${deviceId}", data.getDeviceId()); |
| | | |
| | | publishService.publishMsg(topic, resp.getData()); |
| | | } |
| | | |
| | | log.info("=======æå¨æµè¯ç²®æ
æ¨é==========={}", resp.getData()); |
| | | |
| | | return "SUCCESSï¼æ§è¡å®æ"; |
| | | } |
| | | |
| | | } |
| | |
| | | <Property name="label">设å¤ç±»åKEY</Property> |
| | | </PropertyDef> |
| | | <PropertyDef name="cableRule"> |
| | | <Property/> |
| | | <Property></Property> |
| | | <Property name="label">å¸çº¿è§å</Property> |
| | | </PropertyDef> |
| | | <PropertyDef name="cableCir"> |
| | | <Property/> |
| | | <Property></Property> |
| | | <Property name="label">çä»å±è§å</Property> |
| | | </PropertyDef> |
| | | </DataType> |
| | |
| | | <Property name="caption">å é¤</Property> |
| | | <Property name="iconClass">fa fa-minus</Property> |
| | | <Property name="width">90</Property> |
| | | <Property name="exClassName">toolbar-button-warn</Property> |
| | | </ToolBarButton> |
| | | <Separator/> |
| | | <ToolBarButton> |
| | | <ClientEvent name="onClick">var cur = view.get("#dgMain").getCurrentItem();
 |
| | | view.get("#ajaxTestGrain").set("parameter",cur).execute(function(result){
 |
| | | $alert(result);
 |
| | | });
 |
| | | </ClientEvent> |
| | | <Property name="caption">æµè¯ç²®æ
</Property> |
| | | <Property name="iconClass">fa fa-minus</Property> |
| | | <Property name="exClassName">toolbar-button-warn</Property> |
| | | </ToolBarButton> |
| | | </ToolBar> |
| | |
| | | <Property name="service">gatewayDeviceService#delData</Property> |
| | | <Property name="confirmMessage">ç¡®å®è¦å é¤ä¹ï¼</Property> |
| | | </AjaxAction> |
| | | <AjaxAction id="ajaxTestGrain"> |
| | | <Property name="service">gatewayDeviceService2#ajaxTestGrain2</Property> |
| | | <Property name="confirmMessage">ç¡®å®è¦æå¨æ§è¡ç²®æ
ä¹ï¼</Property> |
| | | </AjaxAction> |
| | | </View> |
| | | </ViewConfig> |
| | |
| | | public void connect() { |
| | | try { |
| | | //å建MQTT客æ·ç«¯å¯¹è±¡ |
| | | client = new MqttClient(mqttProperties.getHost(), mqttProperties.getClientInId(), new MemoryPersistence()); |
| | | client = new MqttClient(mqttProperties.getHost(), mqttProperties.getClientId(), new MemoryPersistence()); |
| | | //è¿æ¥è®¾ç½® |
| | | MqttConnectOptions options = new MqttConnectOptions(); |
| | | //æ¯å¦æ¸
空sessionï¼è®¾ç½®ä¸ºfalse表示æå¡å¨ä¼ä¿ç客æ·ç«¯çè¿æ¥è®°å½ï¼å®¢æ·ç«¯éè¿ä¹åè½è·åå°æå¡å¨å¨å®¢æ·ç«¯æå¼è¿æ¥æé´æ¨éçæ¶æ¯ |
| | |
| | | //设置å¿è·³æ¶é´ åä½ä¸ºç§ï¼è¡¨ç¤ºæå¡å¨æ¯é1.5*20ç§çæ¶é´å客æ·ç«¯åéå¿è·³å¤æå®¢æ·ç«¯æ¯å¦å¨çº¿ |
| | | options.setKeepAliveInterval(20); |
| | | //设置é屿¶æ¯çè¯é¢ï¼è¥å®¢æ·ç«¯åæå¡å¨ä¹é´çè¿æ¥æå¤æå¼ï¼æå¡å¨å°åå¸å®¢æ·ç«¯çéå±ä¿¡æ¯ |
| | | options.setWill("willTopic", (mqttProperties.getClientInId() + "䏿å¡å¨æå¼è¿æ¥").getBytes(), 0, false); |
| | | options.setWill("willTopic", (mqttProperties.getClientId() + "䏿å¡å¨æå¼è¿æ¥").getBytes(), 0, false); |
| | | //设置åè° |
| | | // client.setCallback(new MqttConsumerCallBack()); |
| | | client.setCallback(mqttConsumerCallBack); |
| | |
| | | public @ResponseBody |
| | | String connect() { |
| | | client.connect(); |
| | | return mqttProperties.getClientOutId() + "è¿æ¥å°æå¡å¨"; |
| | | return mqttProperties.getClientId() + "è¿æ¥å°æå¡å¨"; |
| | | } |
| | | |
| | | @RequestMapping("/disConnect") |
| | | @ResponseBody |
| | | public String disConnect() { |
| | | client.disConnect(); |
| | | return mqttProperties.getClientOutId() + "䏿å¡å¨æå¼è¿æ¥"; |
| | | return mqttProperties.getClientId() + "䏿å¡å¨æå¼è¿æ¥"; |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | |
| | | /** |
| | | * 客æ·ç«¯Id-åå¸è
Id |
| | | * 客æ·ç«¯Id |
| | | */ |
| | | private String clientOutId; |
| | | |
| | | /** |
| | | * 客æ·ç«¯Id-被订é
è
Id |
| | | */ |
| | | private String clientInId; |
| | | |
| | | private String clientId; |
| | | |
| | | /** |
| | | * è¶
æ¶æ¶é´ |
| | |
| | | import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; |
| | | import org.eclipse.paho.client.mqttv3.MqttCallback; |
| | | import org.eclipse.paho.client.mqttv3.MqttMessage; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | @Slf4j |
| | | @Component |
| | | public class MqttProviderCallBack implements MqttCallback { |
| | | |
| | | /** |
| | |
| | | |
| | | @Autowired |
| | | private MqttProperties mqttProperties; |
| | | @Autowired |
| | | private MqttProviderCallBack mqttProviderCallBack; |
| | | /** |
| | | * 客æ·ç«¯å¯¹è±¡ |
| | | */ |
| | |
| | | public void connect(){ |
| | | try{ |
| | | //å建MQTT客æ·ç«¯å¯¹è±¡ |
| | | client = new MqttClient(mqttProperties.getHost(),mqttProperties.getClientOutId(),new MemoryPersistence()); |
| | | client = new MqttClient(mqttProperties.getHost(),mqttProperties.getClientId(),new MemoryPersistence()); |
| | | //è¿æ¥è®¾ç½® |
| | | MqttConnectOptions options = new MqttConnectOptions(); |
| | | //æ¯å¦æ¸
空sessionï¼è®¾ç½®false表示æå¡å¨ä¼ä¿ç客æ·ç«¯çè¿æ¥è®°å½ï¼è®¢é
主é¢ï¼qosï¼,客æ·ç«¯éè¿ä¹åè½è·åå°æå¡å¨å¨å®¢æ·ç«¯æå¼è¿æ¥æé´æ¨éçæ¶æ¯ |
| | |
| | | //设置å¿è·³æ¶é´ åä½ä¸ºç§ï¼è¡¨ç¤ºæå¡å¨æ¯é 1.5*20ç§çæ¶é´å客æ·ç«¯åéå¿è·³å¤æå®¢æ·ç«¯æ¯å¦å¨çº¿ |
| | | options.setKeepAliveInterval(20); |
| | | //设置é屿¶æ¯çè¯é¢ï¼è¥å®¢æ·ç«¯åæå¡å¨ä¹é´çè¿æ¥æå¤æå¼ï¼æå¡å¨å°åå¸å®¢æ·ç«¯çéå±ä¿¡æ¯ |
| | | options.setWill("willTopic",(mqttProperties.getClientOutId() + "䏿å¡å¨æå¼è¿æ¥").getBytes(),0,false); |
| | | options.setWill("willTopic",(mqttProperties.getClientId()+ "䏿å¡å¨æå¼è¿æ¥").getBytes(),0,false); |
| | | //设置åè° |
| | | client.setCallback(new MqttProviderCallBack()); |
| | | client.setCallback(mqttProviderCallBack); |
| | | client.connect(options); |
| | | } catch(MqttException e){ |
| | | e.printStackTrace(); |
| | |
| | | package com.fzzy.mqtt; |
| | | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.eclipse.paho.client.mqttv3.MqttClient; |
| | | import org.eclipse.paho.client.mqttv3.MqttConnectOptions; |
| | | import org.eclipse.paho.client.mqttv3.MqttException; |
| | | import org.eclipse.paho.client.mqttv3.MqttMessage; |
| | | import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | @Slf4j |
| | | @Service |
| | | public class MqttPublishService { |
| | | |
| | | |
| | | @Resource |
| | | private MqttProperties mqttProperties; |
| | | |
| | | private static MqttClient client ; |
| | | |
| | | |
| | | public void init() throws MqttException { |
| | | //String topic = "/device/hx-weigh-big-01/91511424746940066Y001_91511424746940066Y0010000_002_004_002_001/message/property/report"; |
| | | String username = "admin"; |
| | | String password = "admin123321"; |
| | | String clientid = "FZZY-gateway"; |
| | | String broker = "tcp://127.0.0.1:1883"; |
| | | String username = mqttProperties.getUsername(); |
| | | String password = mqttProperties.getPassword(); |
| | | String clientid = mqttProperties.getClientId(); |
| | | String broker = mqttProperties.getHost(); |
| | | //String content = " { \"headers\":{ \"productId\":\"hx-weigh-big-01\", \"keepOnlineTimeoutSeconds\":600, \"keepOnline\":true, \"deviceName\":\"å°ç£
ç§°é\" }, \"messageType\":\"REPORT_PROPERTY\", \"deviceId\":\"91511424746940066Y001_91511424746940066Y0010000_002_004_002_001\", \"properties\":{ \"weightInfo\":\"{\\\"exceed\\\":false,\\\"grossWeight\\\":3000.0,\\\"netWeight\\\":3000.0,\\\"static\\\":false,\\\"tareWeight\\\":3000.0,\\\"weightUnit\\\":\\\"KG\\\"}\" }, \"timestamp\":1698336020044 }"; |
| | | int qos = 0; |
| | | try { |
| | |
| | | } |
| | | |
| | | } |
| | | |
| | | public void publishMsg(String topic,String content) { |
| | | |
| | | // String topic = "/device/hx-weigh-big-01/91511424746940066Y001_91511424746940066Y0010000_002_004_002_001/message/property/report"; |
| | | //String content = " { \"headers\":{ \"productId\":\"hx-weigh-big-01\", \"keepOnlineTimeoutSeconds\":600, \"keepOnline\":true, \"deviceName\":\"å°ç£
ç§°é\" }, \"messageType\":\"REPORT_PROPERTY\", \"deviceId\":\"91511424746940066Y001_91511424746940066Y0010000_002_004_002_001\", \"properties\":{ \"weightInfo\":\"{\\\"exceed\\\":false,\\\"grossWeight\\\":3000.0,\\\"netWeight\\\":3000.0,\\\"static\\\":false,\\\"tareWeight\\\":3000.0,\\\"weightUnit\\\":\\\"KG\\\"}\" }, \"timestamp\":1698336020044 }"; |
| | | int qos = 0; |
| | | int qos = mqttProperties.getQos(); |
| | | |
| | | try { |
| | | // åå»ºæ¶æ¯å¹¶è®¾ç½® QoS |
| | |
| | | message.setQos(qos); |
| | | // å叿¶æ¯ |
| | | client.publish(topic, message); |
| | | System.out.println("Message published"); |
| | | System.out.println("topic: " + topic); |
| | | System.out.println("message content: " + content); |
| | | |
| | | |
| | | log.info("------------Message published-------------"); |
| | | log.info("topic: " + topic); |
| | | log.info("message content: " + content); |
| | | |
| | | // å
³éè¿æ¥ |
| | | //client.disconnect(); |
| | | // å
³é客æ·ç«¯ |
| | |
| | | host: tcp://127.0.0.1:1883 |
| | | username: admin |
| | | password: pwdmqtt.. |
| | | client-outId: fzzy-customer-id |
| | | client-inId: fzzy-6e3d92ff71b911eea5e50250f2000002 |
| | | client-id: fzzy-customer-igds-api |
| | | timeout: 10 |
| | | keep-alive-interval: 20 |
| | | max-connect-times: 5 |