summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorvlapa <vlapa@ya.ru>2026-06-13 21:07:04 +0300
committervlapa <vlapa@ya.ru>2026-06-13 21:07:04 +0300
commit47ddc975c2a3d70a6773f7696d29f43a5adb86fe (patch)
tree8d93df25a56bb04b9793b1b9a50d2592d9bff154 /src
First
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp88
1 files changed, 88 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp
new file mode 100644
index 0000000..f30686f
--- /dev/null
+++ b/src/main.cpp
@@ -0,0 +1,88 @@
+#include <ESP8266WiFi.h>
+#include <ESP8266HTTPClient.h>
+#include <WiFiClient.h>
+
+const char *ssid = "link";
+const char *password = "dkfgf#*12091997";
+const char *host = "89.110.92.137";
+const int port = 8000;
+const char *sensor_1 = "Home_bme280_balkon";
+const char *sensor_2 = "Villa_bme280_base1";
+
+void setup()
+{
+ Serial.begin(115200);
+ WiFi.begin(ssid, password);
+
+ while (WiFi.status() != WL_CONNECTED)
+ {
+ delay(500);
+ Serial.print(".");
+ }
+
+ if (WiFi.status() == WL_CONNECTED)
+ {
+ Serial.println("\nOK !");
+ }
+
+
+ //=====================================================
+ String sensorKeys = sensor_1;
+ sensorKeys += ",";
+ sensorKeys += sensor_2;
+
+ WiFiClient client;
+ HTTPClient http;
+
+ String url = "http://" + String(host) + ":" + String(port) + "/";
+ Serial.println("Sending POST to: " + url);
+ Serial.println("Data: " + sensorKeys);
+
+ http.begin(client, url);
+ http.addHeader("Content-Type", "text/plain");
+ http.setTimeout(10000);
+
+
+ // Отправляем POST с нашими ключами
+ int httpCode = http.POST(sensorKeys);
+
+ // Анализируем ответ
+ if (httpCode > 0)
+ {
+ Serial.printf("Response code: %d\n", httpCode);
+
+ if (httpCode == HTTP_CODE_OK)
+ {
+ String payload = http.getString();
+ Serial.println("Server response: \n" + payload);
+ }
+ }
+ else
+ {
+ Serial.printf("POST failed, error: %s\n", http.errorToString(httpCode).c_str());
+ }
+
+ http.end();
+
+ //=====================================================
+
+ // if (client.connect(host, 8000))
+ // {
+ // client.println("GET / HTTP/1.1");
+ // client.print("Host: ");
+ // client.println(host);
+ // client.println("Connection: close");
+ // client.println();
+ // Serial.println("Отправили запрос");
+
+ // delay(500);
+
+ // while (client.available())
+ // {
+ // String line = client.readStringUntil('\r');
+ // Serial.print(line);
+ // }
+ // }
+}
+
+void loop() {} \ No newline at end of file