B站:https://space.bilibili.com/309103931

中移4G模块-ML302专栏:https://blog.csdn.net/qq_33259323/category_10453372.html

中移4G模块-ML302文集:https://www.bilibili.com/read/readlist/rl328642

中移4G模块-ML302-OpenCpu开发-服务器搭建

https://blog.csdn.net/qq_33259323/article/details/108960799

https://www.bilibili.com/read/cv7880356

模块:ML302-OpenCpu

MQTT平台:阿里云

后端:Java,SpringBoot等

使用开发工具:IDEA

1. pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.3.4.RELEASE</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.mm.iot</groupId><artifactId>iotdemo</artifactId><version>0.0.1-SNAPSHOT</version><name>iotdemo</name><description>Demo project for Spring Boot</description><properties><java.version>1.8</java.version></properties><dependencies><!-- 阿里云IOT SDK aliyun-java-sdk-iot --><dependency><groupId>com.aliyun</groupId><artifactId>aliyun-java-sdk-iot</artifactId><version>7.13.0</version></dependency><!-- 阿里云公共包 --><dependency><groupId>com.aliyun</groupId><artifactId>aliyun-java-sdk-core</artifactId><version>4.5.6</version></dependency><!-- 小辣椒 --><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.16.18</version></dependency><!-- web --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!-- json --><dependency><groupId>net.sf.json-lib</groupId><artifactId>json-lib</artifactId><version>2.4</version><classifier>jdk15</classifier></dependency><!-- 测试 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><!-- 热部署 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><scope>runtime</scope></dependency><dependency><groupId>org.testng</groupId><artifactId>testng</artifactId><version>RELEASE</version><scope>compile</scope></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope><exclusions><exclusion><groupId>org.junit.vintage</groupId><artifactId>junit-vintage-engine</artifactId></exclusion></exclusions></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>

2.项目目录

3.项目yaml配置

server:port: 8085
spring:resources:static-locations: classpath:/iot/dist

4.阿里云IOT客户端配置bean

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;@Configuration
public class AliIOTConfig {private static final String ACCESSKEY = "xxx";private static final String ACCESSSECRET = "yyy";/*** 默认AliIOTConfig* @return*/@Primary@Beanpublic DefaultAcsClient restTemplate() throws ClientException {DefaultProfile.addEndpoint("cn-shanghai", "cn-shanghai", "Iot", "iot.cn-shanghai.aliyuncs.com");IClientProfile profile = DefaultProfile.getProfile("cn-shanghai", ACCESSKEY, ACCESSSECRET);DefaultAcsClient client = new DefaultAcsClient(profile); //初始化SDK客户端。return client;}}

5.Test模拟发送数据给设备

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.iot.model.v20180120.PubRequest;
import com.aliyuncs.iot.model.v20180120.PubResponse;
import net.sf.json.JSONObject;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.Hex;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.io.IOException;@RunWith(SpringRunner.class)
@SpringBootTest
public class IotdemoApplicationTests {@Autowiredprivate DefaultAcsClient defaultAcsClient;@Testvoid send() throws DecoderException {JSONObject data = new JSONObject();data.put("gpio_out_a",255);data.put("gpio_out_b",255);PubRequest request = new PubRequest();request.setProductKey("XXXXXXX");request.setMessageContent(Base64.encodeBase64String((data.toString()).getBytes()));request.setTopicFullName("/a1fkKLo7NeH/YYYYYYYYYYYY/user/uart");request.setQos(0); //目前支持QoS0和QoS1。try {PubResponse response = defaultAcsClient.getAcsResponse(request);System.out.println(response);//System.out.println(response.getSuccess());//System.out.println(response.getErrorMessage());} catch (ServerException e) {e.printStackTrace();} catch (ClientException e) {e.printStackTrace();}}
}

中移4G模块-ML302-OpenCpu开发-服务器搭建相关推荐

  1. 中移4G模块-ML302-OpenCpu开发-(MQTT连接阿里云-订阅主题)

