Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
黄嘉阳
/
iot-platform-server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
98596986
authored
Sep 11, 2023
by
huangjy
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
feat,添加mqtt订阅
parent
d9920102
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
10 additions
and
10 deletions
server-common/src/main/java/com/makeit/module/iot/mqtt/DeviceInfo.java → server-web/src/main/java/com/makeit/mqtt/DeviceInfo.java
server-common/src/main/java/com/makeit/module/iot/mqtt/HeaderInfo.java → server-web/src/main/java/com/makeit/mqtt/HeaderInfo.java
server-common/src/main/java/com/makeit/module/iot/mqtt/MqttConfig.java → server-web/src/main/java/com/makeit/mqtt/MqttConfig.java
server-common/src/main/java/com/makeit/module/iot/mqtt/MqttPushClient.java → server-web/src/main/java/com/makeit/mqtt/MqttPushClient.java
server-common/src/main/java/com/makeit/module/iot/mqtt/PushCallback.java → server-web/src/main/java/com/makeit/mqtt/PushCallback.java
server-web/src/main/resources/application-dev.yml
server-web/src/main/resources/application-test.yml
server-web/src/test/java/com/makeit/iotapi/IotTest.java
server-
common/src/main/java/com/makeit/module/io
t/mqtt/DeviceInfo.java
→
server-
web/src/main/java/com/makei
t/mqtt/DeviceInfo.java
View file @
98596986
package
com
.
makeit
.
m
odule
.
iot
.
m
qtt
;
package
com
.
makeit
.
mqtt
;
import
lombok.Data
;
import
lombok.Data
;
...
...
server-
common/src/main/java/com/makeit/module/io
t/mqtt/HeaderInfo.java
→
server-
web/src/main/java/com/makei
t/mqtt/HeaderInfo.java
View file @
98596986
package
com
.
makeit
.
m
odule
.
iot
.
m
qtt
;
package
com
.
makeit
.
mqtt
;
import
lombok.Data
;
import
lombok.Data
;
...
...
server-
common/src/main/java/com/makeit/module/io
t/mqtt/MqttConfig.java
→
server-
web/src/main/java/com/makei
t/mqtt/MqttConfig.java
View file @
98596986
package
com
.
makeit
.
m
odule
.
iot
.
m
qtt
;
package
com
.
makeit
.
mqtt
;
import
com.makeit.module.iot.service.IotTokenService
;
import
com.makeit.module.iot.service.IotTokenService
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
...
@@ -49,7 +49,7 @@ public class MqttConfig {
...
@@ -49,7 +49,7 @@ public class MqttConfig {
clientId
=
StringUtils
.
isNotEmpty
(
iotToken
)
?
iotToken
:
clientId
;
clientId
=
StringUtils
.
isNotEmpty
(
iotToken
)
?
iotToken
:
clientId
;
mqttPushClient
.
connect
(
hostUrl
,
clientId
,
username
,
password
,
timeout
,
keepalive
);
mqttPushClient
.
connect
(
hostUrl
,
clientId
,
username
,
password
,
timeout
,
keepalive
);
// 订阅主题
// 订阅主题
mqttPushClient
.
subscribe
(
"/device/*/*/**"
,
0
);
mqttPushClient
.
subscribe
(
defaultTopic
,
0
);
return
mqttPushClient
;
return
mqttPushClient
;
}
}
...
...
server-
common/src/main/java/com/makeit/module/io
t/mqtt/MqttPushClient.java
→
server-
web/src/main/java/com/makei
t/mqtt/MqttPushClient.java
View file @
98596986
package
com
.
makeit
.
m
odule
.
iot
.
m
qtt
;
package
com
.
makeit
.
mqtt
;
import
org.eclipse.paho.client.mqttv3.*
;
import
org.eclipse.paho.client.mqttv3.*
;
import
org.eclipse.paho.client.mqttv3.persist.MemoryPersistence
;
import
org.eclipse.paho.client.mqttv3.persist.MemoryPersistence
;
...
@@ -85,7 +85,7 @@ public class MqttPushClient {
...
@@ -85,7 +85,7 @@ public class MqttPushClient {
}
}
public
void
subscribe
(
String
defaultTopic
,
int
qos
)
{
public
void
subscribe
(
String
defaultTopic
,
int
qos
)
{
logger
.
info
(
"开始订阅主题"
+
defaultTopic
);
logger
.
info
(
"开始订阅主题
:
"
+
defaultTopic
);
try
{
try
{
MqttPushClient
.
getMqttClient
().
subscribe
(
defaultTopic
,
qos
);
MqttPushClient
.
getMqttClient
().
subscribe
(
defaultTopic
,
qos
);
}
catch
(
MqttException
e
)
{
}
catch
(
MqttException
e
)
{
...
...
server-
common/src/main/java/com/makeit/module/io
t/mqtt/PushCallback.java
→
server-
web/src/main/java/com/makei
t/mqtt/PushCallback.java
View file @
98596986
package
com
.
makeit
.
m
odule
.
iot
.
m
qtt
;
package
com
.
makeit
.
mqtt
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
org.eclipse.paho.client.mqttv3.IMqttDeliveryToken
;
import
org.eclipse.paho.client.mqttv3.IMqttDeliveryToken
;
...
...
server-web/src/main/resources/application-dev.yml
View file @
98596986
...
@@ -116,7 +116,7 @@ mqtt:
...
@@ -116,7 +116,7 @@ mqtt:
password
:
8e3795ef7b5e95869fa8c323b865b3a9
password
:
8e3795ef7b5e95869fa8c323b865b3a9
hostUrl
:
tcp://124.71.33.17:11883
hostUrl
:
tcp://124.71.33.17:11883
clientId
:
ab3a2fd694c8c838aba2686df3a80e7b
clientId
:
ab3a2fd694c8c838aba2686df3a80e7b
defaultTopic
:
defaultTopic
:
/device/*/*/**
timeout
:
10
timeout
:
10
keepalive
:
60
keepalive
:
60
...
...
server-web/src/main/resources/application-test.yml
View file @
98596986
...
@@ -113,7 +113,7 @@ mqtt:
...
@@ -113,7 +113,7 @@ mqtt:
password
:
8e3795ef7b5e95869fa8c323b865b3a9
password
:
8e3795ef7b5e95869fa8c323b865b3a9
hostUrl
:
tcp://124.71.33.17:11883
hostUrl
:
tcp://124.71.33.17:11883
clientId
:
ab3a2fd694c8c838aba2686df3a80e7b
clientId
:
ab3a2fd694c8c838aba2686df3a80e7b
defaultTopic
:
defaultTopic
:
/device/*/*/**
timeout
:
10
timeout
:
10
keepalive
:
60
keepalive
:
60
...
...
server-web/src/test/java/com/makeit/iotapi/IotTest.java
View file @
98596986
...
@@ -59,7 +59,7 @@ public class IotTest {
...
@@ -59,7 +59,7 @@ public class IotTest {
@Test
@Test
void
getLastDeviceLog
()
{
void
getLastDeviceLog
()
{
iotProductDeviceService
.
getLastDeviceLog
(
"1
694547143952007168
"
);
iotProductDeviceService
.
getLastDeviceLog
(
"1
701127702523473920
"
);
}
}
@Test
@Test
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment