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
Next revision
Previous revision
latinet:unicaes:workshops:communication-23 [2024/09/10 20:30] – [2. ESP8266 and WiFi] 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();
   }   }
  
Line 82: Line 82:
  
 ===== 3. Our first MQTT Publish ===== ===== 3. Our first MQTT Publish =====
 +
 Stepping ahead, you'll have the chance to implement your first MQTT publish from the ESP8266. While the following example provides a static demonstration, we encourage you to take it a step further by incorporating one of the sensors available to you. Stepping ahead, you'll have the chance to implement your first MQTT publish from the ESP8266. While the following example provides a static demonstration, we encourage you to take it a step further by incorporating one of the sensors available to you.
  
-PubSubClient Library: [[https://github.com/knolleary/pubsubclient|PubSubClient by knolleary]]+To start, search and install the library "PubSubClient " by Nick O'Leary in Arduino IDE or download and install it manually from source [[https://github.com/knolleary/pubsubclient| Github PubSubClient by knolleary]].
  
 <file c++ mqtt-publish.ino> <file c++ mqtt-publish.ino>
latinet/unicaes/workshops/communication-23.1725993043.txt.gz · Last modified: 2024/09/10 20:30 by harley.lara