Update WiFi connection handling, adjust MQTT timer, and implement group ID deserialization
This commit is contained in:
@@ -36,6 +36,7 @@ String serializeSensorValue(
|
||||
return output;
|
||||
}
|
||||
|
||||
#if DEVICE_ROLE == ACTUATOR
|
||||
MAX7219Status_t deserializeActuatorStatus(HTTPClient &http, int httpResponseCode)
|
||||
{
|
||||
if (httpResponseCode > 0)
|
||||
@@ -86,3 +87,30 @@ MAX7219Status_t deserializeActuatorStatus(HTTPClient &http, int httpResponseCode
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
int deserializeGroupId(HTTPClient &http, int httpResponseCode)
|
||||
{
|
||||
if (httpResponseCode > 0)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
Serial.print("HTTP Response code: ");
|
||||
Serial.println(httpResponseCode);
|
||||
#endif
|
||||
String responseJson = http.getString();
|
||||
DynamicJsonDocument doc(ESP.getMaxAllocHeap());
|
||||
DeserializationError error = deserializeJson(doc, responseJson);
|
||||
|
||||
if (error)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
Serial.print(F("deserializeJson() failed: "));
|
||||
Serial.println(error.f_str());
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
return (int)doc["message"] | -1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@@ -5,7 +5,8 @@ const String mqttId = "CUS-" + String(DEVICE_ID, HEX);
|
||||
int GROUP_ID;
|
||||
|
||||
TaskTimer globalTimer{0, 10000};
|
||||
TaskTimer mqttTimer{0, 2500};
|
||||
TaskTimer mqttTimer{0, 5000};
|
||||
TaskTimer wifiTimer{0, 5000};
|
||||
|
||||
#if DEVICE_ROLE == ACTUATOR
|
||||
TaskTimer matrixTimer{0, 25};
|
||||
@@ -32,7 +33,11 @@ void setup()
|
||||
Serial.println("Iniciando...");
|
||||
#endif
|
||||
|
||||
WiFi_Init();
|
||||
while(WiFi_Init() != WL_CONNECTED)
|
||||
{
|
||||
Serial.println("Esperando conexión WiFi...");
|
||||
delay(1000);
|
||||
}
|
||||
MQTT_Init(MQTT_URI, MQTT_PORT);
|
||||
|
||||
try
|
||||
@@ -223,8 +228,7 @@ uint32_t getChipID()
|
||||
|
||||
int getGroupId(int deviceId)
|
||||
{
|
||||
String url = String(API_URI) + "groups/" + GROUP_ID + "/devices/" + String(DEVICE_ID, HEX) + "/actuators/" + MAX7219_ID + "/status";
|
||||
String url = String(RAW_API_URI) + "devices/" + String(DEVICE_ID, HEX) + "/my-group";
|
||||
getRequest(url, response);
|
||||
MAX7219Status_t statusData = deserializeActuatorStatus(httpClient, httpClient.GET());
|
||||
currentMessage = statusData.actuatorStatus;
|
||||
return deserializeGroupId(httpClient, httpClient.GET());
|
||||
}
|
||||
Reference in New Issue
Block a user