Files
IoTManager/push_pushingbox.ino

59 lines
1.5 KiB
Arduino
Raw Normal View History

2020-02-10 01:06:18 +03:00
void Push_init() {
server.on("/pushingboxDate", HTTP_GET, [](AsyncWebServerRequest * request) {
if (request->hasArg("pushingbox_id")) {
jsonWriteStr(configSetup, "pushingbox_id", request->getParam("pushingbox_id")->value());
2020-02-10 01:06:18 +03:00
}
saveConfig();
request->send(200, "text/text", "ok"); // отправляем ответ о выполнении
});
}
void pushControl() {
String title = sCmd.next();
title.replace("#", " ");
String body = sCmd.next();
body.replace("#", " ");
static String body_old;
const char* logServer = "api.pushingbox.com";
String deviceId = jsonRead(configSetup, "pushingbox_id");
Serial.println("- starting client");
2020-04-22 20:35:50 +02:00
WiFiClient client_push;
2020-02-10 01:06:18 +03:00
Serial.println("- connecting to pushing server: " + String(logServer));
2020-04-22 20:35:50 +02:00
if (client_push.connect(logServer, 80)) {
2020-02-10 01:06:18 +03:00
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...");
2020-04-22 20:35:50 +02:00
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);
2020-02-10 01:06:18 +03:00
}
2020-04-22 20:35:50 +02:00
client_push.stop();
2020-02-10 01:06:18 +03:00
Serial.println("- stopping the client");
}