{"id":78800,"date":"2019-01-14T14:44:15","date_gmt":"2019-01-14T14:44:15","guid":{"rendered":"https:\/\/randomnerdtutorials.com\/?p=78800"},"modified":"2021-12-31T15:18:42","modified_gmt":"2021-12-31T15:18:42","slug":"low-power-weather-station-datalogger-using-esp8266-bme280-micropython","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/low-power-weather-station-datalogger-using-esp8266-bme280-micropython\/","title":{"rendered":"Low Power Weather Station Datalogger using ESP8266 and BME280 with MicroPython"},"content":{"rendered":"<p>This project shows how to build a data logger that publishes temperature, humidity and pressure readings every 10 minutes to a Google Sheets spreadsheet using an ESP8266 12-E. Between sensor readings the ESP is in deep sleep mode and only consumes 7\u03bcA. The ESP board is programmed using MicroPython and we use the IFTTT Webhooks service to integrate the project with Google sheets.<\/p>\n<p><!--more--><\/p>\n<p><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter size-full wp-image-79490\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/01\/ESP12-e-low-power-micropython-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\/2019\/01\/ESP12-e-low-power-micropython-thumbnail.jpg?w=1280&amp;quality=100&amp;strip=all&amp;ssl=1 1280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/01\/ESP12-e-low-power-micropython-thumbnail.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/01\/ESP12-e-low-power-micropython-thumbnail.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/01\/ESP12-e-low-power-micropython-thumbnail.jpg?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/p>\n<p>This project is also compatible with the ESP32. You just have to make a few modifications in the code (we&#8217;ll show you what you need to do).<\/p>\n<p>Throughout this project, you&#8217;ll learn the following concepts:<\/p>\n<ul>\n<li>Read temperature, humidity and pressure with the BME280 and ESP8266\/ESP32 using MicroPython;<\/li>\n<li>Make HTTP post requests in MicroPython to send sensor readings to a third-party service;<\/li>\n<li>Use IFTTT Webhooks services to save sensor readings in a Google Sheets spreadsheet;<\/li>\n<li>Put the ESP8266\/ESP32 in deep sleep mode and wake it up with a timer;<\/li>\n<li>Learn more about deep sleep in MicroPython:\n<ul>\n<li><a href=\"https:\/\/randomnerdtutorials.com\/micropython-esp8266-deep-sleep-wake-up-sources\/\">ESP8266 Deep Sleep and Wake Up Sources<\/a><\/li>\n<li><a href=\"https:\/\/randomnerdtutorials.com\/micropython-esp32-deep-sleep-wake-up-sources\/\">ESP32 Deep Sleep and Wake Up Sources<\/a><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>MicroPython Firmware<\/h2>\n<p>To follow this tutorial you need MicroPython firmware flashed in your ESP32 or ESP8266. You also need an IDE to write and upload the code to your board. We suggest using Thonny IDE or uPyCraft IDE:<\/p>\n<ul>\n<li>Thonny IDE:\n<ul>\n<li><a href=\"https:\/\/randomnerdtutorials.com\/getting-started-thonny-micropython-python-ide-esp32-esp8266\/\">Installing and getting started with Thonny IDE<\/a><\/li>\n<li><a href=\"https:\/\/randomnerdtutorials.com\/flashing-micropython-firmware-esptool-py-esp32-esp8266\/\">Flashing MicroPython Firmware with esptool.py<\/a><\/li>\n<\/ul>\n<\/li>\n<li>uPyCraft IDE:\n<ul>\n<li>Install uPyCraft IDE (<a href=\"https:\/\/randomnerdtutorials.com\/install-upycraft-ide-windows-pc-instructions\/\">Windows<\/a>,\u00a0<a href=\"https:\/\/randomnerdtutorials.com\/install-upycraft-ide-mac-os-x-instructions\/\">Mac OS X<\/a>,\u00a0<a href=\"https:\/\/randomnerdtutorials.com\/install-upycraft-ide-linux-ubuntu-instructions\/\">Linux<\/a>)<\/li>\n<li><a href=\"https:\/\/randomnerdtutorials.com\/flash-upload-micropython-firmware-esp32-esp8266\/\">Flash\/Upload MicroPython Firmware to ESP32 and ESP8266<\/a><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>Creating Your IFTTT Account<\/h2>\n<p>In this project we&#8217;ll publish sensor readings in a Google Sheets spreadsheet. To do that, we&#8217;ll use IFTTT Webhooks services. So, you need to create a free account on IFTTT.<\/p>\n<p>Go the official site\u00a0<a href=\"https:\/\/ifttt.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">ifttt.com<\/a>, enter your email and complete your account to get started.<\/p>\n<p><img data-recalc-dims=\"1\" decoding=\"async\" class=\"aligncenter size-full wp-image-56609\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/03\/ifttt.jpg?resize=750%2C353&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"750\" height=\"353\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/03\/ifttt.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/03\/ifttt.jpg?resize=300%2C141&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/p>\n<h2>Creating an Applet<\/h2>\n<p>Next, you need to create a new Applet. Follow the next steps to create a new Applet:<\/p>\n<p><strong>1)<\/strong> Go to &#8220;<strong>My Applets<\/strong>&#8220;and create a new Applet by clicking the &#8220;<strong>New Applet<\/strong>&#8221; button.<\/p>\n<p><img data-recalc-dims=\"1\" decoding=\"async\" class=\"aligncenter size-full wp-image-56635\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/03\/1_new_applet-1.png?resize=1045%2C252&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"1045\" height=\"252\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/03\/1_new_applet-1.png?w=1045&amp;quality=100&amp;strip=all&amp;ssl=1 1045w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/03\/1_new_applet-1.png?resize=300%2C72&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/03\/1_new_applet-1.png?resize=768%2C185&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/03\/1_new_applet-1.png?resize=1024%2C247&amp;quality=100&amp;strip=all&amp;ssl=1 1024w\" sizes=\"(max-width: 1045px) 100vw, 1045px\" \/><\/p>\n<p><strong>2)<\/strong> Click on the &#8220;<strong>this<\/strong>&#8221; word that is in a blue color &#8211; as highlighted in the figure below.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-56636\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/03\/2_this.png?resize=760%2C203&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"760\" height=\"203\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/03\/2_this.png?w=760&amp;quality=100&amp;strip=all&amp;ssl=1 760w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/03\/2_this.png?resize=300%2C80&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 760px) 100vw, 760px\" \/><br \/>\n<strong>3)<\/strong> Search for the &#8220;<strong>Webhooks<\/strong>&#8221; service and select the <strong>Webhooks<\/strong> icon.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-56637\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/03\/3_webhooks.png?resize=547%2C340&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"547\" height=\"340\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/03\/3_webhooks.png?w=547&amp;quality=100&amp;strip=all&amp;ssl=1 547w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/03\/3_webhooks.png?resize=300%2C186&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 547px) 100vw, 547px\" \/><\/p>\n<p><strong>4)<\/strong> Choose the &#8220;<strong>Receive a web request<\/strong>&#8221; trigger.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-56638\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/03\/4_receive_request.png?resize=346%2C387&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"346\" height=\"387\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/03\/4_receive_request.png?w=346&amp;quality=100&amp;strip=all&amp;ssl=1 346w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/03\/4_receive_request.png?resize=268%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 268w\" sizes=\"(max-width: 346px) 100vw, 346px\" \/><\/p>\n<p><strong>5)<\/strong> Give a name to the event. In this case, we&#8217;ll be using &#8220;<strong>bme_280_readings<\/strong>&#8221; and we recommend using that exact same event name as shown in the figure below. After that, click the &#8220;<strong>Create trigger<\/strong>&#8221; button.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-78845\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/12\/ifttt_event_name.jpg?resize=305%2C343&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"305\" height=\"343\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/12\/ifttt_event_name.jpg?w=445&amp;quality=100&amp;strip=all&amp;ssl=1 445w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/12\/ifttt_event_name.jpg?resize=266%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 266w\" sizes=\"(max-width: 305px) 100vw, 305px\" \/><\/p>\n<p><strong>6)<\/strong> Click the &#8220;<strong>that<\/strong>&#8221; word to proceed.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-56640\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/03\/6_that.png?resize=680%2C104&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"680\" height=\"104\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/03\/6_that.png?w=680&amp;quality=100&amp;strip=all&amp;ssl=1 680w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/03\/6_that.png?resize=300%2C46&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 680px) 100vw, 680px\" \/><\/p>\n<p><strong>7)<\/strong> Search for the &#8220;<strong>Google Sheets<\/strong>&#8221; service, and select the <strong>Google Sheets<\/strong> icon.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-56641\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/03\/7_google_sheets.png?resize=548%2C354&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"548\" height=\"354\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/03\/7_google_sheets.png?w=548&amp;quality=100&amp;strip=all&amp;ssl=1 548w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/03\/7_google_sheets.png?resize=300%2C194&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 548px) 100vw, 548px\" \/><\/p>\n<p><strong>8)<\/strong> If you haven&#8217;t connected with the Google Sheets service yet, you need to click the &#8220;<strong>Connect<\/strong>&#8221; button.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-56655\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/03\/connect-google-sheets.jpg?resize=500%2C268&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"500\" height=\"268\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/03\/connect-google-sheets.jpg?w=500&amp;quality=100&amp;strip=all&amp;ssl=1 500w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/03\/connect-google-sheets.jpg?resize=300%2C161&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/03\/connect-google-sheets.jpg?resize=280%2C150&amp;quality=100&amp;strip=all&amp;ssl=1 280w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/p>\n<p><strong>9)<\/strong> Choose the &#8220;<strong>Add a row to spreadsheet<\/strong>&#8221; action.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-56642\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/03\/8_select_add_row.png?resize=478%2C342&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"478\" height=\"342\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/03\/8_select_add_row.png?w=478&amp;quality=100&amp;strip=all&amp;ssl=1 478w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/03\/8_select_add_row.png?resize=300%2C215&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 478px) 100vw, 478px\" \/><\/p>\n<p><strong>10)<\/strong> Then, complete the action fields. Give the spreadsheet a name, and leave the other fields as default. Finally, click the &#8220;<strong>Create action<\/strong>&#8221; button.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-78846\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/12\/complete_action_fields_ifttt.jpg?resize=397%2C815&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"397\" height=\"815\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/12\/complete_action_fields_ifttt.jpg?w=440&amp;quality=100&amp;strip=all&amp;ssl=1 440w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/12\/complete_action_fields_ifttt.jpg?resize=146%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 146w\" sizes=\"(max-width: 397px) 100vw, 397px\" \/><\/p>\n<p><strong>11)<\/strong> Your Applet should be created after you press the &#8220;<strong>Finish<\/strong>&#8221; button.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-56644\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/03\/10_review_and_finish.png?resize=342%2C454&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"342\" height=\"454\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/03\/10_review_and_finish.png?w=342&amp;quality=100&amp;strip=all&amp;ssl=1 342w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/03\/10_review_and_finish.png?resize=226%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 226w\" sizes=\"(max-width: 342px) 100vw, 342px\" \/><\/p>\n<h2>Testing Your Applet<\/h2>\n<p>Before proceeding with the project, it is very important to test your applet first. Follow the next steps to test your Applet.<\/p>\n<p><strong>1)<\/strong> Go to the <a href=\"https:\/\/ifttt.com\/maker_webhooks\" target=\"_blank\" rel=\"noopener noreferrer\">Webhooks Service page<\/a>, and click the &#8220;<strong>Documentation<\/strong>&#8221; button.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-56670\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/03\/1_maker_webhooks.png?resize=602%2C261&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"602\" height=\"261\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/03\/1_maker_webhooks.png?w=602&amp;quality=100&amp;strip=all&amp;ssl=1 602w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/03\/1_maker_webhooks.png?resize=300%2C130&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 602px) 100vw, 602px\" \/><\/p>\n<p><strong>2)<\/strong> A page as shown in the following figure will appear. The page shows your unique API key. You shouldn&#8217;t share your unique API key with anyone.<\/p>\n<p>Fill the &#8220;<strong>To trigger an Event<\/strong>&#8221; section as shown below &#8211; it is highlighted with red rectangles. Then, click the &#8220;<strong>Test it<\/strong>&#8221; button.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78857\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/12\/webhooks_documentation_f.jpg?resize=732%2C621&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"732\" height=\"621\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/12\/webhooks_documentation_f.jpg?w=732&amp;quality=100&amp;strip=all&amp;ssl=1 732w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/12\/webhooks_documentation_f.jpg?resize=300%2C255&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 732px) 100vw, 732px\" \/><\/p>\n<p class=\"rntbox rntclblue\"><strong>Note: <\/strong> save your IFTTT API key because you&#8217;ll need it later in this project.<\/p>\n<p><strong>3)<\/strong> The event should be successfully triggered, and you&#8217;ll get a green message as shown below saying &#8220;<strong>Event has been triggered<\/strong>&#8220;.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78848\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/12\/event_has_been_triggered.png?resize=750%2C67&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"750\" height=\"67\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/12\/event_has_been_triggered.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/12\/event_has_been_triggered.png?resize=300%2C27&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/p>\n<p><strong>4)<\/strong> Go to your Google Drive. The IFTTT service should have created a folder called &#8220;<strong>IFTTT<\/strong>&#8221; with the &#8220;<strong>MakerWebooks\/bme280<\/strong>&#8221; folder inside. Inside this folder, you&#8217;ll find the <strong>Bme_280_readings<\/strong> spreadsheet.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78815\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/12\/ifttt_webhooks_bme280.jpg?resize=621%2C149&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"621\" height=\"149\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/12\/ifttt_webhooks_bme280.jpg?w=621&amp;quality=100&amp;strip=all&amp;ssl=1 621w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/12\/ifttt_webhooks_bme280.jpg?resize=300%2C72&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 621px) 100vw, 621px\" \/><\/p>\n<p><strong>5)<\/strong> Open the spreadsheet. You should have the values you&#8217;ve filled previously to test the Applet.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78858\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/12\/test-applet.jpg?resize=750%2C423&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"750\" height=\"423\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/12\/test-applet.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/12\/test-applet.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/p>\n<p>Continue reading this tutorial to see how to integrate the IFTTT Google Sheets service with your ESP8266 or ESP32.<\/p>\n<h2>Parts Required<\/h2>\n<p>Here&#8217;s a list of parts you need to build the circuit for this project:<\/p>\n<ul>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/esp8266-12e-esp-12e\/\" target=\"_blank\" rel=\"noopener noreferrer\">ESP8266 12-E<\/a> \u2013 read <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:\/\/www.banggood.com\/5Pcs-Serial-Port-WIFI-ESP8266-Module-Adapter-Plate-With-IO-Lead-Out-For-ESP-07-ESP-08-ESP-12-p-1056677.html?p=MA240439985285201910\" target=\"_blank\" rel=\"noopener nofollow noreferrer\">ESP8266 12-E adapter<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/ftdi-programmer-board\/\" target=\"_blank\" rel=\"noopener noreferrer\">FTDI programmer<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/esp32-dev-board-wi-fi-bluetooth\/\" target=\"_blank\" rel=\"noopener noreferrer\">[Alternative] ESP32 board<\/a>\u00a0&#8211; read <a href=\"https:\/\/makeradvisor.com\/esp32-development-boards-review-comparison\/\" target=\"_blank\" rel=\"noopener noreferrer\">ESP32 development boards comparison<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/bme280-sensor-module\/\" target=\"_blank\" rel=\"noopener noreferrer\">BME280 sensor module<\/a><\/li>\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp8266-voltage-regulator-lipo-and-li-ion-batteries\/\" target=\"_blank\" rel=\"noopener noreferrer\">[Optional]\u00a0Voltage regulator circuit for LiPo and Li-ion batteries<\/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<li><a href=\"https:\/\/makeradvisor.com\/tools\/mb-102-solderless-breadboard-830-points\/\" target=\"_blank\" rel=\"noopener noreferrer\">Breadboard<\/a><\/li>\n<\/ul>\n<p>For this project we&#8217;ll be using the ESP8266 12-E because it consumes less power in <a href=\"https:\/\/randomnerdtutorials.com\/micropython-esp8266-deep-sleep-wake-up-sources\/\">deep sleep mode<\/a> (it doesn&#8217;t have a built-in programmer). You can also use an <a href=\"https:\/\/makeradvisor.com\/tools\/esp8266-esp-12e-nodemcu-wi-fi-development-board\/\">ESP8266 NodeMCU Kit<\/a> or an <a href=\"https:\/\/makeradvisor.com\/tools\/esp32-dev-board-wi-fi-bluetooth\/\">ESP32 development board<\/a>.<\/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>Uploading Code to the ESP8266\u00a012-E Chip<\/h2>\n<p>Uploading code to the ESP-12E requires establishing a serial communication between your ESP8266 and an FTDI Programmer as shown in the schematic diagram below.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-79540\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/01\/esp8266-esp12-e-ftdi-uploading-code.png?resize=1200%2C284&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"1200\" height=\"284\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/01\/esp8266-esp12-e-ftdi-uploading-code.png?w=1294&amp;quality=100&amp;strip=all&amp;ssl=1 1294w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/01\/esp8266-esp12-e-ftdi-uploading-code.png?resize=300%2C71&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/01\/esp8266-esp12-e-ftdi-uploading-code.png?resize=768%2C182&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/01\/esp8266-esp12-e-ftdi-uploading-code.png?resize=1024%2C242&amp;quality=100&amp;strip=all&amp;ssl=1 1024w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/p>\n<ul>\n<li>RX &#8211; TX<\/li>\n<li>TX &#8211; RX<\/li>\n<li>VCC &#8211; VCC<\/li>\n<li>VCC &#8211; EN<\/li>\n<li>GND &#8211; GND<\/li>\n<li>GND &#8211; GPIO15<\/li>\n<li>GND &#8211; GPIO0<\/li>\n<\/ul>\n<p>If you want to learn more about the ESP12-E pins and how to use them, you can read our <a href=\"https:\/\/randomnerdtutorials.com\/esp8266-pinout-reference-gpios\/\">ESP8266 Pinout Reference Guide<\/a>.<\/p>\n<h2>Installing the BME280 library<\/h2>\n<p>The library to read from the BME280 sensor isn\u2019t part of the standard MicroPython firmware. So, you need to upload the library to your ESP8266\/ESP32 board.<\/p>\n<p>In uPyCraft IDE, create a new file by pressing the <strong>New File button (1)<\/strong>. Copy the BME280 library code into it. The BME280 library code can be found in the following link:<\/p>\n<p><a href=\"https:\/\/raw.githubusercontent.com\/RuiSantosdotme\/ESP-MicroPython\/master\/code\/WiFi\/HTTP_Client_IFTTT_BME280\/BME280.py\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/raw.githubusercontent.com\/RuiSantosdotme\/ESP-MicroPython\/master\/code\/WiFi\/HTTP_Client_IFTTT_BME280\/BME280.py<\/a><\/p>\n<p>Save the file by pressing the <strong>Save button (2)<\/strong>.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78802\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/12\/create_bme280_file_f.png?resize=750%2C334&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"750\" height=\"334\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/12\/create_bme280_file_f.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/12\/create_bme280_file_f.png?resize=300%2C134&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/p>\n<p>Call this new file \u201c<strong>BME280.py<\/strong>\u201d and press <strong>ok.<\/strong><\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78803\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/12\/create_bme280_file_2.png?resize=402%2C112&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"402\" height=\"112\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/12\/create_bme280_file_2.png?w=402&amp;quality=100&amp;strip=all&amp;ssl=1 402w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/12\/create_bme280_file_2.png?resize=300%2C84&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 402px) 100vw, 402px\" \/><\/p>\n<p>Click the <strong>Download and Run<\/strong> button.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-75060\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/10\/uPycraft-ide-tools-menu-download-and-run.png?resize=238%2C45&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"238\" height=\"45\" \/><\/p>\n<p class=\"rntbox rntclblue\"><strong>Note: <\/strong> if you&#8217;re having trouble uploading a new script to your ESP board, you might need to re-flash the MicroPython firmware on your board: <a href=\"https:\/\/randomnerdtutorials.com\/flash-upload-micropython-firmware-esp32-esp8266\/\" target=\"_blank\" rel=\"noopener noreferrer\">Flash\/Upload MicroPython Firmware to ESP<\/a>. When the ESP is in deep sleep mode, you can&#8217;t upload new scripts. Make sure you reset your board, press the Stop button in uPyCraft IDE immediately to catch it awake, so you can access the saved scripts and upload new ones.<\/p>\n<p>The file should be saved on the device folder with the name \u201c<strong>BME280.py<\/strong>\u201d as highlighted in the figure below.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78804\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/12\/BME280_success.png?resize=750%2C395&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"750\" height=\"395\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/12\/BME280_success.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/12\/BME280_success.png?resize=300%2C158&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/p>\n<p>Now, you can use the library functionalities in your code by importing the library.<\/p>\n<h2>Code<\/h2>\n<p>After uploading the <em>BME280.py<\/em> file to your ESP8266 or ESP32, copy the following code to the <em>boot.py<\/em> file. The <em>boot.py<\/em> file runs once on boot (it means every time the ESP8266\/ESP32 wakes up).<\/p>\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\"># Complete project details at https:\/\/RandomNerdTutorials.com\nimport machine\nfrom machine import Pin, I2C\n\nimport BME280\nimport network\nimport urequests\nfrom time import sleep\n\nimport esp\nesp.osdebug(None)\n\nimport gc\ngc.collect()\n\nssid = 'REPLACE_WITH_YOUR_SSID'\npassword = 'REPLACE_WITH_YOUR_PASSWORD'\n\napi_key = 'REPLACE_WITH_YOUR_IFTTT_API_KEY'\n\nms_sleep_time = 600000\n\nstation = network.WLAN(network.STA_IF)\n\nstation.active(True)\nstation.connect(ssid, password)\n\nwhile station.isconnected() == False:\n  pass\n\nprint('Connection successful')\nprint(station.ifconfig())\n\ndef deep_sleep(msecs) :\n  # configure RTC.ALARM0 to be able to wake the device\n  rtc = machine.RTC()\n  rtc.irq(trigger=rtc.ALARM0, wake=machine.DEEPSLEEP)\n\n  # set RTC.ALARM0 to fire after X milliseconds (waking the device)\n  rtc.alarm(rtc.ALARM0, msecs)\n\n  # put the device to sleep\n  machine.deepsleep()\n\n# ESP8266 - Pin assignement\ni2c = I2C(scl=Pin(5),sda=Pin(4), freq=10000)\n\n# ESP32 - Pin assignement\n#i2c = I2C(scl=Pin(22),sda=Pin(21), freq=10000)\n\ntry:\n  bme = BME280.BME280(i2c=i2c)\n  temp = bme.temperature\n  hum = bme.humidity\n  pres = bme.pressure\n\n  # uncomment for temperature in Fahrenheit\n  #temp = (bme.read_temperature()\/100) * (9\/5) + 32\n  #temp = str(round(temp, 2)) + 'F'\n\n  sensor_readings = {'value1':temp[:-1], 'value2':hum[:-1], 'value3':pres[:-3]}\n  print(sensor_readings)\n\n  request_headers = {'Content-Type': 'application\/json'}\n\n  request = urequests.post(\n    'http:\/\/maker.ifttt.com\/trigger\/bme280\/with\/key\/' + api_key,\n    json=sensor_readings,\n    headers=request_headers)\n  print(request.text)\n  request.close()\n\nexcept OSError as e:\n  print('Failed to read\/publish sensor readings.')\n\nsleep(10)\n\n#ESP8266\ndeep_sleep(ms_sleep_time)\n\n#ESP32\n#machine.deepsleep(ms_sleep_time)\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/ESP-MicroPython\/esp_deepsleep_bme280_boot.py\" target=\"_blank\">View raw code<\/a><\/p>\n<p>Before uploading the code to your board, you need to include your own network credentials and your unique IFTTT API key. Continue reading to see how to do that.<\/p>\n<h2>How the Code Works<\/h2>\n<p>Let&#8217;s take a quick look at the code and see how it works.<\/p>\n<h3>Importing libraries<\/h3>\n<p>You start by importing the necessary modules. To interact with the GPIOs and read data from the sensor via I2C communication, you need to import the <span class=\"rnthl rntliteral\">Pin<\/span> and <span class=\"rnthl rntliteral\">I2C<\/span> classes from the <span class=\"rnthl rntliteral\">machine<\/span> module. You also import the complete <span class=\"rnthl rntliteral\">machine<\/span> module to be able to use functions related with deep sleep.<\/p>\n<pre class=\"language-python\"><code class=\"language-python\">import machine\nfrom machine import Pin, I2C<\/code><\/pre>\n<p>You need to import the <span class=\"rnthl rntliteral\">BME280<\/span> library that you previously uploaded to the board.<\/p>\n<pre class=\"language-python\"><code>import BME280<\/code><\/pre>\n<p>To connect to your network, you need to import the <span class=\"rnthl rntliteral\">network<\/span> module.<\/p>\n<pre class=\"language-python\"><code>import network<\/code><\/pre>\n<p>You need the <span class=\"rnthl rntliteral\">urequests<\/span> library. This library allows you to make HTTP requests. In this example, we\u2019ll make a request to the IFTTT services to publish the sensor readings to a Google Sheets spreadsheet.<\/p>\n<pre class=\"language-python\"><code>import urequests<\/code><\/pre>\n<p>Finally, import the<span class=\"rnthl rntliteral\">sleep<\/span> function from the <span class=\"rnthl rntliteral\">time<\/span> module to be able to add delays to the code.<\/p>\n<pre class=\"language-python\"><code>from time import sleep<\/code><\/pre>\n<h3>Setting your network credentials<\/h3>\n<p>You need to add your SSID and password in the following variables:<\/p>\n<pre class=\"language-python\"><code class=\"language-python\">ssid = 'REPLACE_WITH_YOUR_SSID'\npassword = 'REPLACE_WITH_YOUR_PASSWORD'<\/code><\/pre>\n<h3>Including your IFTTT API key<\/h3>\n<p>Insert your unique API key from the Webhooks IFTTT service in the following line:<\/p>\n<pre class=\"language-python\"><code>api_key = 'REPLACE_WITH_YOUR_WEBHOOKS_IFTTT_API_KEY'<\/code><\/pre>\n<h3>Setting the sleep time<\/h3>\n<p>In this example we\u2019ve set the sleep time to 10 minutes (600000 milliseconds). This means that every 10 minutes the ESP wakes up, takes the readings, and publishes them in your Google Sheets spreadsheet. The sleep time is set in the <span class=\"rnthl rntliteral\">ms_sleep_time<\/span> variable in milliseconds:<\/p>\n<pre class=\"language-python\"><code>ms_sleep_time = 600000<\/code><\/pre>\n<p class=\"rntbox rntcred\"><strong>Warning: <\/strong> if you set a very short period, you may exceed the limit of requests imposed by the IFTTT services.<\/p>\n<h3>Connecting to the network<\/h3>\n<p>The following lines connect the\u00a0ESP8266\/ESP32 to your router, and print the ESP IP address:<\/p>\n<pre class=\"language-python\"><code class=\"language-python\">station = network.WLAN(network.STA_IF) \n\nstation.active(True) \nstation.connect(ssid, password) \n\nwhile station.isconnected() == False: \n  pass\n\nprint('Connection successful') \nprint(station.ifconfig())<\/code><\/pre>\n<h3>Deep sleep function (ESP8266)<\/h3>\n<p>Then, create a function called <span class=\"rnthl rntliteral\">deep_sleep()<\/span> that accepts as argument the number of milliseconds we want the ESP8266 to be in deep sleep mode.<\/p>\n<pre class=\"language-python\"><code class=\"language-python\">def deep_sleep(msecs) :\n  # configure RTC.ALARM0 to be able to wake the device \n  rtc = machine.RTC() \n  rtc.irq(trigger=rtc.ALARM0, wake=machine.DEEPSLEEP) \n\n  # set RTC.ALARM0 to fire after X milliseconds (waking the device)\n  rtc.alarm(rtc.ALARM0, msecs)\n  \n  # put the device to sleep \n  machine.deepsleep()<\/code><\/pre>\n<p class=\"rntbox rntclblue\"><strong>Note: <\/strong>if you&#8217;re using an ESP32, you don&#8217;t need to create\/use this function.<\/p>\n<h3>Reading temperature, humidity, and pressure<\/h3>\n<p>Then, create an <span class=\"rnthl rntliteral\">I2C<\/span> instance called <span class=\"rnthl rntliteral\">i2c<\/span>. You need this to create an I2C connection with the BME280 sensor. Pass as arguments the SCL and SDA pins, as well as a frequency. Don\u2019t worry about the frequency, a value of 10000 Hz works just fine for this sensor.<\/p>\n<p>The ESP8266 default I2C pins are <span class=\"rnthl rntclblue\">GPIO 5<\/span> (SLC) and <span class=\"rnthl rntclgreen\">GPIO 4<\/span> (SDA).<\/p>\n<pre class=\"language-python\"><code>i2c = I2C(scl=Pin(5),sda=Pin(4), freq=10000)<\/code><\/pre>\n<p>The ESP32 default I2C pins are <span class=\"rnthl rntclblue\">GPIO 22<\/span> (SCL) and <span class=\"rnthl rntclgreen\">GPIO 21<\/span> (SDA). Comment the previous line and uncomment the following line if you&#8217;re using an ESP32 board.<\/p>\n<pre class=\"language-python\"><code>#i2c = I2C(scl=Pin(22),sda=Pin(21), freq=10000)<\/code><\/pre>\n<p>Then, use <span class=\"rnthl rntliteral\">try<\/span>except statements. In the <span class=\"rnthl rntliteral\">try<\/span> statement, we read from the sensor and make an HTTP post request to the IFTTT services.<\/p>\n<p>The temperature is saved on the <span class=\"rnthl rntliteral\">temp<\/span> variable, the humidity on the <span class=\"rnthl rntliteral\">hum<\/span> variable, and the pressure on the <span class=\"rnthl rntliteral\">pres<\/span> variable.<\/p>\n<pre class=\"language-python\"><code class=\"language-python\">try: \n  bme = BME280.BME280(i2c=i2c) \n  temp = bme.temperature \n  hum = bme.humidity \n  pres = bme.pressure<\/code><\/pre>\n<p>Uncomment the following lines, if you want to get temperature in Fahrenheit degrees.<\/p>\n<pre class=\"language-python\"><code class=\"language-python\"># uncomment for temperature in Fahrenheit \n#temp = (bme.read_temperature()\/100) * (9\/5) + 32 \n#temp = str(round(temp, 2)) + 'F'<\/code><\/pre>\n<p>Then, store the sensor readings in JSON format in the <span class=\"rnthl rntliteral\">sensor_readings<\/span> variable. This is required to make the HTTP POST request on IFTTT.<\/p>\n<pre class=\"language-python\"><code>sensor_readings = {'value1':temp[:-1], 'value2':hum[:-1], 'value3':pres[:-3]}<\/code><\/pre>\n<p>The BME280 library returns the readings with units (C for temperature, % for humidity, and hpa for pressure). To make it easier to analyse the data later, we remove the units by adding [:-1] to remove the last character from the string. The [:-3] for the pressure removes the last three characters from the string (hpa).<\/p>\n<h3>HTTP Post request<\/h3>\n<p>A general HTTP POST request in MicroPython using the <span class=\"rnthl rntliteral\">urequests<\/span> library has the following format:<\/p>\n<pre class=\"language-python\"><code>request= requests.post(&lt;your_url&gt;, json=&lt;json_data&gt;, headers=&lt;headers&gt;)<\/code><\/pre>\n<p>The first parameter is the URL in which you will make the request. As we\u2019ve seen in the IFTTT Applet, we need to use the following URL (in which <span class=\"rnthl rntliteral\">api_key<\/span> will be replaced with your own API key):<\/p>\n<pre class=\"language-python\"><code>http:\/\/maker.ifttt.com\/trigger\/bme_280_readings\/with\/key\/your_api_key<\/code><\/pre>\n<p>The JSON parameter should contain data in JSON format. In our case, that&#8217;s the <span class=\"rnthl rntliteral\">sensor_readings<\/span> variable:<\/p>\n<pre class=\"language-python\"><code>json=sensor_readings<\/code><\/pre>\n<p>The <span class=\"rnthl rntliteral\">headers<\/span> parameter contains information about the request. For our request, the headers should be as follows:<\/p>\n<pre class=\"language-python\"><code>request_headers = {'Content-Type': 'application\/json'}<\/code><\/pre>\n<p>Finally, we make the request using the <span class=\"rnthl rntliteral\">post()<\/span> method with the information we\u2019ve defined earlier:<\/p>\n<pre class=\"language-python\"><code class=\"language-python\">request = urequests.post(\n  'http:\/\/maker.ifttt.com\/trigger\/bme_280_readings\/with\/key\/' + api_key,\n  json=sensor_readings,\n  headers=request_headers)<\/code><\/pre>\n<p>Finally, print the request and close the connection:<\/p>\n<pre class=\"language-python\"><code class=\"language-python\">print(request.text)\nrequest.close()<\/code><\/pre>\n<p>If reading data from the sensor or publishing the sensor readings fails, the <span class=\"rnthl rntliteral\">except<\/span> statement runs and we print the &#8216;Failed to read\/publish sensor readings.&#8217; message.<\/p>\n<pre class=\"language-python\"><code class=\"language-python\">except OSError as e:\n  print('Failed to read\/publish sensor readings.')<\/code><\/pre>\n<p>The except statements in MicroPython prevent your board from crashing in case an error occurs.<\/p>\n<h3>Going to sleep<\/h3>\n<p>After making the HTTP POST request, we put the ESP8266\/ESP32 in deep sleep mode. Use the following line if you&#8217;re using an ESP8266:<\/p>\n<pre class=\"language-python\"><code>deep_sleep(sleep_time_ms)<\/code><\/pre>\n<p>Comment the previous line and uncomment the following line if you&#8217;re using an ESP32:<\/p>\n<pre class=\"language-python\"><code>#machine.deepsleep(ms_sleep_time)<\/code><\/pre>\n<p>To use deep sleep with the ESP32 with timer wake up, we just need to use the <span class=\"rnthl rntliteral\">deepsleep()<\/span> method and pass as an argument the sleep time in milliseconds.<\/p>\n<h2>Building the Circuit<\/h2>\n<p>The BME280 sensor we&#8217;re using communicates via I2C communication protocol.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-78859\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/12\/BME280.jpg?resize=750%2C412&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"750\" height=\"412\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/12\/BME280.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/12\/BME280.jpg?resize=300%2C165&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/p>\n<p>Follow one of the next schematics depending on the board you&#8217;re using.<\/p>\n<p><strong>ESP8266 12-E<\/strong><\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-79287\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/12\/esp12-e-bme280_bb_f.png?resize=640%2C503&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"640\" height=\"503\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/12\/esp12-e-bme280_bb_f.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/12\/esp12-e-bme280_bb_f.png?resize=300%2C236&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/p>\n<p class=\"rntbox rntcred\"><strong>Important: <\/strong> you should only connect GPIO16 to the RST pin after uploading the code. This connection is needed so that the ESP8266 is able to wake itself up.<\/p>\n<p class=\"rntbox rntclblue\"><strong>Note: <\/strong> if you&#8217;re using an ESP8266 12-E, we recommend using <a href=\"https:\/\/www.banggood.com\/5Pcs-Serial-Port-WIFI-ESP8266-Module-Adapter-Plate-With-IO-Lead-Out-For-ESP-07-ESP-08-ESP-12-p-1056677.html?p=MA240439985285201910\" target=\"_blank\" rel=\"noopener nofollow noreferrer\">an adapter<\/a> to use it with a breadboard and make the wiring easier. Alternatively, you can make a PCB at home like we did. We used the etching technique.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-79447\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/01\/esp12-e-pcb.jpg?resize=750%2C418&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"esp8266 12-E PCB adapter to breadboard\" width=\"750\" height=\"418\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/01\/esp12-e-pcb.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/01\/esp12-e-pcb.jpg?resize=300%2C167&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/p>\n<p><strong>ESP8266 NodeMCU Kit<\/strong><\/p>\n<p>If you&#8217;re using an ESP8266 NodeMCU kit, you also need to connect the RST pin to GPIO 16 (D0) after uploading the code.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-57695\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/04\/bme_280_esp8266_bb.png?resize=401%2C311&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"401\" height=\"311\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/04\/bme_280_esp8266_bb.png?w=753&amp;quality=100&amp;strip=all&amp;ssl=1 753w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/04\/bme_280_esp8266_bb.png?resize=300%2C232&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 401px) 100vw, 401px\" \/><\/p>\n<p><strong>ESP32<\/strong><\/p>\n<p>If you&#8217;re using an ESP32, you just need to wire the circuit as shown in the schematic diagram:<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-56623\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/03\/ESP32-bme280_bb.png?resize=400%2C348&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"400\" height=\"348\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/03\/ESP32-bme280_bb.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2018\/03\/ESP32-bme280_bb.png?resize=300%2C261&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 400px) 100vw, 400px\" \/><\/p>\n<h2>Demonstration<\/h2>\n<p>After uploading the necessary files to your board in the following order:<\/p>\n<ol>\n<li><em>BME280.py<\/em><\/li>\n<li><em>boot.py<\/em><\/li>\n<\/ol>\n<p>The ESP8266\/ESP32 will start publishing the sensor readings on the Google Sheets spreadsheet.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-79487\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/01\/spreadsheet-esp8266-bme280.png?resize=750%2C348&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"750\" height=\"348\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/01\/spreadsheet-esp8266-bme280.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/01\/spreadsheet-esp8266-bme280.png?resize=300%2C139&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/01\/spreadsheet-esp8266-bme280.png?resize=510%2C238&amp;quality=100&amp;strip=all&amp;ssl=1 510w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/p>\n<h2>Power Consumption<\/h2>\n<p>When the ESP8266 12-E is in deep sleep mode it consumes about 7uA to 8uA.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-79444\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/01\/esp12-e-low-power-bme280.jpg?resize=750%2C438&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"750\" height=\"438\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/01\/esp12-e-low-power-bme280.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/01\/esp12-e-low-power-bme280.jpg?resize=300%2C175&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/p>\n<p>When the ESP8266 wakes up and connects to Wi-Fi, the current consumption can go up to 80mA.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-79445\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/01\/esp12-e-normal.mode_.jpg?resize=750%2C451&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"750\" height=\"451\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/01\/esp12-e-normal.mode_.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/01\/esp12-e-normal.mode_.jpg?resize=300%2C180&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/p>\n<p>If you&#8217;re using a ESP development board, you&#8217;ll get a higher current consumption in deep sleep.<\/p>\n<h2>Powering the ESP8266\/ESP32 with Batteries<\/h2>\n<p>If you build this project with the ESP8266 12-E chip, it uses very little power during deepsleep (approximately 7uA). You can power it using batteries and they will last for several months (or even years depending on the capacity).<\/p>\n<p>We plan to create a Part 2 of this project using a battery powered circuit. Meanwhile, you can read <a href=\"https:\/\/randomnerdtutorials.com\/esp8266-voltage-regulator-lipo-and-li-ion-batteries\/\">this tutorial to\u00a0power the ESP using LiPo and Li-ion batteries<\/a>.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-47763\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/11\/ESP8266-LiPo-Li-ion-Batteries-circuit-schematic-fritzing.jpg?resize=522%2C456&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"522\" height=\"456\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/11\/ESP8266-LiPo-Li-ion-Batteries-circuit-schematic-fritzing.jpg?w=522&amp;quality=100&amp;strip=all&amp;ssl=1 522w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/11\/ESP8266-LiPo-Li-ion-Batteries-circuit-schematic-fritzing.jpg?resize=300%2C262&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 522px) 100vw, 522px\" \/><\/p>\n<h2>Wrapping Up<\/h2>\n<p>With this project you&#8217;ve learned how to build a datalogger that publishes sensor readings to a Google Sheets spreadsheet. Throughout the instructions, you&#8217;ve learned how to use the BME280, make HTTP POST requests and use deep sleep with ESP8266\/ESP32 using MicroPython.<\/p>\n<p>We hope you&#8217;ve found this project interesting. You may also like:<\/p>\n<ul>\n<li><strong><a href=\"https:\/\/randomnerdtutorials.com\/micropython-programming-with-esp32-and-esp8266\/\" rel=\"noopener noreferrer\">[eBook] MicroPython Programming with ESP32 and ESP8266<\/a><\/strong><\/li>\n<li><a href=\"https:\/\/randomnerdtutorials.com\/micropython-esp8266-deep-sleep-wake-up-sources\/\">ESP8266 Deep Sleep and Wake Up Sources (MicroPython)<\/a><\/li>\n<li><a href=\"https:\/\/randomnerdtutorials.com\/micropython-esp32-deep-sleep-wake-up-sources\/\">ESP32 Deep Sleep and Wake Up Sources (MicroPython)<\/a><\/li>\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-web-server-with-bme280-mini-weather-station\/\">ESP32 Web Server with BME280 \u2013 Mini Weather Station<\/a>\u00a0(Arduino IDE)<\/li>\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-esp8266-publish-sensor-readings-to-google-sheets\/\">ESP32 Publish Sensor Readings to Google Sheets (ESP8266 Compatible)<\/a>\u00a0(Arduino IDE)<\/li>\n<\/ul>\n<p>Thanks for reading.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This project shows how to build a data logger that publishes temperature, humidity and pressure readings every 10 minutes to a Google Sheets spreadsheet using an ESP8266 12-E. Between sensor &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Low Power Weather Station Datalogger using ESP8266 and BME280 with MicroPython\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/low-power-weather-station-datalogger-using-esp8266-bme280-micropython\/#more-78800\" aria-label=\"Read more about Low Power Weather Station Datalogger using ESP8266 and BME280 with MicroPython\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":5,"featured_media":79490,"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":[281,265,309,264],"tags":[],"class_list":["post-78800","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-esp32-project","category-esp8266-project","category-0-esp32-micropython","category-project"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2019\/01\/ESP12-e-low-power-micropython-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\/78800","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\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=78800"}],"version-history":[{"count":2,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/78800\/revisions"}],"predecessor-version":[{"id":108667,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/78800\/revisions\/108667"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/79490"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=78800"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=78800"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=78800"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}