diff options
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | platformio.ini | 17 | ||||
| -rw-r--r-- | src/main.cpp | 88 |
3 files changed, 107 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b9f3806 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.pio +.vscode diff --git a/platformio.ini b/platformio.ini new file mode 100644 index 0000000..5f27019 --- /dev/null +++ b/platformio.ini @@ -0,0 +1,17 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[env:d1_mini] +platform = espressif8266 +board = d1_mini +framework = arduino + +monitor_speed = 115200 +upload_speed = 460800 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 |
