IOT | Post Data to Thingspeak Using ESP8266

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
ESP8266 in India- https://amzn.to/2peaoen

ESP8266 in UK - https://amzn.to/2peaoen

ESP8266 in USA - https://amzn.to/2peaoen

MLX90614
MLX90614 in India- https://amzn.to/2C4E5Br

MLX90614 in UK - https://amzn.to/2C4E5Br

MLX90614 in USA - https://amzn.to/2C4E5Br


BreadBoard

BreadBoard in India- https://amzn.to/2MW0Opb

BreadBoard in USA- https://amzn.to/2MW0Opb BreadBoard in UK- https://amzn.to/2MW0Opb

Step 2: Code

#include
#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 = "api.thingspeak.com";

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)) // "184.106.153.149" or api.thingspeak.com { 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: api.thingspeak.com\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

Be the First to Share

    Recommendations

    • Backyard Contest

      Backyard Contest
    • Maps Challenge

      Maps Challenge
    • First Time Author Contest

      First Time Author Contest

    Comments

    0
    Nihadolly
    Nihadolly

    Question 2 years ago on Step 2

    Im working with wemos d1 r1. Pls help me with the code that sends mlx90614 data to thingspeak with wemos d1 r1