Created a new task in order to test the HttpClient class

This commit is contained in:
anschrammh 2019-12-28 14:10:50 +01:00
parent af25f55089
commit 2b32fd68ea
2 changed files with 59 additions and 16 deletions

View File

@ -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<DictionaryHelper::StringEntity> getData;
getData.add("key1", DictionaryHelper::StringEntity("value1"));
getData.add("key2", DictionaryHelper::StringEntity(NULL));
getData.add("key3", DictionaryHelper::StringEntity("value3"));
getData.add("key4", NULL);
Dictionary<DictionaryHelper::StringEntity> 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;
}

View File

@ -3,11 +3,18 @@
#include <Arduino.h>
#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