Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
邬吉朋
rx
Commits
fd432e21
Commit
fd432e21
authored
Aug 22, 2024
by
wujipeng
Browse files
搭建mqtt
parent
cab99df9
Pipeline
#245
canceled with stages
Changes
7
Pipelines
1
Show whitespace changes
Inline
Side-by-side
src/main/java/com/ruzhoukj/rx/RxApplication.java
View file @
fd432e21
...
...
@@ -3,6 +3,7 @@ package com.ruzhoukj.rx;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.scheduling.annotation.EnableAsync
;
import
org.springframework.scheduling.annotation.EnableScheduling
;
/**
...
...
@@ -10,7 +11,8 @@ import org.springframework.scheduling.annotation.EnableScheduling;
*/
@SpringBootApplication
@EnableScheduling
@ComponentScan
(
basePackages
=
{
"com.platform"
})
@EnableAsync
@ComponentScan
(
basePackages
=
{
"com.platform"
,
"com.ruzhoukj.rx"
})
public
class
RxApplication
{
public
static
void
main
(
String
[]
args
)
{
...
...
src/main/java/com/ruzhoukj/rx/common/mqtt/MqttSubscriberClient.java
View file @
fd432e21
package
com.ruzhoukj.rx.common.mqtt
;
import
com.ruzhoukj.rx.pojo.entity.DataPoint
;
import
com.ruzhoukj.rx.pojo.entity.DeviceData
;
import
com.ruzhoukj.rx.pojo.entity.Fields
;
import
lombok.extern.slf4j.Slf4j
;
import
org.eclipse.paho.client.mqttv3.*
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.PostConstruct
;
import
javax.annotation.Resource
;
import
java.io.IOException
;
/**
...
...
@@ -16,6 +23,7 @@ import javax.annotation.Resource;
@Slf4j
public
class
MqttSubscriberClient
{
@Resource
private
MqttClient
mqttClient
;
...
...
@@ -36,6 +44,25 @@ public class MqttSubscriberClient {
log
.
info
(
"接收到消息: "
+
new
String
(
message
.
getPayload
()));
try
{
DeviceData
deviceData
=
DeviceData
.
fromJson
(
new
String
(
message
.
getPayload
()));
System
.
out
.
println
(
"Device ID: "
+
deviceData
.
getDeviceID
());
for
(
DataPoint
dp
:
deviceData
.
getData
())
{
System
.
out
.
println
(
"Timestamp: "
+
dp
.
getTimestamp
());
Fields
fields
=
dp
.
getFields
();
System
.
out
.
println
(
"ZU: "
+
fields
.
getZu
());
System
.
out
.
println
(
"ZB: "
+
fields
.
getZb
());
System
.
out
.
println
(
"VT: "
+
fields
.
getVt
());
System
.
out
.
println
(
"SVT: "
+
fields
.
getSvt
());
System
.
out
.
println
(
"ZT: "
+
fields
.
getZt
());
System
.
out
.
println
(
"SIN: "
+
fields
.
getSin
());
System
.
out
.
println
(
"TEM: "
+
fields
.
getTem
());
System
.
out
.
println
(
"HUM: "
+
fields
.
getHum
());
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
@Override
...
...
src/main/java/com/ruzhoukj/rx/controller/UserController.java
View file @
fd432e21
...
...
@@ -2,7 +2,7 @@ package com.ruzhoukj.rx.controller;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.ruzhoukj.rx.common.R
;
import
com.ruzhoukj.rx.pojo.User
;
import
com.ruzhoukj.rx.pojo.
entity.
User
;
import
com.ruzhoukj.rx.pojo.entity.UserEntity
;
import
com.ruzhoukj.rx.service.UserService
;
import
com.ruzhoukj.rx.util.JwtUtil
;
...
...
@@ -10,7 +10,6 @@ import io.swagger.annotations.Api;
import
io.swagger.annotations.ApiOperation
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
javax.annotation.Resource
;
...
...
src/main/java/com/ruzhoukj/rx/pojo/entity/DataPoint.java
0 → 100644
View file @
fd432e21
package
com.ruzhoukj.rx.pojo.entity
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
lombok.Data
;
import
java.util.Date
;
/**
* @author 邬吉朋
*/
@Data
public
class
DataPoint
{
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
)
private
Date
timestamp
;
private
Fields
fields
;
}
src/main/java/com/ruzhoukj/rx/pojo/entity/DeviceData.java
0 → 100644
View file @
fd432e21
package
com.ruzhoukj.rx.pojo.entity
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
lombok.Data
;
import
java.io.IOException
;
import
java.util.List
;
/**
* @author 邬吉朋
*/
@Data
public
class
DeviceData
{
private
String
deviceID
;
private
List
<
DataPoint
>
data
;
public
static
DeviceData
fromJson
(
String
json
)
throws
IOException
{
ObjectMapper
mapper
=
new
ObjectMapper
();
return
mapper
.
readValue
(
json
,
DeviceData
.
class
);
}
}
src/main/java/com/ruzhoukj/rx/pojo/entity/Fields.java
0 → 100644
View file @
fd432e21
package
com.ruzhoukj.rx.pojo.entity
;
import
lombok.Data
;
/**
* @author 邬吉朋
*/
@Data
public
class
Fields
{
private
double
zu
;
private
double
zb
;
private
double
vt
;
private
double
svt
;
private
int
zt
;
private
int
sin
;
private
int
tem
;
private
int
hum
;
}
src/main/java/com/ruzhoukj/rx/pojo/User.java
→
src/main/java/com/ruzhoukj/rx/pojo/
entity/
User.java
View file @
fd432e21
package
com.ruzhoukj.rx.pojo
;
package
com.ruzhoukj.rx.pojo
.entity
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
...
...
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