user66859: Hi there I want to send a request to the server with get method with URL parameters, when a key is pressed with nodemcu. But I Can't Do This Work, I Got the Below Error From Serial Monitor:
I Get This Error From Serial Monitor
 ets Jan  8 2013,rst cause:4, boot mode:(3,7)

wdt reset
load 0x4010f000, len 1384, room 16 
tail 8
chksum 0x2d
csum 0x2d
v951aeffa
~ld

My Main Code
#include <ESP8266WiFi.h> 
const char* ssid = "MobinNet1365"; 
//replace with your own wifi ssid 
const char* password = "G12229M1Q64"; //replace with your own //wifi ssid password 
const char* host = "webhook.site";

const int button = 8;
int temp = 0;

void setup() { 
  
  Serial.begin(115200); 
  pinMode(button, INPUT);
  delay(10);
  Serial.println(); 
  Serial.print("Connecting to ");
  Serial.println(ssid);
  
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  
  while (WiFi.status() != WL_CONNECTED){
    delay(500);
    Serial.print(".");
  }
  
  Serial.println("");
  Serial.println("WiFi connected"); 
  Serial.println("IP address: "); 
  Serial.println(WiFi.localIP()); 
} 


void loop() {
  
  temp = digitalRead(button);  
  if (temp == HIGH) {       
    Serial.println(host);
    WiFiClient client;
    const int httpPort = 80;
    
    String url = "/df35c8cd-0398-4c92-b55f-b9e36629b309";
    url += "?switche=";
    url += "1";  
       
    client.print(String("GET ") + url + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "Connection: close\r\n\r\n");      
  }
}

my request sending code is below:
#include <ESP8266WiFi.h> 
const char* ssid = "your-ssid";
const char* password = "your-password";
const char* host = "";

void setup() { 
    Serial.begin(115200); 
    delay(10); 
    Serial.println(); 
    Serial.print("Connecting to ");
    Serial.println(ssid);   
    WiFi.mode(WIFI_STA);
    WiFi.begin(ssid, password);
    while (WiFi.status() != WL_CONNECTED)
    {
        delay(500);
        Serial.print(".");
    }

    Serial.println("");
    Serial.println("WiFi connected"); 
    Serial.println("IP address: "); 
    Serial.println(WiFi.localIP()); 
} 
int value = 0; 
void loop() { 
    delay(5000);
    ++value;
    Serial.print("connecting to ");
    Serial.println(host);
    WiFiClient client;
    const int httpPort = 80;
    if (!client.connect(host, httpPort)) {
        Serial.println("connection failed");
        return;
    }



    String url = "/";
    /* url += "?param1=";
    url += param1;
    url += "?param2=";
    url += param2;
    */
    Serial.print("Requesting URL: ");
    Serial.println(url);
    client.print(String("GET ") + url + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "Connection: close\r\n\r\n");
    unsigned long timeout = millis();
    while (client.available() == 0) {
        if (millis() - timeout > 5000)
        {
            Serial.println(">>> Client Timeout !");
            client.stop(); 
            return;
        } 
    }

    while (client.available())
    {
        String line = client.readStringUntil('\r'); Serial.print(line);
    }
    
    Serial.println();
    Serial.println("closing connection"); 
}

And My Key Press Code Detector Is below:
const int button = 8;
int temp = 0;

void setup() {
  Serial.begin(9600);
  pinMode(button, INPUT);
}

void loop() {
  temp = digitalRead(button);
     
   if (temp == HIGH) {
      Serial.println("LED Turned ON");
      delay(1500);
   }
   else {
      Serial.println("LED Turned OFF");
      delay(1500);
   }
}

And My Circuit Is:
NodeMcu => MicroSwitch
VIN => C
D0 => NO
G => 10k => NO
How Can I Make It When That Key Pressed It Send Request?

user77395: IMHO, some consideration :

const int button = 8;
const int button = 5; // CHANGE TO Pin "D1 GPIO5"

GPIO8 is used to connect the flash chip, you may change to Pin "D1" which is GPIO 5.

Check with your board's pinout.


