{"id":52343,"date":"2018-02-13T10:49:13","date_gmt":"2018-02-13T10:49:13","guid":{"rendered":"http:\/\/randomnerdtutorials.com\/?p=52343"},"modified":"2019-04-02T10:23:24","modified_gmt":"2019-04-02T10:23:24","slug":"esp8266-daily-task-publish-temperature-readings-to-thingspeak","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/esp8266-daily-task-publish-temperature-readings-to-thingspeak\/","title":{"rendered":"ESP8266 Daily Task &#8211; Publish Temperature Readings to ThingSpeak"},"content":{"rendered":"<p>In this project you\u2019re going to learn how to build a sensor node with an ESP8266 that publishes the temperature and humidity once a day to a free service called Thing Speak.<!--more--><\/p>\n<p><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter size-full wp-image-52380\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/ESP8266-daily-task-thumbnail.jpg?resize=1200%2C675&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"1200\" height=\"675\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/ESP8266-daily-task-thumbnail.jpg?w=1280&amp;quality=100&amp;strip=all&amp;ssl=1 1280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/ESP8266-daily-task-thumbnail.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/ESP8266-daily-task-thumbnail.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/ESP8266-daily-task-thumbnail.jpg?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/p>\n<h2>Watch the Video Tutorial and Project Demo<\/h2>\n<p><em>This guide is available in video format (watch below) and in written format (continue reading).<\/em><\/p>\n<p style=\"text-align:center\"><iframe width=\"720\" height=\"405\" src=\"https:\/\/www.youtube.com\/embed\/QH3f-KTTDVY?rel=0\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<h2>Prerequisites<\/h2>\n<p>Before proceeding with this tutorial we recommend taking a look at these resources:<\/p>\n<ul>\n<li><a href=\"https:\/\/randomnerdtutorials.com\/getting-started-with-esp8266-wifi-transceiver-review\/\">Getting Started with ESP8266 Wi-Fi<\/a><\/li>\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp8266-deep-sleep-with-arduino-ide\/\">ESP8266 Deep Sleep with Arduino IDE<\/a><\/li>\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp8266-wi-fi-button-diy-amazon-dash-button-clone\/\" target=\"_blank\" rel=\"noopener noreferrer\">ESP8266 Wi-Fi Button \u2013 DIY Amazon Dash Button Clone<\/a><\/li>\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp8266-dht11dht22-temperature-and-humidity-web-server-with-arduino-ide\/\">ESP8266 DHT11\/DHT22 Temperature and Humidity Web Server<\/a><\/li>\n<\/ul>\n<p>If you like ESP8266 and you want to learn more about it. I recommend downloading my course:\u00a0<a href=\"https:\/\/randomnerdtutorials.com\/home-automation-using-esp8266\/\">Home Automation using ESP8266<\/a>.<\/p>\n<h2>Parts required<\/h2>\n<p>For this project, you\u2019ll need these components:<\/p>\n<ul>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/esp8266-esp-12e-nodemcu-wi-fi-development-board\/\" target=\"_blank\" rel=\"noopener noreferrer\">ESP8266<\/a>\u00a0\u2013 read\u00a0<a href=\"https:\/\/makeradvisor.com\/best-esp8266-wi-fi-development-board\/\" target=\"_blank\" rel=\"noopener noreferrer\">Best ESP8266 Wi-Fi Development Boards<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/dht11-temperature-humidity-sensor\/\" target=\"_blank\" rel=\"noopener noreferrer\">DHT11 temperature and humidity sensor<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/resistors-kits\/\" target=\"_blank\" rel=\"noopener noreferrer\">4.7k Ohm resistor<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/mb-102-solderless-breadboard-830-points\/\" target=\"_blank\" rel=\"noopener noreferrer\">Breadboard<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/jumper-wires-kit-120-pieces\/\" target=\"_blank\" rel=\"noopener noreferrer\">Jumper wires<\/a><\/li>\n<\/ul>\n<p><img data-recalc-dims=\"1\" decoding=\"async\" class=\"aligncenter size-full wp-image-52344\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/esp-circuit.jpg?resize=600%2C485&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"600\" height=\"485\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/esp-circuit.jpg?w=600&amp;quality=100&amp;strip=all&amp;ssl=1 600w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/esp-circuit.jpg?resize=300%2C243&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 600px) 100vw, 600px\" \/><\/p>\n<p>You can use the preceding links or go directly to <a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\">MakerAdvisor.com\/tools<\/a> to find all the parts for your projects at the best price!<\/p><p style=\"text-align:center;\"><a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/header-200.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\"><\/a><\/p>\n<h2>Schematics<\/h2>\n<p>The circuit is very easy to assemble and no soldering is required, simply follow the next diagram.<\/p>\n<p><img data-recalc-dims=\"1\" decoding=\"async\" class=\"aligncenter size-full wp-image-52358\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/esp-daily-task-remove-reset-.png?resize=660%2C876&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"660\" height=\"876\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/esp-daily-task-remove-reset-.png?w=660&amp;quality=100&amp;strip=all&amp;ssl=1 660w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/esp-daily-task-remove-reset-.png?resize=226%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 226w\" sizes=\"(max-width: 660px) 100vw, 660px\" \/><\/p>\n<h2>Preparing Arduino IDE<\/h2>\n<p><strong>Note:<\/strong> you should have the <a href=\"https:\/\/randomnerdtutorials.com\/how-to-install-esp8266-board-arduino-ide\/\">ESP8266 add-on in the Arduino IDE installed<\/a>.<\/p>\n<p>After having the circuit ready, open your Arduino IDE and install two Arduino libraries. Go to <strong>Sketch<\/strong> &gt; <strong>Include library<\/strong> &gt; <strong>Manage libraries\u2026<\/strong><\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-52359\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/manage-libraries-arduino-IDE.png?resize=490%2C240&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"490\" height=\"240\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/manage-libraries-arduino-IDE.png?w=490&amp;quality=100&amp;strip=all&amp;ssl=1 490w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/manage-libraries-arduino-IDE.png?resize=300%2C147&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 490px) 100vw, 490px\" \/><\/p>\n<p>Search for <strong>DHT<\/strong> (or <a href=\"https:\/\/github.com\/adafruit\/DHT-sensor-library\/archive\/master.zip\" target=\"_blank\" rel=\"noopener noreferrer\">download here<\/a>). Press the \u201c<strong>Install<\/strong>\u201d button.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-52357\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/dht-sensor-install-library.png?resize=787%2C444&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"787\" height=\"444\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/dht-sensor-install-library.png?w=787&amp;quality=100&amp;strip=all&amp;ssl=1 787w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/dht-sensor-install-library.png?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/dht-sensor-install-library.png?resize=768%2C433&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 787px) 100vw, 787px\" \/><\/p>\n<p><strong>Note:<\/strong> you may also need to install the\u00a0<a href=\"https:\/\/github.com\/adafruit\/Adafruit_Sensor\/archive\/master.zip\" target=\"_blank\" rel=\"noopener noreferrer\">Adafruit Sensor library<\/a>.<\/p>\n<p>Then, you\u2019ll also have to search for <strong>ESP Daily Task<\/strong> and install that library (or <a href=\"https:\/\/github.com\/RuiSantosdotme\/ESPDailyTask\/archive\/master.zip\" target=\"_blank\" rel=\"noopener noreferrer\">download here<\/a>).<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-52356\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/esp-daily-task-install-library.png?resize=787%2C444&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"787\" height=\"444\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/esp-daily-task-install-library.png?w=787&amp;quality=100&amp;strip=all&amp;ssl=1 787w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/esp-daily-task-install-library.png?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/esp-daily-task-install-library.png?resize=768%2C433&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 787px) 100vw, 787px\" \/><\/p>\n<h2>Thing Speak<\/h2>\n<p>For this project we\u2019ll be using <a href=\"https:\/\/thingspeak.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">ThingSpeak.com<\/a>. Thing Speak allows you to publish your sensor readings to their website and display them in a plot with time stamps. Then, you can access your readings from anywhere in the world.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-52355\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/thingspeak.png?resize=1100%2C830&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"1100\" height=\"830\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/thingspeak.png?w=1100&amp;quality=100&amp;strip=all&amp;ssl=1 1100w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/thingspeak.png?resize=300%2C226&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/thingspeak.png?resize=768%2C579&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/thingspeak.png?resize=1024%2C773&amp;quality=100&amp;strip=all&amp;ssl=1 1024w\" sizes=\"(max-width: 1100px) 100vw, 1100px\" \/><\/p>\n<p>It\u2019s worth saying that this project can be easily modified to publish the values to your home automation hub or another application instead of Thing Speak.<\/p>\n<p>The main concept I want to show you with this project is how you can put your ESP8266 constantly in deep sleep mode, publishing a value every 24 hours.<\/p>\n<h2>Creating New Channel<\/h2>\n<p>If you don\u2019t have an account on Thing Speak you\u2019ll have to create one. After your account is ready, sign in and open the \u201c<strong>Channels<\/strong>\u201d tab.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-52352\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/thingspeak-my-channels.png?resize=438%2C258&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"438\" height=\"258\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/thingspeak-my-channels.png?w=438&amp;quality=100&amp;strip=all&amp;ssl=1 438w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/thingspeak-my-channels.png?resize=300%2C177&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 438px) 100vw, 438px\" \/><\/p>\n<p>Press the create \u201c<strong>New Channe<\/strong>l\u201d button:<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-52353\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/thingspeak-new-channel.png?resize=389%2C183&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"389\" height=\"183\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/thingspeak-new-channel.png?w=389&amp;quality=100&amp;strip=all&amp;ssl=1 389w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/thingspeak-new-channel.png?resize=300%2C141&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 389px) 100vw, 389px\" \/><\/p>\n<p>Type a name for your channel, add a description, and enable a second field. Field 1 will receive the <strong>Humidity<\/strong> readings and Field 2 the <strong>Temperature<\/strong> readings. Once you\u2019ve completed all these fields, save your channel.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-52354\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/thingspeak-save-channel.png?resize=570%2C437&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"570\" height=\"437\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/thingspeak-save-channel.png?w=570&amp;quality=100&amp;strip=all&amp;ssl=1 570w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/thingspeak-save-channel.png?resize=300%2C230&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 570px) 100vw, 570px\" \/><\/p>\n<h2>Customizing Chart<\/h2>\n<p>These charts can be customized, go to your Private View tab and press the edit icon:<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-52351\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/thingspeak-field-chart.png?resize=974%2C614&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"974\" height=\"614\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/thingspeak-field-chart.png?w=974&amp;quality=100&amp;strip=all&amp;ssl=1 974w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/thingspeak-field-chart.png?resize=300%2C189&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/thingspeak-field-chart.png?resize=768%2C484&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 974px) 100vw, 974px\" \/><\/p>\n<p>You can give each chart a title, for example the first chart will be called Humidity % and my second chart will be called Temperature \u00baC.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-52348\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/thing-speak-humidity.png?resize=586%2C485&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"586\" height=\"485\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/thing-speak-humidity.png?w=586&amp;quality=100&amp;strip=all&amp;ssl=1 586w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/thing-speak-humidity.png?resize=300%2C248&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 586px) 100vw, 586px\" \/><\/p>\n<p>You can also customize the background color, x and y axis, and much more, as you can see. When you\u2019re done, press the \u201c<strong>Save<\/strong>\u201d button.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-52349\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/thing-speak-temperature.png?resize=588%2C490&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"588\" height=\"490\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/thing-speak-temperature.png?w=588&amp;quality=100&amp;strip=all&amp;ssl=1 588w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/thing-speak-temperature.png?resize=300%2C250&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 588px) 100vw, 588px\" \/><\/p>\n<h2>Write API Key<\/h2>\n<p>In order to publish values with the ESP8266, you need the <strong>Write API Key<\/strong>. Open the \u201c<strong>API Keys<\/strong>\u201d tab and copy the Write API Key to a safe place because you\u2019ll need it in a moment.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-52350\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/thingspeak-api-key.png?resize=734%2C521&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"734\" height=\"521\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/thingspeak-api-key.png?w=734&amp;quality=100&amp;strip=all&amp;ssl=1 734w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/thingspeak-api-key.png?resize=300%2C213&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 734px) 100vw, 734px\" \/><\/p>\n<h2>Uploading Code<\/h2>\n<p>Go back to your Arduino IDE and copy the code below:<\/p>\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*\n * ESP8266 Daily Task\n * Rui Santos \n * Complete Project Details http:\/\/randomnerdtutorials.com\n *\/\n \n#include &lt;ESP8266WiFi.h&gt;\n#include &lt;ESPDailyTask.h&gt;\n#include &quot;DHT.h&quot;\n\n\/\/ Uncomment one of the lines below for whatever DHT sensor type you're using!\n#define DHTTYPE DHT11   \/\/ DHT 11\n\/\/#define DHTTYPE DHT21   \/\/ DHT 21 (AM2301)\n\/\/#define DHTTYPE DHT22   \/\/ DHT 22  (AM2302), AM2321\n\n\/\/ Replace with your SSID and Password\nconst char* ssid     = &quot;REPLACE_WITH_YOUR_SSID&quot;;\nconst char* password = &quot;REPLACE_WITH_YOUR_PASSWORD&quot;;\n\n\/\/ Replace with your unique Thing Speak WRITE API KEY\nconst char* apiKey = &quot;REPLACE_WITH_YOUR_ThingSpeak_WRITE_API_KEY&quot;;\n\nconst char* resource = &quot;\/update?api_key=&quot;;\n\n\/\/ Thing Speak API server \nconst char* server = &quot;api.thingspeak.com&quot;;\n\n\/\/ Set this for what time your daily code should run \nESPDailyTask dailyTask(11*60 + 15); \/\/ 11:15am\n\n\/\/ DHT Sensor\nconst int DHTPin = 5;\n\/\/ Initialize DHT sensor.\nDHT dht(DHTPin, DHTTYPE);\n\n\/\/ Temporary variables\nstatic char temperatureTemp[7];\nstatic char humidityTemp[7];\n\nvoid setup() {\n  \/\/ Initializing serial port for debugging purposes\n  Serial.begin(115200);\n  delay(10);\n  \n  dailyTask.sleep1Day();\n  \n  \/\/ put your daily code here...\n  dht.begin();\n  \n  initWifi();\n  makeHTTPRequest();\n\n  \/\/ and back to sleep once daily code is done  \n  dailyTask.backToSleep();\n}\n\nvoid loop() {\n  \/\/ sleeping so wont get here\n}\n\n\/\/ Establish a Wi-Fi connection with your router\nvoid initWifi() {\n  Serial.print(&quot;Connecting to: &quot;); \n  Serial.print(ssid);\n  WiFi.begin(ssid, password);  \n\n  int timeout = 10 * 4; \/\/ 10 seconds\n  while(WiFi.status() != WL_CONNECTED  &amp;&amp; (timeout-- &gt; 0)) {\n    delay(250);\n    Serial.print(&quot;.&quot;);\n  }\n  Serial.println(&quot;&quot;);\n\n  if(WiFi.status() != WL_CONNECTED) {\n     Serial.println(&quot;Failed to connect, going back to sleep&quot;);\n  }\n\n  Serial.print(&quot;WiFi connected in: &quot;); \n  Serial.print(millis());\n  Serial.print(&quot;, IP address: &quot;); \n  Serial.println(WiFi.localIP());\n}\n\n\/\/ Make an HTTP request to Thing Speak\nvoid makeHTTPRequest() {\n  \/\/ Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)\n  float h = dht.readHumidity();\n  \/\/ Read temperature as Celsius (the default)\n  float t = dht.readTemperature();\n  \/\/ Read temperature as Fahrenheit (isFahrenheit = true)\n  float f = dht.readTemperature(true);\n  \/\/ Check if any reads failed and exit early (to try again).\n  if (isnan(h) || isnan(t) || isnan(f)) {\n    Serial.println(&quot;Failed to read from DHT sensor!&quot;);\n    strcpy(temperatureTemp,&quot;Failed&quot;);\n    strcpy(humidityTemp, &quot;Failed&quot;);\n    return;    \n  }\n  else {\n    \/\/ Computes temperature values in Celsius + Fahrenheit and Humidity\n    float hic = dht.computeHeatIndex(t, h, false); \n    \/\/ Comment the next line, if you prefer to use Fahrenheit      \n    dtostrf(hic, 6, 2, temperatureTemp);\n                 \n    float hif = dht.computeHeatIndex(f, h);\n    \/\/ Uncomment the next line, if you want to use Fahrenheit\n    \/\/dtostrf(hif, 6, 2, temperatureTemp);   \n          \n    dtostrf(h, 6, 2, humidityTemp);\n    \/\/ You can delete the following Serial.print's, it's just for debugging purposes\n    Serial.print(&quot;Humidity: &quot;);\n    Serial.print(h);\n    Serial.print(&quot; %\\t Temperature: &quot;);\n    Serial.print(t);\n    Serial.print(&quot; *C &quot;);\n    Serial.print(f);\n    Serial.print(&quot; *F\\t Heat index: &quot;);\n    Serial.print(hic);\n    Serial.print(&quot; *C &quot;);\n    Serial.print(hif);\n    Serial.print(&quot; *F&quot;);\n    Serial.print(&quot;Humidity: &quot;);\n    Serial.print(h);\n    Serial.print(&quot; %\\t Temperature: &quot;);\n    Serial.print(t);\n    Serial.print(&quot; *C &quot;);\n    Serial.print(f);\n    Serial.print(&quot; *F\\t Heat index: &quot;);\n    Serial.print(hic);\n    Serial.print(&quot; *C &quot;);\n    Serial.print(hif);\n    Serial.println(&quot; *F&quot;);\n  }\n  \n  Serial.print(&quot;Connecting to &quot;); \n  Serial.print(server);\n  \n  WiFiClient client;\n  int retries = 5;\n  while(!!!client.connect(server, 80) &amp;&amp; (retries-- &gt; 0)) {\n    Serial.print(&quot;.&quot;);\n  }\n  Serial.println();\n  if(!!!client.connected()) {\n     Serial.println(&quot;Failed to connect, going back to sleep&quot;);\n  }\n  \n  Serial.print(&quot;Request resource: &quot;); \n  Serial.println(resource);\n  client.print(String(&quot;GET &quot;) + resource + apiKey + &quot;&amp;field1=&quot; + humidityTemp + &quot;&amp;field2=&quot; + temperatureTemp +\n                  &quot; HTTP\/1.1\\r\\n&quot; +\n                  &quot;Host: &quot; + server + &quot;\\r\\n&quot; + \n                  &quot;Connection: close\\r\\n\\r\\n&quot;);\n                  \n  int timeout = 5 * 10; \/\/ 5 seconds             \n  while(!!!client.available() &amp;&amp; (timeout-- &gt; 0)){\n    delay(100);\n  }\n  if(!!!client.available()) {\n     Serial.println(&quot;No response, going back to sleep&quot;);\n  }\n  while(client.available()){\n    Serial.write(client.read());\n  }\n  \n  Serial.println(&quot;\\nclosing connection&quot;);\n  client.stop();\n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/ESP8266_Daily_Task.ino\" target=\"_blank\">View raw code<\/a><\/p>\n<h3>Preparing your code<\/h3>\n<p>There are 3 variables that you need to change. Add your SSID and password so that your ESP is able to establish a communication with your router:<\/p>\n<pre>\/\/ Replace with your SSID and Password\r\nconst char* ssid = \"<strong><span style=\"color: #ff0000;\">REPLACE_WITH_YOUR_SSID<\/span><\/strong>\";\r\nconst char* password = \"<strong><span style=\"color: #ff0000;\">REPLACE_WITH_YOUR_PASSWORD<\/span><\/strong>\";<\/pre>\n<p>Enter your Thing Speak Write API key in this variable:<\/p>\n<pre>\/\/ Replace with your unique Thing Speak WRITE API KEY\r\nconst char* apiKey = \"<strong><span style=\"color: #ff0000;\">REPLACE_WITH_YOUR_ThingSpeak_WRITE_API_KEY<\/span><\/strong>\";<\/pre>\n<h3>Understanding the code<\/h3>\n<p>Now we can take a closer look at the code. The setup() function starts by initializing the Serial port.<\/p>\n<pre>void <strong>setup()<\/strong> {\r\n \/\/ Initializing serial port for debugging purposes\r\n<strong> Serial.begin(115200);<\/strong>\r\n<strong> delay(10);<\/strong><\/pre>\n<p>Then, it calls the ESP daily task function to determine whether 24 hours have passed or not since the last reading. If not, the ESP goes back to deep sleep mode.<\/p>\n<pre><strong> dailyTask.sleep1Day();<\/strong><\/pre>\n<p>However, if 24 hours have passed since the last reading, the code will proceed. So, it will initialize the DHT sensor, connect to the Wi-Fi router and make an HTTP GET request to Thing Speak in order to publish the readings.<\/p>\n<pre> \/\/ put your daily code here...\r\n<strong> dht.begin();<\/strong>\r\n\r\n<strong> initWifi();<\/strong>\r\n<strong> makeHTTPRequest();<\/strong><\/pre>\n<p>Once the readings are published, the ESP goes back to deep sleep mode.<\/p>\n<pre> \/\/ and back to sleep once daily code is done\r\n<strong> dailyTask.backToSleep();<\/strong>\r\n}<\/pre>\n<p>There\u2019s nothing in the loop() function, because your ESP is constantly in deep sleep mode and wakes itself up.<\/p>\n<pre>void <strong>loop()<\/strong> {\r\n \/\/ sleeping so wont get here\r\n}<\/pre>\n<h3>Other changes \u2013 different sensor and degrees Fahrenheit<\/h3>\n<p>Note that If you\u2019re using a different sensor than the DHT11, you can comment and uncomment the right DEFINE line to use your sensor.<\/p>\n<pre>\/\/ Uncomment one of the lines below for whatever DHT sensor type you're using!\r\n#define DHTTYPE DHT11 \/\/ DHT 11\r\n\/\/#define DHTTYPE DHT21 \/\/ DHT 21 (AM2301)\r\n\/\/#define DHTTYPE DHT22 \/\/ DHT 22 (AM2302), AM2321<\/pre>\n<p>There\u2019s also another important thing you can change. By default this code publishes the temperature in degrees Celsius, but if you comment the variable highlighted in red and uncomment the variable highlighted in green it will publish the temperature in degrees Fahrenheit .<\/p>\n<pre>\/\/ Computes temperature values in Celsius + Fahrenheit and Humidity\r\nfloat hic = dht.computeHeatIndex(t, h, false);\r\n\/\/ Comment the next line, if you prefer to use Fahrenheit\r\n<span style=\"color: #ff0000;\"><strong>dtostrf(hic, 6, 2, temperatureTemp);<\/strong><\/span>\r\n\r\nfloat hif = dht.computeHeatIndex(f, h);\r\n\/\/ Uncomment the next line, if you want to use Fahrenheit\r\n<span style=\"color: #008000;\"><strong>\/\/dtostrf(hif, 6, 2, temperatureTemp);<\/strong><\/span><\/pre>\n<p>Once you\u2019ve made all the changes, you can upload the code to your ESP board.<\/p>\n<h2>Testing the Project<\/h2>\n<p>Finally, open the Arduino IDE serial monitor at a baud rate of 115200. You can test your project and simulate each hour passing. Simply remove the wire that connects the RESET pin to D0 (GPIO 16), and then you just have to press the RESET button to simulate each hour passing.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-52346\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/reset-button.jpg?resize=486%2C447&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"486\" height=\"447\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/reset-button.jpg?w=486&amp;quality=100&amp;strip=all&amp;ssl=1 486w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/reset-button.jpg?resize=300%2C276&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 486px) 100vw, 486px\" \/><\/p>\n<p>So, you need to press 24 times to publish a reading. The counter variable increases every time you press the reset button. Once you reset the ESP8266 24 times, it will publish the readings to Thing Speak.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-52361\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/arduino-IDE-serial-monitor.png?resize=916%2C518&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"916\" height=\"518\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/arduino-IDE-serial-monitor.png?w=916&amp;quality=100&amp;strip=all&amp;ssl=1 916w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/arduino-IDE-serial-monitor.png?resize=300%2C170&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/arduino-IDE-serial-monitor.png?resize=768%2C434&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 916px) 100vw, 916px\" \/><\/p>\n<p>As you can see the Humidity and Temperature have been successfully published and plotted in the chart in real time.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-52345\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/humidity-chart-f.png?resize=461%2C312&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"461\" height=\"312\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/humidity-chart-f.png?w=461&amp;quality=100&amp;strip=all&amp;ssl=1 461w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/humidity-chart-f.png?resize=300%2C203&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 461px) 100vw, 461px\" \/><\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-52347\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/temperature-chart-f.png?resize=463%2C309&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"463\" height=\"309\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/temperature-chart-f.png?w=463&amp;quality=100&amp;strip=all&amp;ssl=1 463w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/temperature-chart-f.png?resize=300%2C200&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 463px) 100vw, 463px\" \/><\/p>\n<p>After testing the circuit, you should reconnect the wire from RESET to D0. The ESP will wake up every hour, but it will only publish a value every 24 hours.<\/p>\n<h2>Wrapping Up<\/h2>\n<p>I hope this project was useful. Now, you know how to apply the daily task concept to any project.<\/p>\n<p><em>This is an excerpt<\/em>\u00a0from my\u00a0<a href=\"https:\/\/randomnerdtutorials.com\/home-automation-using-esp8266\/\">Home Automation using ESP8266 eBook<\/a>. If you like ESP8266 and you want to learn more about it. I recommend downloading my course:\u00a0<a href=\"https:\/\/randomnerdtutorials.com\/home-automation-using-esp8266\/\">Home Automation using ESP8266<\/a>.<\/p>\n<p>I hope this guide was useful. Thanks for reading!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this project you\u2019re going to learn how to build a sensor node with an ESP8266 that publishes the temperature and humidity once a day to a free service called &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"ESP8266 Daily Task &#8211; Publish Temperature Readings to ThingSpeak\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/esp8266-daily-task-publish-temperature-readings-to-thingspeak\/#more-52343\" aria-label=\"Read more about ESP8266 Daily Task &#8211; Publish Temperature Readings to ThingSpeak\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":1,"featured_media":52380,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[265,214,246,300,220,264,215],"tags":[],"class_list":["post-52343","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-esp8266-project","category-esp8266","category-esp8266-arduino-ide","category-0-esp8266","category-http-client","category-project","category-sensors"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/02\/ESP8266-daily-task-thumbnail.jpg?fit=1280%2C720&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/52343","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=52343"}],"version-history":[{"count":0,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/52343\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/52380"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=52343"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=52343"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=52343"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}