Distributed project (2) Web Manage device data upload

Last time, we talked about the entire structure of iot-pt, and then we started to talk about web manage. Web manage is a service that iot-pt provides visual operations, but the author's front-end skills are too weak. Use swagger too.

Flow Description

  1. Users add products on the web side and persist product data
  2. Add attribute information according to products, persist attribute data, and redis cache attribute data
  3. Create instructions based on products and persist instruction data
  4. Create events based on products, persist event data
  5. Create devices based on products, persist device data, and redis cache device data

Structure diagram

Project construction

Use idea to build the spring boot iot-pt project and create the iot-manage module. The spring boot version of the author here is 2.1.4, which introduces swagger, mybatis, and pgsql dependencies.

Build the basic iot-beans module for the writing of common entity classes and common tool classes

The specific construction details are beyond the scope of the author's description.

Model building

Here, the upstream of iot data is implemented first, that is, the business data reported by the device

product model

@ApiModel(value = "产品参数")
public class ProductDTO {
    @ApiModelProperty(value = "产品名称")
    @NotBlank
    private String name;
    @ApiModelProperty(value = "设备型号")
    @NotBlank
    private String model;
    @ApiModelProperty(value = "数据格式")
    private EDataFormat format;
    @ApiModelProperty(value = "是否加密")
    private Integer encrypt;
    @ApiModelProperty(value = "接入协议")
    private EProtocol protocol;

device model

@ApiModel(value = "设备模型")
public class DeviceDTO {
    @ApiModelProperty(value = "名称")
    @NotBlank
    private String name;
    @ApiModelProperty(value = "设备唯一码")
    @NotBlank
    private String imei;
    @ApiModelProperty(value = "产品id")
    private Long productId;

property model

@ApiModel(value = "产品属性")
public class PropertyDTO {
    @ApiModelProperty(value = "产品id")
    private Long productId;
    @ApiModelProperty(value = "属性名称")
    private String name;
    @ApiModelProperty(value = "标识符")
    @NotBlank
    private String identifier;
    @ApiModelProperty(value = "数据类型")
    private EDataType type;
    @ApiModelProperty(value = "偏移量")
    private String ofset;
    @ApiModelProperty(value = "单位")
    private String unit;

Basic data definition

Data Format

public enum EDataFormat {

    JSON("JSON"),
    BYTE("BYTE");

json: The data uploaded by the physical device is key-value json data, and the key corresponds to the identifier attribute of the attribute model

byte: The data uploaded by the physical device is continuous data in decimal, such as: 318645, which is actually split into xx=318, yy=645. This kind of data needs to use the defined offset to read the data, offset and attribute Model offset attribute corresponding

protocol

public enum EProtocol {
    COAP("COAP"),
    QMTT("QMTT");
    EProtocol(String protocol){
        this.protocol = protocol;
    }

redis data cache

Attribute Caching Model

public class RedisPropertyVO {
    private Long id;
    private String ofset;

Product Cache Model

public class RedisProductVO {
    //数据格式
    private String format;
    private List<RedisPropertyVO> propertys;

Device cache model

public class RedisDeviceVO {
    private Long id;
    private Long productId;

database

The database design is in the git iot-pt.sql file

concluding remarks

The rest is the operation of products, attributes, equipment, additions, deletions, modifications, and inspections. The codes are not posted here one by one. Readers can go to git to download

https://gitee.com/distant/iot-pt.git

{{o.name}}
{{m.name}}

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=324104158&siteId=291194637