Wisdom Parking (four) IOT selection - Ali cloud Things

Disclaimer: This article is a blogger original article, follow the CC 4.0 by-sa copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/u012898231/article/details/96149577

In fact, electricity keepsake networking hardware and software side of the core protocol platform has opened up, taking into account the latter part of the platform in the country to put in parking spaces, which is used in addition to the middle of telecom cards, but will surely be used in mobile, linkage and telecommunications in order to avoid things not compatible platform, Ali decided to use cloud of things platform.

Before doing shook his car project is used before Ali cloud communications MQTT used to do things, then we use the information provided MQTT belong to the primary data filtering can convert queue, support for device data is filtered and converted, then transfer to other business. I remember Ali cloud offerings on a piece of messaging middleware product called MQ message queue, and then choose to use MQ category in the inside, such as RocketMQ, Kafka, AMQP, MQTT these, the beginning of which we used MQTT ( MQTT was still in the beta stage, no charge), and then shook his car project 2.0 platform we use RocketMQ used for distributed transactions. This is now outside Ali cloud offerings messaging middleware products have several points of the forum.

MQTT usage scenarios for our software and hardware is simply here to communicate the message through the middle layer of publication and subscription, so the software and hardware are at both ends of the operation can be provided by SDK MQTT, it is quite simple to use and Ali cloud background MQTT there are simple visual interface, operating status monitoring equipment available, such as online, offline and statistical reports.

 Hardware Engineer Chen found me, say former friends recommended Ali cloud of Things platform, the beginning I always thought he said that I had a message queue MQ inside MQTT (now called: micro message queue for IoT), but in fact not the same product. To be honest, the first time into the things Ali cloud platform inside when a bit ignorant than half would not have been clear before the Internet of Things platform and used MQTT what's the difference?

 

 

看起来貌似功能有点强悍,最关键的是可能配置一大堆。我知道,这又将是一个漫长的学习过程了。中间断断续续花了一天的时候,将产品文档从头到位看了篇,中间又看不懂的,有重点关注的,也有一拖而过的,最后总结下。

阿里云物联网平台为设备提供安全可靠的连接通信能力,向下连接海量设备,支撑设备数据采集上云;向上提供云端API,指令数据通过API调用下发至设备端,实现远程控制。物联网平台也提供了其他增值能力,如设备管理、规则引擎、数据分析、边缘计算等,为各类IoT场景和行业开发者赋能。简单来讲:设备接入方面,有提供设备端SDK,快速连接设备上云,效率高。同时支持全球设备接入、异构网络设备接入、多环境下设备接入、多协议设备接入。另外还有使用性能,可以支持具有亿级设备的长连接能力、百万级并发的能力,架构支撑水平性扩展。安全方面,提供多重防护保障设备云端安全,设备认证保障设备安全等等。

具体的东西要在后面使用过程中慢慢体会了,硬件连接那边(设备端开发)陈工在弄,我重点关注下软件这边(云端开发),找到java sdk相关使用文档和demo,基本一会就能跑起来,还是算简单。云端提供的API非常丰富,少说也有60个左右。

 不要慌,后面用到什么再来查相关API使用即可,前期我比较关注的API有两个,一个是下发指令,一个是上报数据,讲白了就是发送数据和接收数据。

1.发送数据

 

重点关注下RRpc这个API。之前我们用MQTT采用的是发布和订阅模式,也就是说软件发指令给硬件,都是走的异步的模式,发完指定后,订阅消息,然后通过消息来判断并做下步业务,这个RRpc从名字来看就是RPC调用,使用起来简化了很多。

public static void rrpcTest(String productKey, String deviceName, String msg) {
        RRpcRequest request = new RRpcRequest();
        request.setProductKey(productKey);
        request.setDeviceName(deviceName);
        request.setRequestBase64Byte(Base64.encodeBase64String(msg.getBytes()));
        request.setTimeout(5000);
        RRpcResponse response = (RRpcResponse)executeTest(request);
        if (response != null && response.getSuccess() != false) {
            LogUtil.print("rrpc消息发送成功!messageId:" + response.getMessageId() + ",payloadBase64Byte:" + new String(
                Base64.decodeBase64(response.getPayloadBase64Byte())));
        } else {
            LogUtil.error("rrpc消息发送失败!requestId:" + response.getRequestId() + "原因:" + response.getErrorMessage());

        }

    }

2.接收数据

 

在工程启动的时候初始化连接并开始监听消息。

  @PostConstruct  
    public void recvMsg(){
		subscribe();
    }
private void subscribe(){
        try {
            String accessKey = accessKeyID;//阿里云accessKey
            String accessSecret = accessKeySecret;//阿里云accessSecret
            String regionId = itoRegionId;//regionId
            String uid = userUID;//阿里云uid          
            String endPoint = "https://" + uid + ".iot-as-http2." + regionId + ".aliyuncs.com";//endPoint:https://${uid}.iot-as-http2.${region}.aliyuncs.com
            
 
 
            Profile profile = Profile.getAccessKeyProfile(endPoint, regionId, accessKey, accessSecret); //连接配置
            MessageClient client = MessageClientFactory.messageClient(profile);//构造客户端

            // 数据接收
            client.connect(messageToken -> {
                Message m = messageToken.getMessage();
                System.out.println("receive message from " + m);
                return MessageCallback.Action.CommitSuccess;
            });
        	
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

 

 

 

Guess you like

Origin blog.csdn.net/u012898231/article/details/96149577