如何使用Nodemcu单击链接

时间:2019-06-03 02:45:49

标签: hyperlink arduino click nodemcu

如何使用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 个答案:

答案 0 :(得分:1)

使用ESP8266发送HTTP get请求非常简单。只需setup您的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()
{
}