Alcance de la leccion
En esta lección aprenderemos…
• ESP8266 Microcontrolador con WiFi
• Censar y transmitir datos por Internet
Cargar datos en la
nube
¿Qué es ThingSpeak?
Es un conjunto de servidor web, más una base de datos y una API que nos
permite almacenar y transmitir datos usando el protocolo HTTP.
Como podemos utilizarlo?
Creación de una cuenta en ThingSpeak
https://thingspeak.com/
Que es un canal
// ThingSpeak Settings
const int channelID = 302476;
String writeAPIKey = "JBH3UF5CULRF3N44"; // write API key for your ThingSpeak
Channel
const char* server = "api.thingspeak.com";
const int postingInterval = 20 * 1000; // post data every 20 seconds
#include <ESP8266WiFi.h>
// Wi-Fi Settings
const char* ssid = "xxxxxx"; // your wireless network name (SSID)
const char* password = "xxxxxxx."; // your Wi-Fi network password
WiFiClient client;
// ThingSpeak Settings
const int channelID = 302476;
String writeAPIKey = "JBH3UF5CULRF3N44"; // write API key for your ThingSpeak
Channel
const char* server = "api.thingspeak.com";
const int postingInterval = 20 * 1000; // post data every 20 seconds
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
}
void loop() {
if (client.connect(server, 80)) {
// Measure Signal Strength (RSSI) of Wi-Fi connection
long rssi = WiFi.RSSI();
// Construct API request body
String body = "field1=";
body += String(rssi);
Serial.print("RSSI: ");
Serial.println(rssi);
client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: " + writeAPIKey + "\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(body.length());
client.print("\n\n");
client.print(body);
client.print("\n\n");
}
client.stop();
// wait and then post again
delay(postingInterval);
}