中移4G模块-ML302-OpenCpu开发-服务器搭建
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开发-服务器搭建相关推荐
- 中移4G模块-ML302-OpenCpu开发-(MQTT连接阿里云-订阅主题)
B站:https://space.bilibili.com/309103931 中移4G模块-ML302专栏:https://blog.csdn.net/qq_33259323/category_10 ...
- 中移4G模块-ML302-OpenCpu开发-ADC
B站:https://space.bilibili.com/309103931 中移4G模块-ML302专栏:https://blog.csdn.net/qq_33259323/category_10 ...
- 中移4G模块-ML302-OpenCpu开发-串口开发
B站:https://space.bilibili.com/309103931 中移4G模块-ML302专栏:https://blog.csdn.net/qq_33259323/category_10 ...
- 中移4G模块-ML302-OpenCpu开发-(MQTT连接阿里云-RRPC通讯)
B站:https://space.bilibili.com/309103931 中移4G模块-ML302专栏:https://blog.csdn.net/qq_33259323/category_10 ...
- 中移4G模块-ML302-OpenCpu开发-2-MQTT连接阿里云
B站:https://space.bilibili.com/309103931 中移4G模块-ML302专栏:https://blog.csdn.net/qq_33259323/category_10 ...
- 中移4G模块-ML302-OpenCpu开发-(固件编译和烧录)
B站:https://space.bilibili.com/309103931 中移4G模块-ML302专栏:https://blog.csdn.net/qq_33259323/category_10 ...
- 中移4G模块-ML302-OpenCpu开发-PCF8591测量电压
B站:https://space.bilibili.com/309103931 中移4G模块-ML302专栏:https://blog.csdn.net/qq_33259323/category_10 ...
- 中移4G模块-ML302-OpenCpu开发-MCP23017输入/输出
B站:https://space.bilibili.com/309103931 中移4G模块-ML302专栏:https://blog.csdn.net/qq_33259323/category_10 ...
- 中移4G模块-ML302-OpenCpu开发-HTTP
B站:https://space.bilibili.com/309103931 中移4G模块-ML302专栏:https://blog.csdn.net/qq_33259323/category_10 ...
最新文章
- [转]EOS智能合约 私链激活 基本操作
- 解决android 异常导致应用程序停止运行的错误
- linux 下一个 osw先从操作系统和标准脚本主动发起
- python 关于排序的问题
- Linux之提高Nginx的安全性:受限server_tokens /user_agents/buffer_size/连接数/请求方法/外链/不用模块 使用日志/TLS/HTTPS/升级
- 如何自动打开function对应的ABAP class
- Qt元对象QMetaObject的indexOfSlot等函数获取类方法注意问题
- 【openMV】openMV之测距
- Java 中关键字transient引出序列化与反序列化
- 剑指Offer之复杂链表的复制
- 程序人生:程序员做外包“前途“,“技术“,“经验“如何决策
- 使用HTML制作在线电子时钟,用HTML5制作数字时钟的教程
- SOCK_STREAM与SOCK_DGRAM套接口类型
- kubectl rollout restart重启pod
- 计算机管理格式化没有顺利完成,格式化没有顺利完成怎么办?
- 运行uniapp跳转微信开发工具后一直卡在微信开发工具首页的解决方法
- NTP调整系统时间同步
- Redhat最小化安装后再安装图形界面
- 用Delphi自制英语复读机
- 图像处理——Fast AutoAugment