From 877c8fa206681a93f6e2f09a97703954c7c90275 Mon Sep 17 00:00:00 2001 From: Guillermo Marcel Date: Sun, 20 Apr 2025 17:59:59 -0300 Subject: [PATCH] feat: add samples files --- others/HttpServerTests.h | 86 ++++++++++++++++++++++++++++++++++++++ others/MultiTaskTests.h | 83 ++++++++++++++++++++++++++++++++++++ others/updateResponse.json | 13 ++++++ 3 files changed, 182 insertions(+) create mode 100644 others/HttpServerTests.h create mode 100644 others/MultiTaskTests.h create mode 100644 others/updateResponse.json diff --git a/others/HttpServerTests.h b/others/HttpServerTests.h new file mode 100644 index 0000000..91e7b44 --- /dev/null +++ b/others/HttpServerTests.h @@ -0,0 +1,86 @@ +void SendNotifAsyncInt(void *pvParameters) +{ + for (;;) + { + if (!s.sendNotif && !s.isFired) + { + vTaskDelay(100 / portTICK_PERIOD_MS); + continue; + } + if (s.sendNotif) + { + s.eventId = millis(); + } + SendNotif(); + s.sendNotif = false; + vTaskDelay(FromSeconds(3) / portTICK_PERIOD_MS); + } +} +void SendNotif() +{ + // client2 = new WiFiClientSecure; + client2 = new WiFiClient; + + if (client2) + { + // set secure client with certificate + // client2->setCACert(francelsoft_root_ca); + // client2->setInsecure(); + // create an HTTPClient instance + HTTPClient https; + + // Initializing an HTTPS communication using the secure client + // if (https.begin(*client2, "https://push.francelsoft.com/test/publish?message=Unauthzorized+Access&priority=high&tags=warning,rotating_light")) { // HTTPS + + String eventtype = s.sendNotif ? "Fired" : "EventUpdate"; + String url = "http://10.88.88.169:9003/?eventId=" + String(s.eventId) + "&eventType=" + eventtype + "&eventData=t"; + Serial.print("[HTTPS] " + url); + if (https.begin(*client2, url)) + { // HTTPS + // Serial.print("[HTTPS] GET...\n"); + // start connection and send HTTP header + int httpCode = https.GET(); + // httpCode will be negative on error + if (httpCode > 0) + { + // HTTP header has been send and Server response header has been handled + // Serial.printf("[HTTPS] GET Finished... code: %d\n", httpCode); + // file found at server + if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) + { + // print server response payload + String payload = https.getString(); + if (payload == "AUTHORIZE_ENTRANCE") + { + // Todo Extract to Disarm method + Serial.println("Entrace authorized by servcer."); + s.isFired = false; + s.isArmed = s.doorStatus == DOOR_CLOSED; + } + + Serial.println(payload); + + // Dictionary &d = *(new Dictionary()); + // d.jload(payload); + + // Serial.println(d["authorizeEntrace"]); + // if(d["authorizeEntrance"]=="true"){ + // //Todo Extract to Disarm method + // Serial.println("Entrace authorized by servcer."); + // s.isFired=false; + // s.isArmed=s.doorStatus==DOOR_CLOSED; + // } + } + } + else + { + Serial.printf("[HTTPS] GET... failed, error: %s\n", https.errorToString(httpCode).c_str()); + } + https.end(); + } + } + else + { + Serial.printf("[HTTPS] Unable to connect\n"); + } +} \ No newline at end of file diff --git a/others/MultiTaskTests.h b/others/MultiTaskTests.h new file mode 100644 index 0000000..8d9e740 --- /dev/null +++ b/others/MultiTaskTests.h @@ -0,0 +1,83 @@ +TaskHandle_t Task1; +TaskHandle_t Task2; +const int led1 = 2; +const int led2 = 4; + +void stp() +{ + pinMode(led1, OUTPUT); + pinMode(led2, OUTPUT); + + xTaskCreatePinnedToCore( + Task1code, /* Task function. */ + "Task1", /* name of task. */ + 10000, /* Stack size of task */ + NULL, /* parameter of the task */ + 1, /* priority of the task */ + &Task1, /* Task handle to keep track of created task */ + 0); /* pin task to core 0 */ + // xTaskCreate(Task1code, "task1", 1000, NULL, 1, NULL); + delay(500); + + xTaskCreatePinnedToCore( + Task2code, /* Task function. */ + "Task2", /* name of task. */ + 10000, /* Stack size of task */ + NULL, /* parameter of the task */ + 1, /* priority of the task */ + &Task2, /* Task handle to keep track of created task */ + 1); /* pin task to core 1 */ + // xTaskCreate(Task2code, "task2", 1000, NULL, 1, NULL); + delay(500); +} + +// Task1code: blinks an LED every 1000 ms +void Task1code(void *pvParameters) +{ + Serial.print("Task1 running on core "); + Serial.println(xPortGetCoreID()); + + for (;;) + { + digitalWrite(led1, HIGH); + delay(1000); + digitalWrite(led1, LOW); + delay(1000); + } +} + +// Task2code: blinks an LED every 700 ms +void Task2code(void *pvParameters) +{ + Serial.print("Task2 running on core "); + Serial.println(xPortGetCoreID()); + + for (;;) + { + digitalWrite(led2, HIGH); + delay(700); + if (!s.isFired) + { + digitalWrite(led2, LOW); + delay(700); + } + } +} + +void killOne() +{ + // Kill task1 if it's running + if (Task1 != NULL) + { + eTaskState taskState = eTaskGetState(Task1); + if (taskState == eDeleted) + { + Serial.println("Task deleted"); + } + else + { + Serial.println("No more green"); + vTaskDelete(Task1); + } + } +} \ No newline at end of file diff --git a/others/updateResponse.json b/others/updateResponse.json new file mode 100644 index 0000000..9d635c1 --- /dev/null +++ b/others/updateResponse.json @@ -0,0 +1,13 @@ +{ + "disarm": false, + "cards": [ + { + "id": "0015", + "name": "guille" + }, + { + "id": "AA111f", + "name": "Andre" + } + ] +} \ No newline at end of file