changed deviceId from Integer to String/CHAR(6)
This commit is contained in:
102
README.md
102
README.md
@@ -26,8 +26,9 @@ La encontraréis en `dist/`
|
||||
```sql
|
||||
USE dad;
|
||||
|
||||
DROP TABLE IF EXISTS co_values;
|
||||
DROP TABLE IF EXISTS weather_values;
|
||||
DROP TABLE IF EXISTS gps_values;
|
||||
DROP TABLE IF EXISTS air_values;
|
||||
DROP TABLE IF EXISTS actuators;
|
||||
DROP TABLE IF EXISTS sensors;
|
||||
DROP TABLE IF EXISTS devices;
|
||||
@@ -39,54 +40,60 @@ CREATE TABLE IF NOT EXISTS groups(
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS devices(
|
||||
deviceId INT PRIMARY KEY AUTO_INCREMENT NOT NULL,
|
||||
deviceId CHAR(6) PRIMARY KEY NOT NULL,
|
||||
groupId INT NOT NULL,
|
||||
deviceName VARCHAR(64) DEFAULT NULL,
|
||||
FOREIGN KEY (groupId) REFERENCES groups(groupId)
|
||||
FOREIGN KEY (groupId) REFERENCES groups(groupId) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS sensors(
|
||||
sensorId INT PRIMARY KEY AUTO_INCREMENT NOT NULL,
|
||||
deviceId INT NOT NULL,
|
||||
sensorId INT NOT NULL,
|
||||
deviceId CHAR(6) NOT NULL,
|
||||
sensorType VARCHAR(64) NOT NULL,
|
||||
unit VARCHAR(8) NOT NULL,
|
||||
status INT NOT NULL,
|
||||
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
|
||||
FOREIGN KEY (deviceId) REFERENCES devices(deviceId)
|
||||
PRIMARY KEY (deviceId, sensorId),
|
||||
FOREIGN KEY (deviceId) REFERENCES devices(deviceId) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS actuators (
|
||||
actuatorId INT PRIMARY KEY AUTO_INCREMENT NOT NULL,
|
||||
deviceId INT NOT NULL,
|
||||
actuatorId INT NOT NULL,
|
||||
deviceId CHAR(6) NOT NULL,
|
||||
status INT NOT NULL,
|
||||
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
|
||||
FOREIGN KEY (deviceId) REFERENCES devices(deviceId)
|
||||
PRIMARY KEY (deviceId, actuatorId),
|
||||
FOREIGN KEY (deviceId) REFERENCES devices(deviceId) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS gps_values(
|
||||
valueId INT PRIMARY KEY AUTO_INCREMENT NOT NULL,
|
||||
deviceId CHAR(6) NOT NULL,
|
||||
sensorId INT NOT NULL,
|
||||
lat FLOAT NOT NULL,
|
||||
lon FLOAT NOT NULL,
|
||||
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
|
||||
FOREIGN KEY (sensorId) REFERENCES sensors(sensorId)
|
||||
FOREIGN KEY (deviceId, sensorId) REFERENCES sensors(deviceId, sensorId) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS weather_values (
|
||||
valueId INT PRIMARY KEY AUTO_INCREMENT NOT NULL ,
|
||||
deviceId CHAR(6) NOT NULL,
|
||||
sensorId INT NOT NULL,
|
||||
temperature FLOAT NOT NULL,
|
||||
humidity FLOAT NOT NULL,
|
||||
pressure FLOAT NOT NULL,
|
||||
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
|
||||
FOREIGN KEY (sensorId) REFERENCES sensors(sensorId)
|
||||
FOREIGN KEY (deviceId, sensorId) REFERENCES sensors(deviceId, sensorId) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS co_values (
|
||||
valueId INT PRIMARY KEY AUTO_INCREMENT NOT NULL ,
|
||||
deviceId CHAR(6) NOT NULL,
|
||||
sensorId INT NOT NULL,
|
||||
value FLOAT NOT NULL,
|
||||
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP(),
|
||||
FOREIGN KEY (sensorId) REFERENCES sensors(sensorId)
|
||||
FOREIGN KEY (deviceId, sensorId) REFERENCES sensors(deviceId, sensorId) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE OR REPLACE VIEW v_sensor_values AS
|
||||
@@ -98,14 +105,15 @@ SELECT
|
||||
s.status AS sensorStatus,
|
||||
wv.temperature,
|
||||
wv.humidity,
|
||||
wv.pressure,
|
||||
cv.value AS carbonMonoxide,
|
||||
gv.lat,
|
||||
gv.lon,
|
||||
COALESCE(gv.timestamp, wv.timestamp, cv.timestamp) AS timestamp -- el primero no nulo
|
||||
FROM sensors s
|
||||
LEFT JOIN weather_values wv ON s.sensorId = wv.sensorId
|
||||
LEFT JOIN co_values cv ON s.sensorId = cv.sensorId
|
||||
LEFT JOIN gps_values gv ON s.sensorId = gv.sensorId;
|
||||
LEFT JOIN weather_values wv ON s.deviceId = wv.deviceId AND s.sensorId = wv.sensorId
|
||||
LEFT JOIN co_values cv ON s.deviceId = cv.deviceId AND s.sensorId = cv.sensorId
|
||||
LEFT JOIN gps_values gv ON s.deviceId = gv.deviceId AND s.sensorId = gv.sensorId;
|
||||
|
||||
|
||||
CREATE OR REPLACE VIEW v_latest_values AS
|
||||
@@ -118,14 +126,15 @@ SELECT
|
||||
s.timestamp AS sensorTimestamp,
|
||||
wv.temperature,
|
||||
wv.humidity,
|
||||
wv.pressure,
|
||||
cv.value AS carbonMonoxide,
|
||||
gv.lat,
|
||||
gv.lon,
|
||||
COALESCE(gv.timestamp, wv.timestamp, cv.timestamp) AS airValuesTimestamp -- el primero no nulo
|
||||
FROM sensors s
|
||||
LEFT JOIN weather_values wv ON s.sensorId = wv.sensorId
|
||||
LEFT JOIN co_values cv ON s.sensorId = cv.sensorId
|
||||
LEFT JOIN gps_values gv ON s.sensorId = gv.sensorId
|
||||
LEFT JOIN weather_values wv ON s.deviceId = wv.deviceId AND s.sensorId = wv.sensorId
|
||||
LEFT JOIN co_values cv ON s.deviceId = cv.deviceId AND s.sensorId = cv.sensorId
|
||||
LEFT JOIN gps_values gv ON s.deviceId = gv.deviceId AND s.sensorId = gv.sensorId
|
||||
WHERE (wv.timestamp = (SELECT MAX(timestamp) FROM weather_values WHERE sensorId = s.sensorId)
|
||||
OR cv.timestamp = (SELECT MAX(timestamp) FROM co_values WHERE sensorId = s.sensorId)
|
||||
OR gv.timestamp = (SELECT MAX(timestamp) FROM gps_values WHERE sensorId = s.sensorId));
|
||||
@@ -138,7 +147,7 @@ SELECT
|
||||
c.value AS carbonMonoxide,
|
||||
c.timestamp
|
||||
FROM sensors s
|
||||
JOIN co_values c ON s.sensorId = c.sensorId
|
||||
JOIN co_values c ON s.deviceId = c.deviceId AND s.sensorId = c.sensorId
|
||||
WHERE s.sensorType = 'CO';
|
||||
|
||||
CREATE OR REPLACE VIEW v_gps_by_device AS
|
||||
@@ -148,7 +157,7 @@ SELECT
|
||||
g.lon,
|
||||
g.timestamp
|
||||
FROM sensors s
|
||||
JOIN gps_values g ON s.sensorId = g.sensorId
|
||||
JOIN gps_values g ON s.deviceId = g.deviceId AND s.sensorId = g.sensorId
|
||||
WHERE s.sensorType = 'GPS';
|
||||
|
||||
CREATE OR REPLACE VIEW v_weather_by_device AS
|
||||
@@ -156,9 +165,10 @@ SELECT
|
||||
s.deviceId,
|
||||
w.temperature AS temperature,
|
||||
w.humidity AS humidity,
|
||||
w.pressure AS pressure,
|
||||
w.timestamp
|
||||
FROM sensors s
|
||||
JOIN weather_values w ON s.sensorId = w.sensorId
|
||||
JOIN weather_values w ON s.deviceId = w.deviceId AND s.sensorId = w.sensorId
|
||||
WHERE s.sensorType = 'Temperature & Humidity';
|
||||
-- VISTAS AUXILIARES
|
||||
|
||||
@@ -210,46 +220,16 @@ ORDER BY deviceId, timestamp;
|
||||
INSERT INTO groups (groupName) VALUES ('Grupo 1');
|
||||
|
||||
-- Insertar dispositivos
|
||||
INSERT INTO devices (groupId, deviceName) VALUES
|
||||
(1, 'Dispositivo 1'),
|
||||
(1, 'Dispositivo 2'),
|
||||
(1, 'Dispositivo 3');
|
||||
INSERT INTO devices (deviceId, groupId, deviceName) VALUES
|
||||
('6A6098', 1, 'Dispositivo 1');
|
||||
|
||||
-- Sensores para el Dispositivo 1
|
||||
-- Cada dispositivo tiene un único sensor de cada tipo (GPS, Temperature & Humidity, CO)
|
||||
INSERT INTO sensors (deviceId, sensorType, unit, status) VALUES
|
||||
(1, 'GPS', 'N/A', 1), -- Sensor de GPS para Dispositivo 1
|
||||
(1, 'Temperature & Humidity', '°C/%', 1), -- Sensor de Temp/Humidity para Dispositivo 1
|
||||
(1, 'CO', 'ppm', 1); -- Sensor de CO para Dispositivo 1
|
||||
-- Sensores para el Dispositivo 6A6098
|
||||
INSERT INTO sensors (sensorId, deviceId, sensorType, unit, status) VALUES
|
||||
(1, '6A6098', 'GPS', 'N/A', 1),
|
||||
(2, '6A6098', 'Temperature & Humidity', '°C/%', 1),
|
||||
(3, '6A6098', 'CO', 'ppm', 1);
|
||||
|
||||
-- Sensores para el Dispositivo 2
|
||||
INSERT INTO sensors (deviceId, sensorType, unit, status) VALUES
|
||||
(2, 'GPS', 'N/A', 1), -- Sensor de GPS para Dispositivo 2
|
||||
(2, 'Temperature & Humidity', '°C/%', 1), -- Sensor de Temp/Humidity para Dispositivo 2
|
||||
(2, 'CO', 'ppm', 1); -- Sensor de CO para Dispositivo 2
|
||||
|
||||
-- Sensores para el Dispositivo 3
|
||||
INSERT INTO sensors (deviceId, sensorType, unit, status) VALUES
|
||||
(3, 'GPS', 'N/A', 1), -- Sensor de GPS para Dispositivo 3
|
||||
(3, 'Temperature & Humidity', '°C/%', 1), -- Sensor de Temp/Humidity para Dispositivo 3
|
||||
(3, 'CO', 'ppm', 1); -- Sensor de CO para Dispositivo 3
|
||||
|
||||
-- Valores de GPS para los Dispositivos
|
||||
-- Cada dispositivo tiene un único sensor de GPS con latitud y longitud asociada
|
||||
INSERT INTO gps_values (sensorId, lat, lon) VALUES
|
||||
(1, 37.3861, -5.9921), -- GPS para Dispositivo 1
|
||||
(4, 37.3850, -5.9910), -- GPS para Dispositivo 2
|
||||
(7, 37.3860, -5.9920); -- GPS para Dispositivo 3
|
||||
|
||||
-- Valores de Temperatura, Humedad y CO para los Dispositivos
|
||||
-- Cada dispositivo tiene un único sensor de aire (temperatura, humedad, CO) con valores asociados
|
||||
INSERT INTO weather_values (sensorId, temperature, humidity) VALUES
|
||||
(2, 22.5, 45.0), -- Temperatura, Humedad para Dispositivo 1
|
||||
(5, 24.5, 50.0), -- Temperatura, Humedad para Dispositivo 2
|
||||
(8, 21.0, 44.0); -- Temperatura, Humedad para Dispositivo 3
|
||||
|
||||
INSERT INTO co_values (sensorId, value) VALUES
|
||||
(3, 0.02), -- CO para Dispositivo 1
|
||||
(6, 0.04), -- CO para Dispositivo 2
|
||||
(9, 0.01); -- CO para Dispositivo 3
|
||||
-- ACtuadores para el Dispositivo 6A6098
|
||||
INSERT INTO actuators (actuatorId, deviceId, status, timestamp) VALUES
|
||||
(1, '6A6098', 1, CURRENT_TIMESTAMP());
|
||||
```
|
||||
|
||||
@@ -11,6 +11,8 @@ public class Constants {
|
||||
|
||||
|
||||
/* API Endpoints */
|
||||
public static final String POST_PAYLOAD = RAW_API_PREFIX + "/device-payload";
|
||||
|
||||
public static final String GET_GROUPS = RAW_API_PREFIX + "/groups";
|
||||
public static final String POST_GROUPS = RAW_API_PREFIX + "/groups";
|
||||
public static final String PUT_GROUP_BY_ID = RAW_API_PREFIX + "/groups/:groupId";
|
||||
|
||||
@@ -10,7 +10,7 @@ import net.miarma.contaminus.util.DateParser;
|
||||
public class Actuator {
|
||||
|
||||
private Integer actuatorId;
|
||||
private Integer deviceId;
|
||||
private String deviceId;
|
||||
private Integer status;
|
||||
private Long timestamp;
|
||||
|
||||
@@ -18,12 +18,12 @@ public class Actuator {
|
||||
|
||||
public Actuator(Row row) {
|
||||
this.actuatorId = row.getInteger("actuatorId");
|
||||
this.deviceId = row.getInteger("deviceId");
|
||||
this.deviceId = row.getString("deviceId");
|
||||
this.status = row.getInteger("status");
|
||||
this.timestamp = DateParser.parseDate(row.getLocalDateTime("timestamp"));
|
||||
}
|
||||
|
||||
public Actuator(Integer actuatorId, Integer deviceId, Integer status, Long timestamp) {
|
||||
public Actuator(Integer actuatorId, String deviceId, Integer status, Long timestamp) {
|
||||
super();
|
||||
this.actuatorId = actuatorId;
|
||||
this.deviceId = deviceId;
|
||||
@@ -39,11 +39,11 @@ public class Actuator {
|
||||
this.actuatorId = actuatorId;
|
||||
}
|
||||
|
||||
public Integer getDeviceId() {
|
||||
public String getDeviceId() {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
public void setDeviceId(Integer deviceId) {
|
||||
public void setDeviceId(String deviceId) {
|
||||
this.deviceId = deviceId;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import net.miarma.contaminus.util.DateParser;
|
||||
public class COValue {
|
||||
|
||||
private Integer valueId;
|
||||
private String deviceId;
|
||||
private Integer sensorId;
|
||||
private Float value;
|
||||
private Long timestamp;
|
||||
@@ -18,14 +19,16 @@ public class COValue {
|
||||
|
||||
public COValue(Row row) {
|
||||
this.valueId = row.getInteger("valueId");
|
||||
this.deviceId = row.getString("deviceId");
|
||||
this.sensorId = row.getInteger("sensorId");
|
||||
this.value = row.getFloat("value");
|
||||
this.timestamp = DateParser.parseDate(row.getLocalDateTime("timestamp"));
|
||||
}
|
||||
|
||||
public COValue(Integer valueId, Integer sensorId, Float value, Long timestamp) {
|
||||
public COValue(Integer valueId, String deviceId, Integer sensorId, Float value, Long timestamp) {
|
||||
super();
|
||||
this.valueId = valueId;
|
||||
this.deviceId = deviceId;
|
||||
this.sensorId = sensorId;
|
||||
this.value = value;
|
||||
this.timestamp = timestamp;
|
||||
@@ -39,6 +42,14 @@ public class COValue {
|
||||
this.valueId = valueId;
|
||||
}
|
||||
|
||||
public String getDeviceId() {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
public void setDeviceId(String deviceId) {
|
||||
this.deviceId = deviceId;
|
||||
}
|
||||
|
||||
public Integer getSensorId() {
|
||||
return sensorId;
|
||||
}
|
||||
@@ -65,7 +76,7 @@ public class COValue {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(sensorId, timestamp, value, valueId);
|
||||
return Objects.hash(deviceId, sensorId, timestamp, value, valueId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -77,17 +88,20 @@ public class COValue {
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
COValue other = (COValue) obj;
|
||||
return Objects.equals(sensorId, other.sensorId) && Objects.equals(timestamp, other.timestamp)
|
||||
&& Objects.equals(value, other.value) && Objects.equals(valueId, other.valueId);
|
||||
return Objects.equals(deviceId, other.deviceId) && Objects.equals(sensorId, other.sensorId)
|
||||
&& Objects.equals(timestamp, other.timestamp) && Objects.equals(value, other.value)
|
||||
&& Objects.equals(valueId, other.valueId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "COValue [valueId=" + valueId + ", sensorId=" + sensorId + ", value=" + value + ", timestamp="
|
||||
+ timestamp + "]";
|
||||
return "COValue [valueId=" + valueId + ", deviceId=" + deviceId + ", sensorId=" + sensorId + ", value=" + value
|
||||
+ ", timestamp=" + timestamp + "]";
|
||||
}
|
||||
|
||||
public static COValue fromPayload(DevicePayload payload) {
|
||||
return new COValue(null, payload.getDeviceId(), payload.getSensorId(), payload.getCarbonMonoxide(), payload.getTimestamp());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -6,30 +6,30 @@ import net.miarma.contaminus.common.Table;
|
||||
@Table("devices")
|
||||
public class Device {
|
||||
|
||||
private Integer deviceId;
|
||||
private String deviceId;
|
||||
private Integer groupId;
|
||||
private String deviceName;
|
||||
|
||||
public Device() {}
|
||||
|
||||
public Device(Row row) {
|
||||
this.deviceId = row.getInteger("deviceId");
|
||||
this.deviceId = row.getString("deviceId");
|
||||
this.groupId = row.getInteger("groupId");
|
||||
this.deviceName = row.getString("deviceName");
|
||||
}
|
||||
|
||||
public Device(Integer deviceId, Integer groupId, String deviceName) {
|
||||
public Device(String deviceId, Integer groupId, String deviceName) {
|
||||
super();
|
||||
this.deviceId = deviceId;
|
||||
this.groupId = groupId;
|
||||
this.deviceName = deviceName;
|
||||
}
|
||||
|
||||
public Integer getDeviceId() {
|
||||
public String getDeviceId() {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
public void setDeviceId(Integer deviceId) {
|
||||
public void setDeviceId(String deviceId) {
|
||||
this.deviceId = deviceId;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,26 +8,26 @@ import net.miarma.contaminus.util.DateParser;
|
||||
|
||||
@Table("v_co_by_device")
|
||||
public class DeviceCO {
|
||||
private Integer deviceId;
|
||||
private String deviceId;
|
||||
private Float carbonMonoxide;
|
||||
private Long timestamp;
|
||||
|
||||
public DeviceCO() {}
|
||||
|
||||
public DeviceCO(Row row) {
|
||||
this.deviceId = row.getInteger("deviceId");
|
||||
this.deviceId = row.getString("deviceId");
|
||||
this.carbonMonoxide = row.getFloat("carbonMonoxide");
|
||||
this.timestamp = DateParser.parseDate(row.getLocalDateTime("timestamp"));
|
||||
}
|
||||
|
||||
public DeviceCO(Integer deviceId, Float carbonMonoxide, Long timestamp) {
|
||||
public DeviceCO(String deviceId, Float carbonMonoxide, Long timestamp) {
|
||||
super();
|
||||
this.deviceId = deviceId;
|
||||
this.carbonMonoxide = carbonMonoxide;
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
public Integer getDeviceId() {
|
||||
public String getDeviceId() {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import net.miarma.contaminus.util.DateParser;
|
||||
|
||||
@Table("v_gps_by_device")
|
||||
public class DeviceGPS {
|
||||
private Integer deviceId;
|
||||
private String deviceId;
|
||||
private Float lat;
|
||||
private Float lon;
|
||||
private Long timestamp;
|
||||
@@ -16,20 +16,20 @@ public class DeviceGPS {
|
||||
public DeviceGPS() {}
|
||||
|
||||
public DeviceGPS(Row row) {
|
||||
this.deviceId = row.getInteger("deviceId");
|
||||
this.deviceId = row.getString("deviceId");
|
||||
this.lat = row.getFloat("lat");
|
||||
this.lon = row.getFloat("lon");
|
||||
this.timestamp = DateParser.parseDate(row.getLocalDateTime("timestamp"));
|
||||
}
|
||||
|
||||
public DeviceGPS(Integer deviceId, Float lat, Float lon) {
|
||||
public DeviceGPS(String deviceId, Float lat, Float lon) {
|
||||
super();
|
||||
this.deviceId = deviceId;
|
||||
this.lat = lat;
|
||||
this.lon = lon;
|
||||
}
|
||||
|
||||
public Integer getDeviceId() {
|
||||
public String getDeviceId() {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import net.miarma.contaminus.util.DateParser;
|
||||
|
||||
@Table("v_latest_values")
|
||||
public class DeviceLatestValuesView {
|
||||
private Integer deviceId;
|
||||
private String deviceId;
|
||||
private Integer sensorId;
|
||||
private String sensorType;
|
||||
private String unit;
|
||||
@@ -23,7 +23,7 @@ public class DeviceLatestValuesView {
|
||||
public DeviceLatestValuesView() {}
|
||||
|
||||
public DeviceLatestValuesView(Row row) {
|
||||
this.deviceId = row.getInteger("deviceId");
|
||||
this.deviceId = row.getString("deviceId");
|
||||
this.sensorId = row.getInteger("sensorId");
|
||||
this.sensorType = row.getString("sensorType");
|
||||
this.unit = row.getString("unit");
|
||||
@@ -37,7 +37,7 @@ public class DeviceLatestValuesView {
|
||||
this.airValuesTimestamp = DateParser.parseDate(row.getLocalDateTime("airValuesTimestamp"));
|
||||
}
|
||||
|
||||
public DeviceLatestValuesView(Integer deviceId, Integer sensorId, String sensorType, String unit, Integer sensorStatus,
|
||||
public DeviceLatestValuesView(String deviceId, Integer sensorId, String sensorType, String unit, Integer sensorStatus,
|
||||
Long sensorTimestamp, Float temperature, Float humidity, Float carbonMonoxide, Float lat, Float lon,
|
||||
Long airValuesTimestamp) {
|
||||
super();
|
||||
@@ -55,7 +55,7 @@ public class DeviceLatestValuesView {
|
||||
this.airValuesTimestamp = airValuesTimestamp;
|
||||
}
|
||||
|
||||
public Integer getDeviceId() {
|
||||
public String getDeviceId() {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
package net.miarma.contaminus.database.entities;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class DevicePayload {
|
||||
private String deviceId;
|
||||
private Integer sensorId;
|
||||
private Float temperature;
|
||||
private Float humidity;
|
||||
private Float pressure;
|
||||
private Float carbonMonoxide;
|
||||
private Float lat;
|
||||
private Float lon;
|
||||
private Long timestamp;
|
||||
|
||||
public DevicePayload() {}
|
||||
|
||||
public DevicePayload(String deviceId, Integer sensorId, String sensorType, String unit, Integer sensorStatus,
|
||||
Float temperature, Float humidity, Float pressure, Float carbonMonoxide, Float lat, Float lon, Long timestamp) {
|
||||
super();
|
||||
this.deviceId = deviceId;
|
||||
this.sensorId = sensorId;
|
||||
this.temperature = temperature;
|
||||
this.humidity = humidity;
|
||||
this.pressure = pressure;
|
||||
this.carbonMonoxide = carbonMonoxide;
|
||||
this.lat = lat;
|
||||
this.lon = lon;
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
public String getDeviceId() {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
public void setDeviceId(String deviceId) {
|
||||
this.deviceId = deviceId;
|
||||
}
|
||||
|
||||
public Integer getSensorId() {
|
||||
return sensorId;
|
||||
}
|
||||
|
||||
public void setSensorId(Integer sensorId) {
|
||||
this.sensorId = sensorId;
|
||||
}
|
||||
|
||||
public Float getTemperature() {
|
||||
return temperature;
|
||||
}
|
||||
|
||||
public void setTemperature(Float temperature) {
|
||||
this.temperature = temperature;
|
||||
}
|
||||
|
||||
public Float getHumidity() {
|
||||
return humidity;
|
||||
}
|
||||
|
||||
public void setHumidity(Float humidity) {
|
||||
this.humidity = humidity;
|
||||
}
|
||||
|
||||
public Float getPressure() {
|
||||
return pressure;
|
||||
}
|
||||
|
||||
public Float getCarbonMonoxide() {
|
||||
return carbonMonoxide;
|
||||
}
|
||||
|
||||
public void setCarbonMonoxide(Float carbonMonoxide) {
|
||||
this.carbonMonoxide = carbonMonoxide;
|
||||
}
|
||||
|
||||
public Float getLat() {
|
||||
return lat;
|
||||
}
|
||||
|
||||
public void setLat(Float lat) {
|
||||
this.lat = lat;
|
||||
}
|
||||
|
||||
public Float getLon() {
|
||||
return lon;
|
||||
}
|
||||
|
||||
public void setLon(Float lon) {
|
||||
this.lon = lon;
|
||||
}
|
||||
|
||||
public Long getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
public void setTimestamp(Long timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(carbonMonoxide, deviceId, humidity, lat, lon, pressure, sensorId, temperature, timestamp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
DevicePayload other = (DevicePayload) obj;
|
||||
return Objects.equals(carbonMonoxide, other.carbonMonoxide) && Objects.equals(deviceId, other.deviceId)
|
||||
&& Objects.equals(humidity, other.humidity) && Objects.equals(lat, other.lat)
|
||||
&& Objects.equals(lon, other.lon) && Objects.equals(pressure, other.pressure)
|
||||
&& Objects.equals(sensorId, other.sensorId) && Objects.equals(temperature, other.temperature)
|
||||
&& Objects.equals(timestamp, other.timestamp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DevicePayload [deviceId=" + deviceId + ", sensorId=" + sensorId + ", temperature=" + temperature
|
||||
+ ", humidity=" + humidity + ", pressure=" + pressure + ", carbonMonoxide=" + carbonMonoxide + ", lat="
|
||||
+ lat + ", lon=" + lon + ", timestamp=" + timestamp + "]";
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import net.miarma.contaminus.util.DateParser;
|
||||
|
||||
@Table("v_pollution_map")
|
||||
public class DevicePollutionMap {
|
||||
private Integer deviceId;
|
||||
private String deviceId;
|
||||
private String deviceName;
|
||||
private Float lat;
|
||||
private Float lon;
|
||||
@@ -18,7 +18,7 @@ public class DevicePollutionMap {
|
||||
public DevicePollutionMap() {}
|
||||
|
||||
public DevicePollutionMap(Row row) {
|
||||
this.deviceId = row.getInteger("deviceId");
|
||||
this.deviceId = row.getString("deviceId");
|
||||
this.deviceName = row.getString("deviceName");
|
||||
this.lat = row.getFloat("lat");
|
||||
this.lon = row.getFloat("lon");
|
||||
@@ -26,7 +26,7 @@ public class DevicePollutionMap {
|
||||
this.timestamp = DateParser.parseDate(row.getLocalDateTime("timestamp"));
|
||||
}
|
||||
|
||||
public DevicePollutionMap(Integer deviceId, String deviceName, Float lat, Float lon, Float carbonMonoxide,
|
||||
public DevicePollutionMap(String deviceId, String deviceName, Float lat, Float lon, Float carbonMonoxide,
|
||||
Long timestamp) {
|
||||
super();
|
||||
this.deviceId = deviceId;
|
||||
@@ -37,7 +37,7 @@ public class DevicePollutionMap {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
public Integer getDeviceId() {
|
||||
public String getDeviceId() {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import net.miarma.contaminus.util.DateParser;
|
||||
|
||||
@Table("v_sensor_history_by_device")
|
||||
public class DeviceSensorHistory {
|
||||
private Integer deviceId;
|
||||
private String deviceId;
|
||||
private String deviceName;
|
||||
private Float value;
|
||||
private String valueType;
|
||||
@@ -17,14 +17,14 @@ public class DeviceSensorHistory {
|
||||
public DeviceSensorHistory() {}
|
||||
|
||||
public DeviceSensorHistory(Row row) {
|
||||
this.deviceId = row.getInteger("deviceId");
|
||||
this.deviceId = row.getString("deviceId");
|
||||
this.deviceName = row.getString("deviceName");
|
||||
this.value = row.getFloat("value");
|
||||
this.valueType = row.getString("valueType");
|
||||
this.timestamp = DateParser.parseDate(row.getLocalDateTime("timestamp"));
|
||||
}
|
||||
|
||||
public DeviceSensorHistory(Integer deviceId, String deviceName, Float value, String valueType, Long timestamp) {
|
||||
public DeviceSensorHistory(String deviceId, String deviceName, Float value, String valueType, Long timestamp) {
|
||||
super();
|
||||
this.deviceId = deviceId;
|
||||
this.deviceName = deviceName;
|
||||
@@ -33,7 +33,7 @@ public class DeviceSensorHistory {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
public Integer getDeviceId() {
|
||||
public String getDeviceId() {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import net.miarma.contaminus.util.DateParser;
|
||||
@Table("v_sensor_values")
|
||||
public class DeviceSensorValue {
|
||||
private Integer sensorId;
|
||||
private Integer deviceId;
|
||||
private String deviceId;
|
||||
private String sensorType;
|
||||
private String unit;
|
||||
private Integer sensorStatus;
|
||||
@@ -24,7 +24,7 @@ public class DeviceSensorValue {
|
||||
|
||||
public DeviceSensorValue(Row row) {
|
||||
this.sensorId = row.getInteger("sensorId");
|
||||
this.deviceId = row.getInteger("deviceId");
|
||||
this.deviceId = row.getString("deviceId");
|
||||
this.sensorType = row.getString("sensorType");
|
||||
this.unit = row.getString("unit");
|
||||
this.sensorStatus = row.getInteger("sensorStatus");
|
||||
@@ -36,7 +36,7 @@ public class DeviceSensorValue {
|
||||
this.timestamp = DateParser.parseDate(row.getLocalDateTime("timestamp"));
|
||||
}
|
||||
|
||||
public DeviceSensorValue(Integer sensorId, Integer deviceId, String sensorType, String unit, Integer sensorStatus,
|
||||
public DeviceSensorValue(Integer sensorId, String deviceId, String sensorType, String unit, Integer sensorStatus,
|
||||
Float temperature, Float humidity, Float carbonMonoxide, Float lat, Float lon, Long timestamp) {
|
||||
super();
|
||||
this.sensorId = sensorId;
|
||||
@@ -56,7 +56,7 @@ public class DeviceSensorValue {
|
||||
return sensorId;
|
||||
}
|
||||
|
||||
public Integer getDeviceId() {
|
||||
public String getDeviceId() {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import net.miarma.contaminus.util.DateParser;
|
||||
|
||||
@Table("v_weather_by_device")
|
||||
public class DeviceWeather {
|
||||
private Integer deviceId;
|
||||
private String deviceId;
|
||||
private Float temperature;
|
||||
private Float humidity;
|
||||
private Long timestamp;
|
||||
@@ -16,13 +16,13 @@ public class DeviceWeather {
|
||||
public DeviceWeather() {}
|
||||
|
||||
public DeviceWeather(Row row) {
|
||||
this.deviceId = row.getInteger("deviceId");
|
||||
this.deviceId = row.getString("deviceId");
|
||||
this.temperature = row.getFloat("temperature");
|
||||
this.humidity = row.getFloat("humidity");
|
||||
this.timestamp = DateParser.parseDate(row.getLocalDateTime("timestamp"));
|
||||
}
|
||||
|
||||
public DeviceWeather(Integer deviceId, Float temperature, Float humidity, Long timestamp) {
|
||||
public DeviceWeather(String deviceId, Float temperature, Float humidity, Long timestamp) {
|
||||
super();
|
||||
this.deviceId = deviceId;
|
||||
this.temperature = temperature;
|
||||
@@ -30,7 +30,7 @@ public class DeviceWeather {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
public Integer getDeviceId() {
|
||||
public String getDeviceId() {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import net.miarma.contaminus.util.DateParser;
|
||||
public class GpsValue {
|
||||
|
||||
private Integer valueId;
|
||||
private String deviceId;
|
||||
private Integer sensorId;
|
||||
private Float lat;
|
||||
private Float lon;
|
||||
@@ -19,15 +20,17 @@ public class GpsValue {
|
||||
|
||||
public GpsValue(Row row) {
|
||||
this.valueId = row.getInteger("valueId");
|
||||
this.deviceId = row.getString("deviceId");
|
||||
this.sensorId = row.getInteger("sensorId");
|
||||
this.lat = row.getFloat("lat");
|
||||
this.lon = row.getFloat("lon");
|
||||
this.timestamp = DateParser.parseDate(row.getLocalDateTime("timestamp"));
|
||||
}
|
||||
|
||||
public GpsValue(Integer valueId, Integer sensorId, Float lat, Float lon, Long timestamp) {
|
||||
public GpsValue(Integer valueId, String deviceId, Integer sensorId, Float lat, Float lon, Long timestamp) {
|
||||
super();
|
||||
this.valueId = valueId;
|
||||
this.deviceId = deviceId;
|
||||
this.sensorId = sensorId;
|
||||
this.lat = lat;
|
||||
this.lon = lon;
|
||||
@@ -42,6 +45,14 @@ public class GpsValue {
|
||||
this.valueId = valueId;
|
||||
}
|
||||
|
||||
public String getDeviceId() {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
public void setDeviceId(String deviceId) {
|
||||
this.deviceId = deviceId;
|
||||
}
|
||||
|
||||
public Integer getSensorId() {
|
||||
return sensorId;
|
||||
}
|
||||
@@ -76,7 +87,7 @@ public class GpsValue {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(lat, lon, sensorId, timestamp, valueId);
|
||||
return Objects.hash(deviceId, lat, lon, sensorId, timestamp, valueId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -88,17 +99,20 @@ public class GpsValue {
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
GpsValue other = (GpsValue) obj;
|
||||
return Objects.equals(lat, other.lat) && Objects.equals(lon, other.lon)
|
||||
&& Objects.equals(sensorId, other.sensorId) && Objects.equals(timestamp, other.timestamp)
|
||||
&& Objects.equals(valueId, other.valueId);
|
||||
return Objects.equals(deviceId, other.deviceId) && Objects.equals(lat, other.lat)
|
||||
&& Objects.equals(lon, other.lon) && Objects.equals(sensorId, other.sensorId)
|
||||
&& Objects.equals(timestamp, other.timestamp) && Objects.equals(valueId, other.valueId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GpsValue [valueId=" + valueId + ", sensorId=" + sensorId + ", lat=" + lat + ", lon=" + lon
|
||||
+ ", timestamp=" + timestamp + "]";
|
||||
return "GpsValue [valueId=" + valueId + ", deviceId=" + deviceId + ", sensorId=" + sensorId + ", lat=" + lat
|
||||
+ ", lon=" + lon + ", timestamp=" + timestamp + "]";
|
||||
}
|
||||
|
||||
|
||||
public static GpsValue fromPayload(DevicePayload payload) {
|
||||
return new GpsValue(null, payload.getDeviceId(), payload.getSensorId(), payload.getLat(), payload.getLon(),
|
||||
payload.getTimestamp());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import net.miarma.contaminus.util.DateParser;
|
||||
public class Sensor {
|
||||
|
||||
private Integer sensorId;
|
||||
private Integer deviceId;
|
||||
private String deviceId;
|
||||
private String sensorType;
|
||||
private String unit;
|
||||
private Integer status;
|
||||
@@ -20,14 +20,14 @@ public class Sensor {
|
||||
|
||||
public Sensor(Row row) {
|
||||
this.sensorId = row.getInteger("sensorId");
|
||||
this.deviceId = row.getInteger("deviceId");
|
||||
this.deviceId = row.getString("deviceId");
|
||||
this.sensorType = row.getString("sensorType");
|
||||
this.unit = row.getString("unit");
|
||||
this.status = row.getInteger("status");
|
||||
this.timestamp = DateParser.parseDate(row.getLocalDateTime("timestamp"));
|
||||
}
|
||||
|
||||
public Sensor(Integer sensorId, Integer deviceId, String sensorType, String unit, Integer status, Long timestamp) {
|
||||
public Sensor(Integer sensorId, String deviceId, String sensorType, String unit, Integer status, Long timestamp) {
|
||||
super();
|
||||
this.sensorId = sensorId;
|
||||
this.deviceId = deviceId;
|
||||
@@ -45,11 +45,11 @@ public class Sensor {
|
||||
this.sensorId = sensorId;
|
||||
}
|
||||
|
||||
public Integer getDeviceId() {
|
||||
public String getDeviceId() {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
public void setDeviceId(Integer deviceId) {
|
||||
public void setDeviceId(String deviceId) {
|
||||
this.deviceId = deviceId;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,27 +10,33 @@ import net.miarma.contaminus.util.DateParser;
|
||||
public class WeatherValue {
|
||||
|
||||
private Integer valueId;
|
||||
private String deviceId;
|
||||
private Integer sensorId;
|
||||
private Float temperature;
|
||||
private Float humidity;
|
||||
private Float pressure;
|
||||
private Long timestamp;
|
||||
|
||||
public WeatherValue() {}
|
||||
|
||||
public WeatherValue(Row row) {
|
||||
this.valueId = row.getInteger("valueId");
|
||||
this.deviceId = row.getString("deviceId");
|
||||
this.sensorId = row.getInteger("sensorId");
|
||||
this.temperature = row.getFloat("temperature");
|
||||
this.humidity = row.getFloat("humidity");
|
||||
this.pressure = row.getFloat("pressure");
|
||||
this.timestamp = DateParser.parseDate(row.getLocalDateTime("timestamp"));
|
||||
}
|
||||
|
||||
public WeatherValue(Integer valueId, Integer sensorId, Float temperature, Float humidity, Long timestamp) {
|
||||
public WeatherValue(Integer valueId, String deviceId, Integer sensorId, Float temperature, Float humidity, Float pressure, Long timestamp) {
|
||||
super();
|
||||
this.valueId = valueId;
|
||||
this.deviceId = deviceId;
|
||||
this.sensorId = sensorId;
|
||||
this.temperature = temperature;
|
||||
this.humidity = humidity;
|
||||
this.pressure = pressure;
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
@@ -42,6 +48,14 @@ public class WeatherValue {
|
||||
this.valueId = valueId;
|
||||
}
|
||||
|
||||
public String getDeviceId() {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
public void setDeviceId(String deviceId) {
|
||||
this.deviceId = deviceId;
|
||||
}
|
||||
|
||||
public Integer getSensorId() {
|
||||
return sensorId;
|
||||
}
|
||||
@@ -66,6 +80,14 @@ public class WeatherValue {
|
||||
this.humidity = humidity;
|
||||
}
|
||||
|
||||
public Float getPressure() {
|
||||
return pressure;
|
||||
}
|
||||
|
||||
public void setPressure(Float pressure) {
|
||||
this.pressure = pressure;
|
||||
}
|
||||
|
||||
public Long getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
@@ -76,7 +98,7 @@ public class WeatherValue {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(humidity, sensorId, temperature, timestamp, valueId);
|
||||
return Objects.hash(deviceId, humidity, pressure, sensorId, temperature, timestamp, valueId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -88,17 +110,22 @@ public class WeatherValue {
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
WeatherValue other = (WeatherValue) obj;
|
||||
return Objects.equals(humidity, other.humidity) && Objects.equals(sensorId, other.sensorId)
|
||||
return Objects.equals(deviceId, other.deviceId) && Objects.equals(humidity, other.humidity)
|
||||
&& Objects.equals(pressure, other.pressure) && Objects.equals(sensorId, other.sensorId)
|
||||
&& Objects.equals(temperature, other.temperature) && Objects.equals(timestamp, other.timestamp)
|
||||
&& Objects.equals(valueId, other.valueId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "WeatherValue [valueId=" + valueId + ", sensorId=" + sensorId + ", temperature=" + temperature
|
||||
+ ", humidity=" + humidity + ", timestamp=" + timestamp + "]";
|
||||
return "WeatherValue [valueId=" + valueId + ", deviceId=" + deviceId + ", sensorId=" + sensorId
|
||||
+ ", temperature=" + temperature + ", humidity=" + humidity + ", pressure=" + pressure + ", timestamp="
|
||||
+ timestamp + "]";
|
||||
}
|
||||
|
||||
|
||||
public static WeatherValue fromPayload(DevicePayload payload) {
|
||||
return new WeatherValue(null, payload.getDeviceId(), payload.getSensorId(), payload.getTemperature(),
|
||||
payload.getHumidity(), payload.getPressure(), payload.getTimestamp());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,13 +23,17 @@ import net.miarma.contaminus.common.SingleJsonResponse;
|
||||
import net.miarma.contaminus.database.DatabaseManager;
|
||||
import net.miarma.contaminus.database.QueryBuilder;
|
||||
import net.miarma.contaminus.database.entities.Actuator;
|
||||
import net.miarma.contaminus.database.entities.COValue;
|
||||
import net.miarma.contaminus.database.entities.Device;
|
||||
import net.miarma.contaminus.database.entities.DeviceLatestValuesView;
|
||||
import net.miarma.contaminus.database.entities.DevicePayload;
|
||||
import net.miarma.contaminus.database.entities.DevicePollutionMap;
|
||||
import net.miarma.contaminus.database.entities.DeviceSensorHistory;
|
||||
import net.miarma.contaminus.database.entities.DeviceSensorValue;
|
||||
import net.miarma.contaminus.database.entities.GpsValue;
|
||||
import net.miarma.contaminus.database.entities.Group;
|
||||
import net.miarma.contaminus.database.entities.Sensor;
|
||||
import net.miarma.contaminus.database.entities.WeatherValue;
|
||||
|
||||
/*
|
||||
* This class is a Verticle that will handle the Data Layer API.
|
||||
@@ -76,6 +80,9 @@ public class DataLayerAPIVerticle extends AbstractVerticle {
|
||||
.allowedMethods(allowedMethods));
|
||||
router.route().handler(BodyHandler.create());
|
||||
|
||||
// Payload
|
||||
router.route(HttpMethod.POST, Constants.POST_PAYLOAD).handler(this::addDevicePayload);
|
||||
|
||||
// Group Routes
|
||||
router.route(HttpMethod.GET, Constants.GET_GROUPS).handler(this::getAllGroups);
|
||||
router.route(HttpMethod.GET, Constants.GET_GROUP_BY_ID).handler(this::getGroupById);
|
||||
@@ -121,6 +128,48 @@ public class DataLayerAPIVerticle extends AbstractVerticle {
|
||||
});
|
||||
}
|
||||
|
||||
private void addDevicePayload(RoutingContext context) {
|
||||
JsonObject body = context.body().asJsonObject();
|
||||
DevicePayload devicePayload = gson.fromJson(body.toString(), DevicePayload.class);
|
||||
COValue coValue = COValue.fromPayload(devicePayload);
|
||||
GpsValue gpsValue = GpsValue.fromPayload(devicePayload);
|
||||
WeatherValue weatherValue = WeatherValue.fromPayload(devicePayload);
|
||||
|
||||
String coQuery = QueryBuilder
|
||||
.insert(coValue)
|
||||
.build();
|
||||
|
||||
String gpsQuery = QueryBuilder
|
||||
.insert(gpsValue)
|
||||
.build();
|
||||
|
||||
String weatherQuery = QueryBuilder
|
||||
.insert(weatherValue)
|
||||
.build();
|
||||
|
||||
dbManager.execute(coQuery, COValue.class,
|
||||
onSuccess -> {
|
||||
dbManager.execute(gpsQuery, GpsValue.class,
|
||||
onSuccess2 -> {
|
||||
dbManager.execute(weatherQuery, WeatherValue.class,
|
||||
onSuccess3 -> {
|
||||
context.response()
|
||||
.putHeader("content-type", "application/json; charset=utf-8")
|
||||
.end(gson.toJson(SingleJsonResponse.of("Payload added successfully")));
|
||||
},
|
||||
onFailure3 -> {
|
||||
context.fail(500, onFailure3);
|
||||
});
|
||||
},
|
||||
onFailure2 -> {
|
||||
context.fail(500, onFailure2);
|
||||
});
|
||||
},
|
||||
onFailure -> {
|
||||
context.fail(500, onFailure);
|
||||
});
|
||||
}
|
||||
|
||||
private void getAllGroups(RoutingContext context) {
|
||||
String query = QueryBuilder
|
||||
.select(Group.class)
|
||||
@@ -211,7 +260,7 @@ public class DataLayerAPIVerticle extends AbstractVerticle {
|
||||
}
|
||||
|
||||
private void getDeviceById(RoutingContext context) {
|
||||
Integer deviceId = Integer.parseInt(context.request().getParam("deviceId"));
|
||||
String deviceId = context.request().getParam("deviceId");
|
||||
Device device = new Device(deviceId, null, null);
|
||||
|
||||
String query = QueryBuilder
|
||||
|
||||
@@ -95,7 +95,7 @@ public class LogicLayerAPIVerticle extends AbstractVerticle {
|
||||
}
|
||||
|
||||
private void getDeviceSensors(RoutingContext context) {
|
||||
Integer deviceId = Integer.parseInt(context.request().getParam("deviceId"));
|
||||
String deviceId = context.request().getParam("deviceId");
|
||||
Promise<Sensor[]> resultList = Promise.promise();
|
||||
resultList.future().onComplete(result -> {
|
||||
if (result.succeeded()) {
|
||||
@@ -114,7 +114,7 @@ public class LogicLayerAPIVerticle extends AbstractVerticle {
|
||||
}
|
||||
|
||||
private void getDeviceActuators(RoutingContext context) {
|
||||
Integer deviceId = Integer.parseInt(context.request().getParam("deviceId"));
|
||||
String deviceId = context.request().getParam("deviceId");
|
||||
Promise<Actuator[]> resultList = Promise.promise();
|
||||
resultList.future().onComplete(result -> {
|
||||
if (result.succeeded()) {
|
||||
@@ -133,7 +133,7 @@ public class LogicLayerAPIVerticle extends AbstractVerticle {
|
||||
}
|
||||
|
||||
private void getDeviceLatestValues(RoutingContext context) {
|
||||
Integer deviceId = Integer.parseInt(context.request().getParam("deviceId"));
|
||||
String deviceId = context.request().getParam("deviceId");
|
||||
|
||||
Promise<DeviceLatestValuesView[]> resultList = Promise.promise();
|
||||
resultList.future().onComplete(complete -> {
|
||||
@@ -155,7 +155,7 @@ public class LogicLayerAPIVerticle extends AbstractVerticle {
|
||||
}
|
||||
|
||||
private void getDevicePollutionMap(RoutingContext context) {
|
||||
Integer deviceId = Integer.parseInt(context.request().getParam("deviceId"));
|
||||
String deviceId = context.request().getParam("deviceId");
|
||||
|
||||
Promise<DevicePollutionMap[]> resultList = Promise.promise();
|
||||
|
||||
@@ -178,7 +178,7 @@ public class LogicLayerAPIVerticle extends AbstractVerticle {
|
||||
}
|
||||
|
||||
private void getDeviceHistory(RoutingContext context) {
|
||||
Integer deviceId = Integer.parseInt(context.request().getParam("deviceId"));
|
||||
String deviceId = context.request().getParam("deviceId");
|
||||
|
||||
Promise<DeviceSensorHistory[]> resultList = Promise.promise();
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <Wire.h>
|
||||
#include <BME280I2C.h>
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "TinyGPSPlus.h"
|
||||
|
||||
struct GPSData_t
|
||||
|
||||
@@ -1,46 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <HTTPClient.h>
|
||||
|
||||
String serializeSensorValue(
|
||||
int sensorId,
|
||||
int deviceId,
|
||||
String sensorType,
|
||||
String unit,
|
||||
const String &deviceId,
|
||||
const String &sensorType,
|
||||
const String &unit,
|
||||
int sensorStatus,
|
||||
float temperature,
|
||||
float humidity,
|
||||
float carbonMonoxide,
|
||||
float lat,
|
||||
float lon,
|
||||
const BME280Data_t &bme,
|
||||
const MQ7Data_t &mq7,
|
||||
const GPSData_t &gps,
|
||||
long timestamp
|
||||
);
|
||||
|
||||
String serializeActuatorStatus(
|
||||
int actuatorId,
|
||||
int deviceId,
|
||||
const String &deviceId,
|
||||
int status,
|
||||
long timestamp
|
||||
);
|
||||
|
||||
String serializeDevice (
|
||||
int sensorId,
|
||||
int deviceId,
|
||||
String sensorType,
|
||||
int status,
|
||||
long timestamp
|
||||
);
|
||||
|
||||
void deserializeSensorValue (
|
||||
HTTPClient &http,
|
||||
int httpResponseCode
|
||||
);
|
||||
|
||||
void deserializeActuatorStatus (
|
||||
HTTPClient &http,
|
||||
int httpResponseCode
|
||||
);
|
||||
|
||||
void deserializeDevice (
|
||||
HTTPClient &http,
|
||||
int httpResponseCode
|
||||
);
|
||||
void deserializeSensorValue(HTTPClient &http, int httpResponseCode);
|
||||
void deserializeActuatorStatus(HTTPClient &http, int httpResponseCode);
|
||||
void deserializeDevice(HTTPClient &http, int httpResponseCode);
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <MD_Parola.h>
|
||||
#include <MD_MAX72xx.h>
|
||||
#include <SPI.h>
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#define MQ7_A0 34
|
||||
|
||||
@@ -1,2 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
#include <WiFi.h>
|
||||
#include <PubSubClient.h>
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <HTTPClient.h>
|
||||
|
||||
void getRequest(HTTPClient &httpClient, const String url, String &response);
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <WiFi.h>
|
||||
#include <PubSubClient.h>
|
||||
|
||||
|
||||
@@ -20,7 +20,8 @@
|
||||
#include "MAX7219.hpp"
|
||||
#include "MQ7v2.hpp"
|
||||
|
||||
struct TaskTimer {
|
||||
struct TaskTimer
|
||||
{
|
||||
uint32_t lastRun = 0;
|
||||
uint32_t interval = 1000;
|
||||
|
||||
@@ -30,7 +31,14 @@ struct TaskTimer {
|
||||
: lastRun(last), interval(interval) {}
|
||||
};
|
||||
|
||||
enum AirQualityStatus {
|
||||
struct SensorInfo
|
||||
{
|
||||
int id;
|
||||
String type;
|
||||
};
|
||||
|
||||
enum AirQualityStatus
|
||||
{
|
||||
GOOD,
|
||||
BAD
|
||||
};
|
||||
|
||||
@@ -1,31 +1,39 @@
|
||||
#include "JsonTools.hpp"
|
||||
|
||||
String serializeSensorValue(int sensorId, int deviceId, String sensorType, String unit, int sensorStatus, float temperature, float humidity, float carbonMonoxide, float lat, float lon, long timestamp)
|
||||
{
|
||||
DynamicJsonDocument doc(2048);
|
||||
String serializeSensorValue(
|
||||
int sensorId,
|
||||
const String &deviceId,
|
||||
const String &sensorType,
|
||||
const String &unit,
|
||||
int sensorStatus,
|
||||
const BME280Data_t &bme,
|
||||
const MQ7Data_t &mq7,
|
||||
const GPSData_t &gps,
|
||||
long timestamp
|
||||
) {
|
||||
DynamicJsonDocument doc(1024);
|
||||
|
||||
doc["sensorId"] = sensorId;
|
||||
doc["deviceId"] = deviceId;
|
||||
doc["sensorType"] = sensorType;
|
||||
doc["unit"] = unit;
|
||||
doc["sesnsorStatuts"] = sensorStatus;
|
||||
doc["temperature"] = temperature;
|
||||
doc["humidity"] = humidity;
|
||||
doc["carbonMonoxide"] = carbonMonoxide;
|
||||
doc["lat"] = lat;
|
||||
doc["lon"] = lon;
|
||||
doc["sensorStatus"] = sensorStatus;
|
||||
doc["temperature"] = bme.temperature;
|
||||
doc["humidity"] = bme.humidity;
|
||||
doc["pressure"] = bme.pressure;
|
||||
doc["carbonMonoxide"] = mq7.co;
|
||||
doc["lat"] = gps.lat;
|
||||
doc["lon"] = gps.lon;
|
||||
doc["timestamp"] = timestamp;
|
||||
|
||||
String output;
|
||||
serializeJson(doc, output);
|
||||
Serial.println(output);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
String serializeActuatorStatus (int actuatorId, int deviceId, int status, long timestamp)
|
||||
{
|
||||
DynamicJsonDocument doc(2048);
|
||||
String serializeActuatorStatus(const int actuatorId, const String &deviceId, const int status, const long timestamp) {
|
||||
DynamicJsonDocument doc(512);
|
||||
|
||||
doc["actuatorId"] = actuatorId;
|
||||
doc["deviceId"] = deviceId;
|
||||
@@ -35,53 +43,43 @@ String serializeActuatorStatus (int actuatorId, int deviceId, int status, long t
|
||||
String output;
|
||||
serializeJson(doc, output);
|
||||
Serial.println(output);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
String serializeDevice(int sensorId, int deviceId, String sensorType, int status, long timestamp)
|
||||
{
|
||||
DynamicJsonDocument doc(2048);
|
||||
String serializeDevice(const String &deviceId, int groupId, const String &deviceName) {
|
||||
DynamicJsonDocument doc(512);
|
||||
|
||||
doc["sensorId"] = sensorId;
|
||||
doc["deviceId"] = deviceId;
|
||||
doc["sensorType"] = sensorType;
|
||||
doc["status"] = status;
|
||||
doc["timestamp"] = timestamp;
|
||||
doc["groupId"] = groupId;
|
||||
doc["deviceName"] = deviceName;
|
||||
|
||||
String output;
|
||||
serializeJson(doc, output);
|
||||
Serial.println(output);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
void deserializeSensorValue (HTTPClient &http, int httpResponseCode)
|
||||
{
|
||||
|
||||
if (httpResponseCode > 0)
|
||||
{
|
||||
void deserializeSensorValue(HTTPClient &http, int httpResponseCode) {
|
||||
if (httpResponseCode > 0) {
|
||||
Serial.print("HTTP Response code: ");
|
||||
Serial.println(httpResponseCode);
|
||||
String responseJson = http.getString();
|
||||
DynamicJsonDocument doc(ESP.getMaxAllocHeap());
|
||||
DeserializationError error = deserializeJson(doc, responseJson);
|
||||
|
||||
if (error)
|
||||
{
|
||||
if (error) {
|
||||
Serial.print(F("deserializeJson() failed: "));
|
||||
Serial.println(error.f_str());
|
||||
return;
|
||||
}
|
||||
|
||||
JsonArray array = doc.as<JsonArray>();
|
||||
for (JsonObject sensor : array)
|
||||
{
|
||||
for (JsonObject sensor : array) {
|
||||
int sensorId = sensor["sensorId"];
|
||||
int deviceId = sensor["deviceId"];
|
||||
String deviceId = sensor["deviceId"];
|
||||
String sensorType = sensor["sensorType"];
|
||||
String unit = sensor["unit"];
|
||||
int sesnsorStatuts = sensor["sesnsorStatuts"];
|
||||
int sensorStatus = sensor["sensorStatus"];
|
||||
float temperature = sensor["temperature"];
|
||||
float humidity = sensor["humidity"];
|
||||
float carbonMonoxide = sensor["carbonMonoxide"];
|
||||
@@ -89,90 +87,72 @@ void deserializeSensorValue (HTTPClient &http, int httpResponseCode)
|
||||
float lon = sensor["lon"];
|
||||
long timestamp = sensor["timestamp"];
|
||||
|
||||
Serial.println(("Sensor deserialized: [sensorId: " + String(sensorId) + ", deviceId: " + String(deviceId) + ", sensorType: " + sensorType + ", unit: " + unit +", sesnsorStatuts: " + String(sesnsorStatuts) +", temperature: " + String(temperature) +", humidity: " + String(humidity) +", carbonMonoxide: " + String(carbonMonoxide) +", lat: " + String(lat) +", lon: " + String(lon) +", timestamp: " + String(timestamp) + "]").c_str());
|
||||
Serial.println("Sensor deserialized:");
|
||||
Serial.printf(" ID: %d\n Device: %s\n Type: %s\n Unit: %s\n Status: %d\n Temp: %.2f\n Hum: %.2f\n CO: %.2f\n Lat: %.6f\n Lon: %.6f\n Time: %ld\n\n",
|
||||
sensorId, deviceId.c_str(), sensorType.c_str(), unit.c_str(), sensorStatus,
|
||||
temperature, humidity, carbonMonoxide, lat, lon, timestamp);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
Serial.print("Error code: ");
|
||||
Serial.println(httpResponseCode);
|
||||
}
|
||||
}
|
||||
|
||||
void deserializeActuatorStatus (HTTPClient &http, int httpResponseCode)
|
||||
{
|
||||
|
||||
if (httpResponseCode > 0)
|
||||
{
|
||||
void deserializeActuatorStatus(HTTPClient &http, int httpResponseCode) {
|
||||
if (httpResponseCode > 0) {
|
||||
Serial.print("HTTP Response code: ");
|
||||
Serial.println(httpResponseCode);
|
||||
String responseJson = http.getString();
|
||||
DynamicJsonDocument doc(ESP.getMaxAllocHeap());
|
||||
DeserializationError error = deserializeJson(doc, responseJson);
|
||||
|
||||
if (error)
|
||||
{
|
||||
if (error) {
|
||||
Serial.print(F("deserializeJson() failed: "));
|
||||
Serial.println(error.f_str());
|
||||
return;
|
||||
}
|
||||
|
||||
JsonArray array = doc.as<JsonArray>();
|
||||
for (JsonObject actuator : array)
|
||||
{
|
||||
int actuadorId = actuator["actuadorId"];
|
||||
int deviceId = actuator["deviceId"];
|
||||
int statuts = actuator["statuts"];
|
||||
for (JsonObject actuator : array) {
|
||||
int actuatorId = actuator["actuatorId"];
|
||||
String deviceId = actuator["deviceId"];
|
||||
int status = actuator["status"];
|
||||
long timestamp = actuator["timestamp"];
|
||||
|
||||
Serial.println(("Actuador deserialized: [actuadorId: " + String(actuadorId) +
|
||||
", deviceId: " + String(deviceId) +
|
||||
", statuts: " + String(statuts) +
|
||||
", timestamp: " + String(timestamp) + "]").c_str());
|
||||
Serial.println("Actuator deserialized:");
|
||||
Serial.printf(" ID: %d\n Device: %s\n Status: %d\n Time: %ld\n\n",
|
||||
actuatorId, deviceId.c_str(), status, timestamp);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
Serial.print("Error code: ");
|
||||
Serial.println(httpResponseCode);
|
||||
}
|
||||
}
|
||||
|
||||
void deserializeDevice (HTTPClient &http, int httpResponseCode)
|
||||
{
|
||||
|
||||
if (httpResponseCode > 0)
|
||||
{
|
||||
void deserializeDevice(HTTPClient &http, int httpResponseCode) {
|
||||
if (httpResponseCode > 0) {
|
||||
Serial.print("HTTP Response code: ");
|
||||
Serial.println(httpResponseCode);
|
||||
String responseJson = http.getString();
|
||||
DynamicJsonDocument doc(ESP.getMaxAllocHeap());
|
||||
DeserializationError error = deserializeJson(doc, responseJson);
|
||||
|
||||
if (error)
|
||||
{
|
||||
if (error) {
|
||||
Serial.print(F("deserializeJson() failed: "));
|
||||
Serial.println(error.f_str());
|
||||
return;
|
||||
}
|
||||
|
||||
JsonArray array = doc.as<JsonArray>();
|
||||
for (JsonObject device : array)
|
||||
{
|
||||
int sensorId = device["sensorId"];
|
||||
int deviceId = device["deviceId"];
|
||||
String sensorType = device["sensorType"];
|
||||
long timestamp = device["timestamp"];
|
||||
|
||||
Serial.println(("Sensor deserialized: [sensorId: " + String(sensorId) +
|
||||
", deviceId: " + String(deviceId) +
|
||||
", sensorType: " + sensorType +
|
||||
", timestamp: " + String(timestamp) + "]").c_str());
|
||||
for (JsonObject device : array) {
|
||||
String deviceId = device["deviceId"];
|
||||
int groupId = device["groupId"];
|
||||
String deviceName = device["deviceName"];
|
||||
|
||||
Serial.println("Device deserialized:");
|
||||
Serial.printf(" ID: %s\n Group: %d\n Name: %s\n\n", deviceId.c_str(), groupId, deviceName.c_str());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
Serial.print("Error code: ");
|
||||
Serial.println(httpResponseCode);
|
||||
}
|
||||
|
||||
@@ -57,8 +57,6 @@ void loop()
|
||||
printAllData();
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
globalTimer.lastRun = now;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user