Files
IoTManager/push_pushingbox.ino
Dmitry Borisenko 9de15efdff DHT support
2020-02-10 01:06:18 +03:00

59 lines
1.5 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
void Push_init() {
server.on("/pushingboxDate", HTTP_GET, [](AsyncWebServerRequest * request) {
if (request->hasArg("pushingbox_id")) {
jsonWrite(configSetup, "pushingbox_id", request->getParam("pushingbox_id")->value());
}
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");
WiFiClient client;
Serial.println("- connecting to pushing server: " + String(logServer));
if (client.connect(logServer, 80)) {
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.print("POST /pushingbox HTTP/1.1\n");
client.print("Host: api.pushingbox.com\n");
client.print("Connection: close\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);
}
client.stop();
Serial.println("- stopping the client");
}