fix network task
This commit is contained in:
16
Network.cpp
16
Network.cpp
@@ -49,7 +49,7 @@ void Network::initialize()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Network::reconnect()
|
bool Network::reconnect()
|
||||||
{
|
{
|
||||||
while (!_mqttClient.connected()) {
|
while (!_mqttClient.connected()) {
|
||||||
Serial.print("Attempting MQTT connection...");
|
Serial.print("Attempting MQTT connection...");
|
||||||
@@ -73,9 +73,19 @@ void Network::reconnect()
|
|||||||
|
|
||||||
void Network::update()
|
void Network::update()
|
||||||
{
|
{
|
||||||
|
if(!WiFi.isConnected())
|
||||||
|
{
|
||||||
|
Serial.println(F("WiFi not connected"));
|
||||||
|
vTaskDelay( 1000 / portTICK_PERIOD_MS);
|
||||||
|
}
|
||||||
|
|
||||||
if(!_mqttClient.connected())
|
if(!_mqttClient.connected())
|
||||||
{
|
{
|
||||||
reconnect();
|
bool success = reconnect();
|
||||||
|
if(!success)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long ts = millis();
|
unsigned long ts = millis();
|
||||||
@@ -92,4 +102,6 @@ void Network::update()
|
|||||||
}
|
}
|
||||||
|
|
||||||
_mqttClient.loop();
|
_mqttClient.loop();
|
||||||
|
|
||||||
|
vTaskDelay( 100 / portTICK_PERIOD_MS);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ public:
|
|||||||
void update();
|
void update();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void reconnect();
|
bool reconnect();
|
||||||
|
|
||||||
PubSubClient _mqttClient;
|
PubSubClient _mqttClient;
|
||||||
WiFiClient _wifiClient;
|
WiFiClient _wifiClient;
|
||||||
|
|||||||
27
main.cpp
27
main.cpp
@@ -11,7 +11,10 @@ Nuki nuki("door", 0);
|
|||||||
|
|
||||||
void networkTask(void *pvParameters)
|
void networkTask(void *pvParameters)
|
||||||
{
|
{
|
||||||
network.update();
|
while(true)
|
||||||
|
{
|
||||||
|
network.update();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void nukiTask(void *pvParameters)
|
void nukiTask(void *pvParameters)
|
||||||
@@ -21,32 +24,16 @@ void nukiTask(void *pvParameters)
|
|||||||
|
|
||||||
void setupTasks()
|
void setupTasks()
|
||||||
{
|
{
|
||||||
xTaskCreate(networkTask, "ntw", 1024, NULL, 1, NULL);
|
xTaskCreate(networkTask, "ntw", 2048, NULL, 1, NULL);
|
||||||
xTaskCreate(nukiTask, "nuki", 1024, NULL, 1, NULL);
|
// xTaskCreate(nukiTask, "nuki", 1024, NULL, 1, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
network.initialize();
|
network.initialize();
|
||||||
// nuki.initialize();
|
// nuki.initialize();
|
||||||
|
|
||||||
/*
|
|
||||||
Serial.begin(115200);
|
|
||||||
|
|
||||||
WiFi.begin(ssid, password);
|
|
||||||
|
|
||||||
while (WiFi.status() != WL_CONNECTED)
|
|
||||||
{
|
|
||||||
delay(500);
|
|
||||||
Serial.println("Connecting to WiFi..");
|
|
||||||
}
|
|
||||||
|
|
||||||
Serial.println("Connected to the WiFi network");
|
|
||||||
*/
|
|
||||||
setupTasks();
|
setupTasks();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{}
|
||||||
// nuki.update();
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user