    B站:https://space.bilibili.com/309103931 中移4G模块-ML302专栏:https://blog.csdn.net/qq_33259323/category_10 ...

  2. 中移4G模块-ML302-OpenCpu开发-ADC

    B站:https://space.bilibili.com/309103931 中移4G模块-ML302专栏:https://blog.csdn.net/qq_33259323/category_10 ...

  3. 中移4G模块-ML302-OpenCpu开发-串口开发

    B站:https://space.bilibili.com/309103931 中移4G模块-ML302专栏:https://blog.csdn.net/qq_33259323/category_10 ...

  4. 中移4G模块-ML302-OpenCpu开发-(MQTT连接阿里云-RRPC通讯)

    B站:https://space.bilibili.com/309103931 中移4G模块-ML302专栏:https://blog.csdn.net/qq_33259323/category_10 ...

  5. 中移4G模块-ML302-OpenCpu开发-2-MQTT连接阿里云

    B站:https://space.bilibili.com/309103931 中移4G模块-ML302专栏:https://blog.csdn.net/qq_33259323/category_10 ...

  6. 中移4G模块-ML302-OpenCpu开发-(固件编译和烧录)

    B站:https://space.bilibili.com/309103931 中移4G模块-ML302专栏:https://blog.csdn.net/qq_33259323/category_10 ...

  7. 中移4G模块-ML302-OpenCpu开发-PCF8591测量电压

    B站:https://space.bilibili.com/309103931 中移4G模块-ML302专栏:https://blog.csdn.net/qq_33259323/category_10 ...

  8. 中移4G模块-ML302-OpenCpu开发-MCP23017输入/输出

    B站:https://space.bilibili.com/309103931 中移4G模块-ML302专栏:https://blog.csdn.net/qq_33259323/category_10 ...

  9. 中移4G模块-ML302-OpenCpu开发-HTTP

    B站:https://space.bilibili.com/309103931 中移4G模块-ML302专栏:https://blog.csdn.net/qq_33259323/category_10 ...

最新文章

  1. [转]EOS智能合约 私链激活 基本操作
  2. 解决android 异常导致应用程序停止运行的错误
  3. linux 下一个 osw先从操作系统和标准脚本主动发起
  4. python 关于排序的问题
  5. Linux之提高Nginx的安全性:受限server_tokens /user_agents/buffer_size/连接数/请求方法/外链/不用模块 使用日志/TLS/HTTPS/升级
  6. 如何自动打开function对应的ABAP class
  7. Qt元对象QMetaObject的indexOfSlot等函数获取类方法注意问题
  8. 【openMV】openMV之测距
  9. Java 中关键字transient引出序列化与反序列化
  10. 剑指Offer之复杂链表的复制
  11. 程序人生:程序员做外包“前途“,“技术“,“经验“如何决策
  12. 使用HTML制作在线电子时钟,用HTML5制作数字时钟的教程
  13. SOCK_STREAM与SOCK_DGRAM套接口类型
  14. kubectl rollout restart重启pod
  15. 计算机管理格式化没有顺利完成,格式化没有顺利完成怎么办?
  16. 运行uniapp跳转微信开发工具后一直卡在微信开发工具首页的解决方法
  17. NTP调整系统时间同步
  18. Redhat最小化安装后再安装图形界面
  19. 用Delphi自制英语复读机
  20. 图像处理——Fast AutoAugment

热门文章

  1. react中form可以嵌套一个form吗_Ant-Design从v3升级到v4的Form适配
  2. 深度学习backbone是什么意思_一场突如其来的讨论:到底什么是深度学习?SVM其实也是深度学习吗?...
  3. UE4的MaterialInstance作用
  4. 锁和并发性----隔离级别
  5. 图(网)的存储结构(数组存储表示即邻接矩阵、邻接表)
  6. Log4j2架构分析与实战
  7. IOS推送消息怎么实现icon图标的数字累加
  8. 利用圆解一元二次方程
  9. 学会判断Web安全网关的性能
  10. 必背42个单词_高中英语必背100个常考单词,考试必考