to prevent non-stop keep calling within in the loop, you may use millis();

for example :
void GetUrl() {
    temp = digitalRead(button);  
  if (temp == HIGH) {       
    Serial.println(host);
    WiFiClient client;
    const int httpPort = 80;
    
    String url = "/df35c8cd-0398-4c92-b55f-b9e36629b309";
    url += "?switche=";
    url += "1";  

    String link = String("GET ") + url + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "Connection: close\r\n\r\n";
//    Serial.println( "link : " + link );
    client.print(String("GET ") + url + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "Connection: close\r\n\r\n");      
  }
}


unsigned long previousMillis = 0;
const long interval = 1000 * 0.5; // 500ms (0.5 sec)

void loop() {
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= interval) {
    GetUrl();
  }
}

Reference :
https://www.arduino.cc/en/Tutorial/BuiltInExamples/BlinkWithoutDelay
https://iotbyhvm.ooo/gpio-pins-esp8266/

66859: <p>Hi there I want to send a request to the server with get method with URL parameters, when a key is pressed with nodemcu. But I Can't Do This Work, I Got the Below Error From Serial Monitor:</p>
<p>I Get This Error From Serial Monitor</p>
<pre><code> ets Jan  8 2013,rst cause:4, boot mode:(3,7)

wdt reset
load 0x4010f000, len 1384, room 16 
tail 8
chksum 0x2d
csum 0x2d
v951aeffa
~ld
</code></pre>
<p><strong>My Main Code</strong></p>
<pre><code>#include &lt;ESP8266WiFi.h&gt; 
const char* ssid = &quot;MobinNet1365&quot;; 
//replace with your own wifi ssid 
const char* password = &quot;G12229M1Q64&quot;; //replace with your own //wifi ssid password 
const char* host = &quot;webhook.site&quot;;

const int button = 8;
int temp = 0;

void setup() { 
  
  Serial.begin(115200); 
  pinMode(button, INPUT);
  delay(10);
  Serial.println(); 
  Serial.print(&quot;Connecting to &quot;);
  Serial.println(ssid);
  
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  
  while (WiFi.status() != WL_CONNECTED){
    delay(500);
    Serial.print(&quot;.&quot;);
  }
  
  Serial.println(&quot;&quot;);
  Serial.println(&quot;WiFi connected&quot;); 
  Serial.println(&quot;IP address: &quot;); 
  Serial.println(WiFi.localIP()); 
} 


void loop() {
  
  temp = digitalRead(button);  
  if (temp == HIGH) {       
    Serial.println(host);
    WiFiClient client;
    const int httpPort = 80;
    
    String url = &quot;/df35c8cd-0398-4c92-b55f-b9e36629b309&quot;;
    url += &quot;?switche=&quot;;
    url += &quot;1&quot;;  
       
    client.print(String(&quot;GET &quot;) + url + &quot; HTTP/1.1\r\n&quot; + &quot;Host: &quot; + host + &quot;\r\n&quot; + &quot;Connection: close\r\n\r\n&quot;);      
  }
}
</code></pre>
<p>my request sending code is below:</p>
<pre><code>#include &lt;ESP8266WiFi.h&gt; 
const char* ssid = &quot;your-ssid&quot;;
const char* password = &quot;your-password&quot;;
const char* host = &quot;&quot;;

