User Tools

Site Tools


latinet:unicaes:workshops:communication-23

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
latinet:unicaes:workshops:communication-23 [2024/09/10 20:34] – [3. Our first MQTT Publish] harley.laralatinet:unicaes:workshops:communication-23 [2024/09/10 20:39] (current) harley.lara
Line 29: Line 29:
  
 // Create an instance of WiFiClientSecure // Create an instance of WiFiClientSecure
-WiFiClientSecure client;+WiFiClientSecure wifi_client;
  
 void setup() { void setup() {
Line 48: Line 48:
  
   // Set the client to verify the server's certificate   // Set the client to verify the server's certificate
-  client.setInsecure();+  wifi_client.setInsecure();
  
   // Give the client a chance to perform the handshake   // Give the client a chance to perform the handshake
Line 57: Line 57:
   if (WiFi.status() == WL_CONNECTED) {   if (WiFi.status() == WL_CONNECTED) {
  
-    client.connect(API_HOST, HTTP_PORT);+    wifi_client.connect(API_HOST, HTTP_PORT);
     // Make an HTTPS GET request     // Make an HTTPS GET request
-    client.println("GET " + String(API_ENDPOINT) + " HTTP/1.1"); +    wifi_client.println("GET " + String(API_ENDPOINT) + " HTTP/1.1"); 
-    client.println("Host: " + String(API_HOST)); +    wifi_client.println("Host: " + String(API_HOST)); 
-    client.println("Connection: close"); +    wifi_client.println("Connection: close"); 
-    client.println();+    wifi_client.println();
  
     // Wait for the response     // Wait for the response
-    while (client.connected()) { +    while (wifi_client.connected()) { 
-      if (client.available()) {+      if (wifi_client.available()) {
         // read an incoming byte from the server and print it to serial monitor:         // read an incoming byte from the server and print it to serial monitor:
-        char c = client.read();+        char c = wifi_client.read();
         Serial.print(c);         Serial.print(c);
       }       }
     }     }
  
-    client.stop();+    wifi_client.stop();
   }   }
  
latinet/unicaes/workshops/communication-23.1725993283.txt.gz · Last modified: 2024/09/10 20:34 by harley.lara