changed deviceId from Integer to String/CHAR(6)
This commit is contained in:
@@ -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 (
|
||||
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,
|
||||
int status,
|
||||
String serializeActuatorStatus(
|
||||
int actuatorId,
|
||||
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