void setup() { 
    Serial.begin(115200); 
    delay(10); 
    Serial.println(); 
    Serial.print(&quot;Connecting to &quot;);
    Serial.println(ssid);   
    WiFi.mode(WIFI_STA);
    WiFi.begin(ssid, password);
    while (WiFi.status() != WL_CONNECTED)
    {
        delay(500);
        Serial.print(&quot;.&quot;);
    }

    Serial.println(&quot;&quot;);
    Serial.println(&quot;WiFi connected&quot;); 
    Serial.println(&quot;IP address: &quot;); 
    Serial.println(WiFi.localIP()); 
} 
int value = 0; 
void loop() { 
    delay(5000);
    ++value;
    Serial.print(&quot;connecting to &quot;);
    Serial.println(host);
    WiFiClient client;
    const int httpPort = 80;
    if (!client.connect(host, httpPort)) {
        Serial.println(&quot;connection failed&quot;);
        return;
    }



    String url = &quot;/&quot;;
    /* url += &quot;?param1=&quot;;
    url += param1;
    url += &quot;?param2=&quot;;
    url += param2;
    */
    Serial.print(&quot;Requesting URL: &quot;);
    Serial.println(url);
    client.print(String(&quot;GET &quot;) + url + &quot; HTTP/1.1\r\n&quot; + &quot;Host: &quot; + host + &quot;\r\n&quot; + &quot;Connection: close\r\n\r\n&quot;);
    unsigned long timeout = millis();
    while (client.available() == 0) {
        if (millis() - timeout &gt; 5000)
        {
            Serial.println(&quot;&gt;&gt;&gt; Client Timeout !&quot;);
            client.stop(); 
            return;
        } 
    }

    while (client.available())
    {
        String line = client.readStringUntil('\r'); Serial.print(line);
    }
    
    Serial.println();
    Serial.println(&quot;closing connection&quot;); 
}
</code></pre>
<p>And My Key Press Code Detector Is below:</p>
<pre><code>const int button = 8;
int temp = 0;

void setup() {
  Serial.begin(9600);
  pinMode(button, INPUT);
}

void loop() {
  temp = digitalRead(button);
     
   if (temp == HIGH) {
      Serial.println(&quot;LED Turned ON&quot;);
      delay(1500);
   }
   else {
      Serial.println(&quot;LED Turned OFF&quot;);
      delay(1500);
   }
}
</code></pre>
<p>And My Circuit Is:</p>
<p>NodeMcu =&gt; MicroSwitch</p>
<p>VIN =&gt; C</p>
<p>D0 =&gt; NO</p>
<p>G =&gt; 10k =&gt; NO</p>
<p>How Can I Make It When That Key Pressed It Send Request?</p>
 77395: <p>IMHO, some consideration :</p>
<ol>
<li>const int button = 8;
const int button = 5; // CHANGE TO Pin &quot;D1 GPIO5&quot;</li>
</ol>
<p>GPIO8 is used to connect the flash chip, you may change to Pin &quot;D1&quot; which is GPIO 5.</p>
<ul>
<li>Check with your board's pinout.</li>
</ul>
<ol start="2">
<li>to prevent non-stop keep calling within in the loop, you may use millis();</li>
</ol>
<p>for example :</p>
<pre><code>void GetUrl() {
    temp = digitalRead(button);  
  if (temp == HIGH) {       
    Serial.println(host);
    WiFiClient client;
    const int httpPort = 80;
    
    String url = &quot;/df35c8cd-0398-4c92-b55f-b9e36629b309&quot;;
    url += &quot;?switche=&quot;;
    url += &quot;1&quot;;  

    String link = String(&quot;GET &quot;) + url + &quot; HTTP/1.1\r\n&quot; + &quot;Host: &quot; + host + &quot;\r\n&quot; + &quot;Connection: close\r\n\r\n&quot;;
//    Serial.println( &quot;link : &quot; + link );
    client.print(String(&quot;GET &quot;) + url + &quot; HTTP/1.1\r\n&quot; + &quot;Host: &quot; + host + &quot;\r\n&quot; + &quot;Connection: close\r\n\r\n&quot;);      
  }
}


unsigned long previousMillis = 0;
const long interval = 1000 * 0.5; // 500ms (0.5 sec)

void loop() {
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis &gt;= interval) {
    GetUrl();
  }
}
</code></pre>
<p>Reference :</p>
<p><a href="https://www.arduino.cc/en/Tutorial/BuiltInExamples/BlinkWithoutDelay" rel="nofollow noreferrer">https://www.arduino.cc/en/Tutorial/BuiltInExamples/BlinkWithoutDelay</a></p>
<p><a href="https://iotbyhvm.ooo/gpio-pins-esp8266/" rel="nofollow noreferrer">https://iotbyhvm.ooo/gpio-pins-esp8266/</a></p>
