Introduction: IOT | Post Data to Thingspeak Using ESP8266

Nowadays, IoT is trending and lots of machine has data to upload over cloud and analyse the data. Small sensors update the data on cloud and actuator on another end acts on it.
I am going to explain the one of the example of IoT.

I this article and i am going to show and guide to post the data to Thingspeak using ESP8266.

Step 1: Required Component

ESP8266 in India-

ESP8266 in UK -

ESP8266 in USA -

MLX90614 in India-

MLX90614 in UK -

MLX90614 in USA -


BreadBoard in India-

BreadBoard in USA- BreadBoard in UK-

Step 2: Code

#include #include

String apiKey = "7CDCTE2767Z8AUIL"; // Enter your Write API key from ThingSpeak

const char *ssid = "hidden"; // replace with your wifi ssid and wpa2 key const char *pass = "qwerty12"; const char* server = "";

WiFiClient client; Adafruit_MLX90614 mlx = Adafruit_MLX90614();

int objTemp; int ambTemp;

void setup() { Serial.begin(115200); delay(10); Serial.println("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, pass); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected"); mlx.begin(); Wire.begin(D1,D2); } void loop() {

if (client.connect(server,80)) // "" or { objTemp = mlx.readObjectTempC(); ambTemp = mlx.readObjectTempC(); String postStr = apiKey; postStr +="&field1="; postStr += String(objTemp); postStr += "\r\n\r\n";

client.print("POST /update HTTP/1.1\n"); client.print("Host:\n"); client.print("Connection: close\n"); client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n"); client.print("Content-Type: application/x-www-form-urlencoded\n"); client.print("Content-Length: "); client.print(postStr.length()); client.print("\n\n"); client.print(postStr);

Serial.print("Ambient = "); Serial.print(ambTemp); Serial.print("*C\tObject = "); Serial.print(objTemp); Serial.println("*C");

} client.stop(); delay(2000); }

Step 3: Demo