mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-29 05:09:46 +01:00
feat: 支持通过OTA更新websocket地址
This commit is contained in:
parent
83f86406b5
commit
0239bbdb70
2 changed files with 23 additions and 0 deletions
|
|
@ -20,6 +20,9 @@ public class DeviceReportRespDTO {
|
||||||
@Schema(description = "固件版本信息")
|
@Schema(description = "固件版本信息")
|
||||||
private Firmware firmware;
|
private Firmware firmware;
|
||||||
|
|
||||||
|
@Schema(description = "WebSocket配置")
|
||||||
|
private Websocket websocket;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
public static class Firmware {
|
public static class Firmware {
|
||||||
|
|
@ -60,4 +63,11 @@ public class DeviceReportRespDTO {
|
||||||
@Schema(description = "时区偏移量,单位为分钟")
|
@Schema(description = "时区偏移量,单位为分钟")
|
||||||
private Integer timezone_offset;
|
private Integer timezone_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public static class Websocket {
|
||||||
|
@Schema(description = "WebSocket服务器地址")
|
||||||
|
private String url;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,8 @@ public class DeviceServiceImpl extends BaseServiceImpl<DeviceDao, DeviceEntity>
|
||||||
|
|
||||||
private final RedisTemplate<String, Object> redisTemplate;
|
private final RedisTemplate<String, Object> redisTemplate;
|
||||||
|
|
||||||
|
private final SysParamsService sysParamsService;
|
||||||
|
|
||||||
// 添加构造函数来初始化 deviceMapper
|
// 添加构造函数来初始化 deviceMapper
|
||||||
public DeviceServiceImpl(DeviceDao deviceDao, SysUserUtilService sysUserUtilService,
|
public DeviceServiceImpl(DeviceDao deviceDao, SysUserUtilService sysUserUtilService,
|
||||||
SysParamsService sysParamsService,
|
SysParamsService sysParamsService,
|
||||||
|
|
@ -55,6 +57,7 @@ public class DeviceServiceImpl extends BaseServiceImpl<DeviceDao, DeviceEntity>
|
||||||
this.sysUserUtilService = sysUserUtilService;
|
this.sysUserUtilService = sysUserUtilService;
|
||||||
this.frontedUrl = sysParamsService.getValue(Constant.SERVER_FRONTED_URL, true);
|
this.frontedUrl = sysParamsService.getValue(Constant.SERVER_FRONTED_URL, true);
|
||||||
this.redisTemplate = redisTemplate;
|
this.redisTemplate = redisTemplate;
|
||||||
|
this.sysParamsService = sysParamsService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -132,6 +135,16 @@ public class DeviceServiceImpl extends BaseServiceImpl<DeviceDao, DeviceEntity>
|
||||||
firmware.setUrl("http://localhost:8002/xiaozhi/ota/download");
|
firmware.setUrl("http://localhost:8002/xiaozhi/ota/download");
|
||||||
response.setFirmware(firmware);
|
response.setFirmware(firmware);
|
||||||
|
|
||||||
|
// 添加WebSocket配置
|
||||||
|
DeviceReportRespDTO.Websocket websocket = new DeviceReportRespDTO.Websocket();
|
||||||
|
// 从系统参数获取WebSocket URL,如果未配置则使用默认值
|
||||||
|
String wsUrl = sysParamsService.getValue("websocket_url", true);
|
||||||
|
if (StringUtils.isBlank(wsUrl)) {
|
||||||
|
wsUrl = "ws://localhost:8000/xiaozhi/v1/";
|
||||||
|
}
|
||||||
|
websocket.setUrl(wsUrl);
|
||||||
|
response.setWebsocket(websocket);
|
||||||
|
|
||||||
DeviceEntity deviceById = getDeviceById(macAddress);
|
DeviceEntity deviceById = getDeviceById(macAddress);
|
||||||
if (deviceById != null) { // 如果设备存在,则更新上次连接时间
|
if (deviceById != null) { // 如果设备存在,则更新上次连接时间
|
||||||
deviceById.setLastConnectedAt(new Date());
|
deviceById.setLastConnectedAt(new Date());
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue