mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-27 09:33:55 +08:00
@@ -91,6 +91,15 @@ public interface Constant {
|
|||||||
*/
|
*/
|
||||||
String SERVER_WEBSOCKET = "server.websocket";
|
String SERVER_WEBSOCKET = "server.websocket";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* mqtt gateway 配置
|
||||||
|
*/
|
||||||
|
String SERVER_MQTT_GATEWAY = "server.mqtt_gateway";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* websocket地址
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ota地址
|
* ota地址
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -78,6 +78,10 @@ public class OTAController {
|
|||||||
@GetMapping
|
@GetMapping
|
||||||
@Hidden
|
@Hidden
|
||||||
public ResponseEntity<String> getOTA() {
|
public ResponseEntity<String> getOTA() {
|
||||||
|
String mqttUdpConfig = sysParamsService.getValue(Constant.SERVER_MQTT_GATEWAY, false);
|
||||||
|
if(StringUtils.isBlank(mqttUdpConfig)) {
|
||||||
|
return ResponseEntity.ok("OTA接口不正常,缺少websocket地址,请登录智控台,在参数管理找到【server.mqtt_udp】配置");
|
||||||
|
}
|
||||||
String wsUrl = sysParamsService.getValue(Constant.SERVER_WEBSOCKET, true);
|
String wsUrl = sysParamsService.getValue(Constant.SERVER_WEBSOCKET, true);
|
||||||
if (StringUtils.isBlank(wsUrl) || wsUrl.equals("null")) {
|
if (StringUtils.isBlank(wsUrl) || wsUrl.equals("null")) {
|
||||||
return ResponseEntity.ok("OTA接口不正常,缺少websocket地址,请登录智控台,在参数管理找到【server.websocket】配置");
|
return ResponseEntity.ok("OTA接口不正常,缺少websocket地址,请登录智控台,在参数管理找到【server.websocket】配置");
|
||||||
|
|||||||
@@ -23,6 +23,9 @@ public class DeviceReportRespDTO {
|
|||||||
@Schema(description = "WebSocket配置")
|
@Schema(description = "WebSocket配置")
|
||||||
private Websocket websocket;
|
private Websocket websocket;
|
||||||
|
|
||||||
|
@Schema(description = "MQTT Gateway配置")
|
||||||
|
private MQTT mqtt;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
public static class Firmware {
|
public static class Firmware {
|
||||||
@@ -70,4 +73,21 @@ public class DeviceReportRespDTO {
|
|||||||
@Schema(description = "WebSocket服务器地址")
|
@Schema(description = "WebSocket服务器地址")
|
||||||
private String url;
|
private String url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public static class MQTT {
|
||||||
|
@Schema(description = "MQTT 配置网址")
|
||||||
|
private String endpoint;
|
||||||
|
@Schema(description = "MQTT 客户端唯一标识符")
|
||||||
|
private String client_id;
|
||||||
|
@Schema(description = "MQTT 认证用户名")
|
||||||
|
private String username;
|
||||||
|
@Schema(description = "MQTT 认证密码")
|
||||||
|
private String password;
|
||||||
|
@Schema(description = "ESP32 发布消息的主题")
|
||||||
|
private String publish_topic;
|
||||||
|
@Schema(description = "ESP32 订阅的主题")
|
||||||
|
private String subscribe_topic;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+18
@@ -176,6 +176,24 @@ public class DeviceServiceImpl extends BaseServiceImpl<DeviceDao, DeviceEntity>
|
|||||||
|
|
||||||
response.setWebsocket(websocket);
|
response.setWebsocket(websocket);
|
||||||
|
|
||||||
|
// 添加MQTT UDP配置
|
||||||
|
// 从系统参数获取WebSocket URL,如果未配置不使用默认值
|
||||||
|
String mqttUdpConfig = sysParamsService.getValue(Constant.SERVER_MQTT_GATEWAY, false);
|
||||||
|
if(!StringUtils.isBlank(mqttUdpConfig)) {
|
||||||
|
DeviceReportRespDTO.MQTT mqtt= new DeviceReportRespDTO.MQTT();
|
||||||
|
mqtt.setEndpoint(mqttUdpConfig);
|
||||||
|
mqtt.setClient_id(clientId);
|
||||||
|
String userNameString = deviceById.getId().replace(":", "_");
|
||||||
|
mqtt.setUsername(userNameString);
|
||||||
|
mqtt.setPassword(deviceById.getBoard());
|
||||||
|
String topicString = deviceById.getBoard() + '/' + deviceById.getAgentId();
|
||||||
|
mqtt.setPublish_topic(topicString);
|
||||||
|
String subscribeString = "devices/p2p/"+userNameString;
|
||||||
|
mqtt.setSubscribe_topic(subscribeString);
|
||||||
|
response.setMqtt(mqtt);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (deviceById != null) {
|
if (deviceById != null) {
|
||||||
// 如果设备存在,则异步更新上次连接时间和版本信息
|
// 如果设备存在,则异步更新上次连接时间和版本信息
|
||||||
String appVersion = deviceReport.getApplication() != null ? deviceReport.getApplication().getVersion()
|
String appVersion = deviceReport.getApplication() != null ? deviceReport.getApplication().getVersion()
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
delete from `sys_params` where id = 108;
|
||||||
|
INSERT INTO `sys_params` (id, param_code, param_value, value_type, param_type, remark) VALUES (108, 'server.mqtt_udp', 'null', 'string', 1, 'mqtt udp 配置');
|
||||||
|
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
delete from `sys_params` where id = 108;
|
||||||
|
INSERT INTO `sys_params` (id, param_code, param_value, value_type, param_type, remark) VALUES (108, 'server.mqtt_gateway', 'null', 'string', 1, 'mqtt gateway 配置');
|
||||||
|
|
||||||
|
delete from `sys_params` where id = 109;
|
||||||
|
INSERT INTO `sys_params` (id, param_code, param_value, value_type, param_type, remark) VALUES (109, 'server.udp_gateway', 'null', 'string', 1, 'udp gateway 配置');
|
||||||
@@ -240,3 +240,16 @@ databaseChangeLog:
|
|||||||
- sqlFile:
|
- sqlFile:
|
||||||
encoding: utf8
|
encoding: utf8
|
||||||
path: classpath:db/changelog/202506261637.sql
|
path: classpath:db/changelog/202506261637.sql
|
||||||
|
id: 202506152342
|
||||||
|
author: marlonz
|
||||||
|
changes:
|
||||||
|
- sqlFile:
|
||||||
|
encoding: utf8
|
||||||
|
path: classpath:db/changelog/202506152342.sql
|
||||||
|
- changeSet:
|
||||||
|
id: 202506152350
|
||||||
|
author: marlonz
|
||||||
|
changes:
|
||||||
|
- sqlFile:
|
||||||
|
encoding: utf8
|
||||||
|
path: classpath:db/changelog/202506152350.sql
|
||||||
|
|||||||
Generated
+19
-5
@@ -10,6 +10,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"core-js": "^3.41.0",
|
"core-js": "^3.41.0",
|
||||||
"cross-env": "^7.0.3",
|
"cross-env": "^7.0.3",
|
||||||
|
"dotenv": "^16.5.0",
|
||||||
"element-ui": "^2.15.14",
|
"element-ui": "^2.15.14",
|
||||||
"flyio": "^0.6.14",
|
"flyio": "^0.6.14",
|
||||||
"normalize.css": "^8.0.1",
|
"normalize.css": "^8.0.1",
|
||||||
@@ -2540,6 +2541,16 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@vue/cli-service/node_modules/dotenv": {
|
||||||
|
"version": "10.0.0",
|
||||||
|
"resolved": "https://registry.npmmirror.com/dotenv/-/dotenv-10.0.0.tgz",
|
||||||
|
"integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "BSD-2-Clause",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=10"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@vue/cli-shared-utils": {
|
"node_modules/@vue/cli-shared-utils": {
|
||||||
"version": "5.0.8",
|
"version": "5.0.8",
|
||||||
"resolved": "https://registry.npmmirror.com/@vue/cli-shared-utils/-/cli-shared-utils-5.0.8.tgz",
|
"resolved": "https://registry.npmmirror.com/@vue/cli-shared-utils/-/cli-shared-utils-5.0.8.tgz",
|
||||||
@@ -4776,12 +4787,15 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/dotenv": {
|
"node_modules/dotenv": {
|
||||||
"version": "10.0.0",
|
"version": "16.5.0",
|
||||||
"resolved": "https://registry.npmmirror.com/dotenv/-/dotenv-10.0.0.tgz",
|
"resolved": "https://registry.npmmirror.com/dotenv/-/dotenv-16.5.0.tgz",
|
||||||
"integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==",
|
"integrity": "sha512-m/C+AwOAr9/W1UOIZUo232ejMNnJAJtYQjUbHoNTBNTJSvqzzDh7vnrei3o3r3m9blf6ZoDkvcw0VmozNRFJxg==",
|
||||||
"dev": true,
|
"license": "BSD-2-Clause",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=10"
|
"node": ">=12"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://dotenvx.com"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/dotenv-expand": {
|
"node_modules/dotenv-expand": {
|
||||||
|
|||||||
Reference in New Issue
Block a user