From 2b32fd68eaf71b9d85de9cf81aa2d5dd21ab41bb Mon Sep 17 00:00:00 2001 From: anschrammh Date: Sat, 28 Dec 2019 14:10:50 +0100 Subject: [PATCH] Created a new task in order to test the HttpClient class --- src/app/tasks.cpp | 64 ++++++++++++++++++++++++++++++++++++----------- src/app/tasks.h | 11 ++++++-- 2 files changed, 59 insertions(+), 16 deletions(-) diff --git a/src/app/tasks.cpp b/src/app/tasks.cpp index bcc339e..af885da 100644 --- a/src/app/tasks.cpp +++ b/src/app/tasks.cpp @@ -1,19 +1,5 @@ #include "tasks.h" -boolean task1(void *pData) -{ - Serial.println("Hi, i am the task one"); - - return true; -} - -boolean task2(void *pData) -{ - Serial.println("Hi, i am the task two"); - - return true; -} - boolean task_blink(void *pData) { SAB *p = (SAB *) pData; @@ -34,4 +20,54 @@ boolean task_batt_sensing(void *pData) boolean task_esp_reset_restart(void * pData) { ESP.restart(); + + return true; +} + +boolean task_post_data_logger(void * pData) +{ + DataLogger *p = (DataLogger *) pData; + //This routine is here to test the new HttpClient class + //HttpClient httpClient("192.168.0.17", "/esp8266/dataLogger.php", 1234); + + if(p->counter == 0) + { + Dictionary getData; + getData.add("key1", DictionaryHelper::StringEntity("value1")); + getData.add("key2", DictionaryHelper::StringEntity(NULL)); + getData.add("key3", DictionaryHelper::StringEntity("value3")); + getData.add("key4", NULL); + + Dictionary postData; + postData.add("post1", DictionaryHelper::StringEntity("postvalue1")); + postData.add("post2", DictionaryHelper::StringEntity(NULL)); + postData.add("post3", DictionaryHelper::StringEntity("postvalue3")); + postData.add("post4", NULL); + + + if(p->client.sendHttpQuery(HttpClient::HttpRequestMethod::POST, &getData, &postData)) + { + Serial.println("Send successful"); + p->rdy = false; + } + } + else if(p->client.isReplyAvailable() != HttpClient::HTTP_CODE::UNDEFINED_CODE && !p->rdy) + { + Serial.printf("Code : %d, counter : %u\n", p->client.isReplyAvailable(), p->counter); + p->rdy = true; + } + + if(p->rdy) + { + char buff[100]; + p->client.readHttpReply((uint8_t *)buff, 100); + Serial.print(buff); + } + + p->counter++; + + if(p->counter == 30) + p->counter = 0; + + return true; } diff --git a/src/app/tasks.h b/src/app/tasks.h index a7431c0..fcec26d 100644 --- a/src/app/tasks.h +++ b/src/app/tasks.h @@ -3,11 +3,18 @@ #include #include "SAB.h" #include "views.h" +#include "HttpClient.h" -boolean task1(void *); -boolean task2(void *); boolean task_blink(void *); boolean task_batt_sensing(void *); boolean task_esp_reset_restart(void *); +typedef struct dataLogger +{ + HttpClient client; + uint8_t counter; + boolean rdy; +}DataLogger; +boolean task_post_data_logger(void *); + #endif //TASKS_H