Files
IoTManager/include/push_pushingbox.h

63 lines
1.8 KiB
C
Raw Normal View History

2020-06-17 23:30:48 +03:00
#pragma once
2020-06-18 23:43:06 +02:00
#include "Global.h"
2020-06-17 23:30:48 +03:00
2020-06-19 01:50:19 +03:00
void Push_init() {
2020-06-17 23:30:48 +03:00
server.on("/pushingboxDate", HTTP_GET, [](AsyncWebServerRequest* request) {
if (request->hasArg("pushingbox_id")) {
2020-06-19 14:50:34 +02:00
jsonWriteStr(configSetupJson, "pushingbox_id", request->getParam("pushingbox_id")->value());
2020-06-17 23:30:48 +03:00
}
saveConfig();
request->send(200, "text/text", "ok"); // отправляем ответ о выполнении
});
}
inline void pushControl() {
String title = sCmd.next();
title.replace("#", " ");
String body = sCmd.next();
body.replace("#", " ");
static String body_old;
const char* logServer = "api.pushingbox.com";
2020-06-19 14:50:34 +02:00
String deviceId = jsonReadStr(configSetupJson, "pushingbox_id");
2020-06-17 23:30:48 +03:00
Serial.println("- starting client");
WiFiClient client_push;
Serial.println("- connecting to pushing server: " + String(logServer));
if (!client_push.connect(logServer, 80)) {
Serial.println("- not connected");
} else {
Serial.println("- succesfully connected");
String postStr = "devid=";
postStr += String(deviceId);
postStr += "&title=";
postStr += String(title);
postStr += "&body=";
postStr += String(body);
postStr += "\r\n\r\n";
Serial.println("- sending data...");
client_push.print("POST /pushingbox HTTP/1.1\n");
client_push.print("Host: api.pushingbox.com\n");
client_push.print("Connection: close\n");
client_push.print("Content-Type: application/x-www-form-urlencoded\n");
client_push.print("Content-Length: ");
client_push.print(postStr.length());
client_push.print("\n\n");
client_push.print(postStr);
}
client_push.stop();
Serial.println("- stopping the client");
}