Как перейти по ссылке с помощью Nodemcu - PullRequest
0 голосов
/ 03 июня 2019

Как перейти по ссылке с помощью nodeMCU?

Я использую NodeMCU 0.9 (модуль ESP-12)

Ссылка: https://docs.google.com/forms/d/e/1FAIpQLSc6pufV7ikz8nvm0pFIHQwzfawNKY2b2T5xJH4zYkQn3HJL3w/viewform?usp=pp_url&entry.496898377=Volt&entry.554080438=Amp&entry.79954202=Power&entry.2022387293=Ah&entry.1863631882=Wh

На самом деле, это ссылка на предварительное поле формы Google.

1 Ответ

1 голос
/ 03 июня 2019

Довольно просто отправить HTTP-запрос на получение с ESP8266.Просто настройте вашу IDE.Затем используйте встроенный HTTPClient для отправки HTTP-запроса:

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

const char *ssid = "yourNetworkName";
const char *password = "yourNetworkPassword";

const char *url = "http://docs.google.com/forms/d/e/1FAIpQLSc6pufV7ikz8nvm0pFIHQwzfawNKY2b2T5xJH4zYkQn3HJL3w/viewform?usp=pp_url&entry.496898377=Volt&entry.554080438=Amp&entry.79954202=Power&entry.2022387293=Ah&entry.1863631882=Wh";

void send_request()
{
    //Check WiFi connection status
    if (WiFi.status() == WL_CONNECTED)
    {
        //Declare an object of class HTTPClient
        HTTPClient http;
        http.begin(url);           //Specify request destination
        int httpCode = http.GET(); //Send the request
        //Check the returning code
        if (httpCode > 0)
        {
            //Get the request response payload
            String payload = http.getString();
            //Print the response payload
            Serial.println(payload);
        }
        //Close connection
        http.end();
    }
}

void setup()
{
    Serial.begin(115200);
    WiFi.begin(ssid, password);
    Serial.print("Connecting.");
    // Checking Wifi connectivity
    while (WiFi.status() != WL_CONNECTED)
    {
        delay(1000);
        Serial.print(".");
    }
    Serial.println("\nConnected !");
    // Sending request
    send_request();
}

void loop()
{
}
...