86 lines
3.0 KiB
C
86 lines
3.0 KiB
C
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");
|
|
}
|
|
} |