{"id":15496,"date":"2016-01-05T10:32:45","date_gmt":"2016-01-05T10:32:45","guid":{"rendered":"http:\/\/randomnerdtutorials.com\/?p=15496"},"modified":"2019-05-01T10:57:31","modified_gmt":"2019-05-01T10:57:31","slug":"esp8266-wireless-weather-station-with-data-logging-to-excel","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/esp8266-wireless-weather-station-with-data-logging-to-excel\/","title":{"rendered":"ESP8266 &#8211; Wireless Weather Station with Data Logging to Excel"},"content":{"rendered":"<p>In this project we are going to establish a wireless communication between two ESPs and send&nbsp;data from three&nbsp;sensors to an Excel spreadsheet. This tutorial shows a&nbsp;wireless weather station with data logging that you can implement in your home.<!--more--><\/p>\n<div style=\"padding: 10px; line-height: 1.2; text-align: center; background-color: #f5f5f5;\">This project is a collaboration between&nbsp;<a href=\"https:\/\/www.facebook.com\/profile.php?id=100007834037753\" target=\"_blank\" rel=\"noopener noreferrer\">Yves Arbour<\/a> and Rui Santos.<\/div>\n<p>&nbsp;<br \/>\n<img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter  wp-image-15640\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/Wireless-Weather-Station-with-Data-Logging-to-Excel-thumb.jpg?resize=700%2C470&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"700\" height=\"470\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/Wireless-Weather-Station-with-Data-Logging-to-Excel-thumb.jpg?w=1288&amp;quality=100&amp;strip=all&amp;ssl=1 1288w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/Wireless-Weather-Station-with-Data-Logging-to-Excel-thumb.jpg?resize=300%2C201&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/Wireless-Weather-Station-with-Data-Logging-to-Excel-thumb.jpg?resize=768%2C515&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/Wireless-Weather-Station-with-Data-Logging-to-Excel-thumb.jpg?resize=1024%2C687&amp;quality=100&amp;strip=all&amp;ssl=1 1024w\" sizes=\"(max-width: 700px) 100vw, 700px\" \/><\/p>\n<p><strong>Before you continue reading this project, please complete&nbsp;the following tutorials:&nbsp;<\/strong><\/p>\n<ul>\n<li><a href=\"https:\/\/randomnerdtutorials.com\/getting-started-with-esp8266-wifi-transceiver-review\/\" target=\"_blank\" rel=\"noopener noreferrer\">How to get started with the ESP8266<\/a><\/li>\n<li><a href=\"https:\/\/randomnerdtutorials.com\/how-to-make-two-esp8266-talk\/\">How to make two ESP8266 talk<\/a><\/li>\n<li><a href=\"https:\/\/randomnerdtutorials.com\/flashing-nodemcu-firmware-on-the-esp8266-using-windows\/\" target=\"_blank\" rel=\"noopener noreferrer\">How to flash your ESP8266&nbsp;with NodeMCU<\/a><\/li>\n<\/ul>\n<p>If you like the ESP WiFi module and you want to build more&nbsp;projects&nbsp;you can download my eBook called <a href=\"https:\/\/randomnerdtutorials.com\/home-automation-using-esp8266\/\" target=\"_blank\" rel=\"noopener noreferrer\">\u201cHome Automation using ESP8266\u201d here<\/a>.&nbsp;<strong>Let\u2019s get started!<\/strong><\/p>\n<h2>Summary<\/h2>\n<p>Here&#8217;s a&nbsp;Figure&nbsp;that describes exactly&nbsp;how everything&nbsp;works together:<\/p>\n<p><img data-recalc-dims=\"1\" decoding=\"async\" class=\"aligncenter size-full wp-image-15641\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/introduction-esp8266-wireless-station.jpg?resize=666%2C281&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"introduction esp8266 wireless station\" width=\"666\" height=\"281\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/introduction-esp8266-wireless-station.jpg?w=666&amp;quality=100&amp;strip=all&amp;ssl=1 666w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/introduction-esp8266-wireless-station.jpg?resize=300%2C127&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 666px) 100vw, 666px\" \/><\/p>\n<h2>Parts List<\/h2>\n<p>Here\u2019s the hardware that you need to make the weather station:<\/p>\n<ul>\n<li><strong><a href=\"https:\/\/makeradvisor.com\/tools\/esp8266-esp-12e-nodemcu-wi-fi-development-board\/\" target=\"_blank\" rel=\"noopener noreferrer\">Recommended: 2x&nbsp;ESP-12E<\/a>&nbsp;<\/strong>read&nbsp;<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>Alternative: <a href=\"http:\/\/ebay.to\/1ZoVc4Z\" target=\"_blank\" rel=\"noopener noreferrer\">2x ESP-201<\/a>&nbsp;+&nbsp;<a href=\"https:\/\/makeradvisor.com\/tools\/ftdi-programmer-board\/\" target=\"_blank\" rel=\"noopener noreferrer\">1x&nbsp;FTDI Programmer<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/ds18b20-digital-temperature-sensor\/\" target=\"_blank\" rel=\"noopener noreferrer\">1x&nbsp;DS18B20&nbsp;<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/mb-102-solderless-breadboard-830-points\/\" target=\"_blank\" rel=\"noopener noreferrer\">1x Breadboard&nbsp;<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/pushbuttons-kit\/\" target=\"_blank\" rel=\"noopener noreferrer\">3x Pushbutton<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/resistors-kits\/\" target=\"_blank\" rel=\"noopener noreferrer\">3x 10k&nbsp;Ohm Resistor<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/resistors-kits\/\" target=\"_blank\" rel=\"noopener noreferrer\">1x 4700&nbsp;Ohm Resistor<\/a><\/li>\n<li><a href=\"https:\/\/makeradvisor.com\/tools\/potentiometer-assortment-kit\/\" target=\"_blank\" rel=\"noopener noreferrer\">1x 10k Ohm Potentiometer<\/a><\/li>\n<\/ul>\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<h3>DS18B20 &#8211; One Wire Digital Temperature Sensor<\/h3>\n<p>In this project, we will be using the <a href=\"http:\/\/ebay.to\/1NC76mS\" target=\"_blank\" rel=\"noopener noreferrer\">DS18B20&nbsp;one wire digital temperature sensor<\/a>.&nbsp;Now, before we get to the programming part, lets learn how to wire up our temperature sensor.<\/p>\n<p>The DS18B20 can be powered by between 3.0V and 5.5V so you can simply connect its GND pin to GND&nbsp;and the VDD pin to 3.3V from the ESP8266.<\/p>\n<p>Then connect the DQ pin to IO04&nbsp;on the ESP8266.&nbsp;A 4K7 ohm pullup resistor is required on the DQ pin to pull it up to 3.3V.<\/p>\n<p><img data-recalc-dims=\"1\" decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/i0.wp.com\/www.hobbytronics.co.uk\/image\/data\/maxim\/ds18b20-pinout.jpg?resize=223%2C281&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"DS18B20 pinout\" width=\"223\" height=\"281\"><\/p>\n<h3>Reading ADC Value<\/h3>\n<p>We&#8217;re going to use&nbsp;the ADC pin to read an analog value and when referring to the ESP ADC&nbsp;pin you will often hear these different terms interchangeably:<\/p>\n<ul>\n<li>ADC (Analog-to-digital Converter)<\/li>\n<li>TOUT<\/li>\n<li>Pin6<\/li>\n<li>A0<\/li>\n<li>Analog Pin 0<\/li>\n<\/ul>\n<p>All these terms refer to the same pin in the <a href=\"http:\/\/ebay.to\/1jU3piA\" target=\"_blank\" rel=\"noopener noreferrer\">ESP8266<\/a> that&nbsp;is highlighted&nbsp;in the next section (<a href=\"https:\/\/randomnerdtutorials.com\/esp8266-adc-reading-analog-values-with-nodemcu\/\">read this article&nbsp;for more information on&nbsp;the ADC pin<\/a>).<\/p>\n<p>Currently, TOUT (Pin6) has&nbsp;a 10-bit precision&nbsp;and its&nbsp;input voltage range is 0 to 1.0 V when TOUT is connected to an external circuit.<\/p>\n<h3>Accessing the ESP8266 Analog Pin<\/h3>\n<p>With the <a href=\"http:\/\/ebay.to\/1ZoVc4Z\" target=\"_blank\" rel=\"noopener noreferrer\">ESP-201<\/a> is very easy to access the ADC, you simply connect a jumper wire to the pin highlighted in the&nbsp;Figure below.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-15634\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/esp-201.png?resize=314%2C300&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"esp-201\" width=\"314\" height=\"300\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/esp-201.png?w=376&amp;quality=100&amp;strip=all&amp;ssl=1 376w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/esp-201.png?resize=300%2C286&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 314px) 100vw, 314px\" \/><\/p>\n<h2>Flashing Boths&nbsp;ESPs with NodeMCU<\/h2>\n<p>We&nbsp;are going to use the NodeMCU firmware, so you have to&nbsp;<a href=\"https:\/\/randomnerdtutorials.com\/flashing-nodemcu-firmware-on-the-esp8266-using-windows\/\" target=\"_blank\" rel=\"noopener noreferrer\">flash your&nbsp;ESPs with NodeMCU firmare<\/a>.<\/p>\n<h2>Downloading ESPlorer IDE<\/h2>\n<p>I recommend using the ESPlorer IDE which is a program&nbsp;created by 4refr0nt&nbsp;to upload scripts&nbsp;to your&nbsp;ESP8266.<\/p>\n<p>Follow these instructions to download and install ESPlorer IDE:<\/p>\n<p>1)&nbsp;<a href=\"http:\/\/esp8266.ru\/esplorer\/#tutorials\" target=\"_blank\" rel=\"noopener noreferrer\">Click here<\/a> to download&nbsp;ESPlorer<\/p>\n<p>2) Unzip that folder<\/p>\n<p>3) Go to the main&nbsp;folder<\/p>\n<p>4) Run&nbsp;ESPlorer.jar<\/p>\n<p>5) Open the ESPlorer<\/p>\n<h2>Uploading a Script&nbsp;to Your ESP8266&nbsp;(3.3V FTDI&nbsp;Programmer)<\/h2>\n<p>The schematics to upload scripts to an&nbsp;ESP are very straight forward. You only need to establish a serial communication between your FTDI programmer and your ESP8266 (repeat the schematics below for the Client and Server).<\/p>\n<p>Here&#8217;s the connections:<\/p>\n<ul>\n<li>VCC &#8211; 3.3V<\/li>\n<li>GND &#8211; GND<\/li>\n<li>TX &#8211; RX<\/li>\n<li>RX &#8211; TX<\/li>\n<li>GPIO 0 &#8211; 3.3V<\/li>\n<li>GPIO 15 &#8211; GND<\/li>\n<\/ul>\n<h2>Writing Your Client Scripts<\/h2>\n<p>There are three scripts that you need to upload to your ESP8266 client:<\/p>\n<ul>\n<li><strong><a href=\"https:\/\/raw.githubusercontent.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/master\/Projects\/Yves-Arbour\/init_client.lua\" target=\"_blank\" rel=\"noopener noreferrer\">init.lua<\/a><\/strong><\/li>\n<li><strong><a href=\"https:\/\/raw.githubusercontent.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/master\/Projects\/Yves-Arbour\/counterMax.lua\" target=\"_blank\" rel=\"noopener noreferrer\">counterMax.lua<\/a><\/strong><\/li>\n<li><strong>ds18b20.lua<\/strong>\n<ul>\n<li><a href=\"https:\/\/raw.githubusercontent.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/master\/Projects\/Yves-Arbour\/ds18b20.lua\" target=\"_blank\" rel=\"noopener noreferrer\">Measures temperature in \u00baC<\/a><\/li>\n<li><a href=\"https:\/\/raw.githubusercontent.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/master\/Projects\/Yves-Arbour\/ds18b20_fahrenheit.lua\" target=\"_blank\" rel=\"noopener noreferrer\">Measures temperature in \u00baF<\/a><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>Start by uploading the following script&nbsp;and name it <em>counterMax.lua<\/em>. It is just a numerical number 1 that does some counting and helps reset your board if it looses connection with the ESP server.<\/p>\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">1\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/Yves-Arbour\/counterMax.lua\" target=\"_blank\">View raw code<\/a><\/p>\n<p>When you upload the <em>counterMax.lua&nbsp;<\/em>script it is expected to print the following error:<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-15632\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/uploading-counter-max.png?resize=473%2C257&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"uploading counter max\" width=\"473\" height=\"257\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/uploading-counter-max.png?w=473&amp;quality=100&amp;strip=all&amp;ssl=1 473w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/uploading-counter-max.png?resize=300%2C163&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 473px) 100vw, 473px\" \/><\/p>\n<p>Upload the script below to read the temperature in \u00baC&nbsp;or upload <a href=\"https:\/\/raw.githubusercontent.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/master\/Projects\/Yves-Arbour\/ds18b20_fahrenheit.lua\" target=\"_blank\" rel=\"noopener noreferrer\">this script to read temperature in \u00baF<\/a>. Make sure you save the file to your ESP with the name <em>ds18b20.lua<\/em>.<\/p>\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">--------------------------------------------------------------------------------\n-- DS18B20 one wire module for NODEMCU\n-- LICENCE: http:\/\/opensource.org\/licenses\/MIT\n-- Vowstar &lt;vowstar@nodemcu.com&gt;\n-- Dramatic simplification: Peter Scargill\n--------------------------------------------------------------------------------\n\n-- Set module name as parameter of require\nlocal modname = ...\nlocal M = {}\n_G[modname] = M\n--------------------------------------------------------------------------------\n-- Local used modules\n--------------------------------------------------------------------------------\n-- Table module\nlocal table = table\n-- String module\nlocal string = string\n-- One wire module\nlocal ow = ow\n-- Timer module\nlocal tmr = tmr\n-- Limited to local environment\nsetfenv(1,M)\n--------------------------------------------------------------------------------\n-- Implementation \u2013 you don\u2019t get any shorter than this\n--------------------------------------------------------------------------------\n\nfunction readNumber(pin)\n        ow.setup(pin)\n        ow.reset(pin)\n        ow.write(pin, 0xCC, 1)\n        ow.write(pin, 0xBE, 1)\n        data = nil\n        data = &quot;&quot;\n        for i = 1, 2 do\n            data = data .. string.char(ow.read(pin))\n        end\n        t = (data:byte(1) + data:byte(2) * 256) \/ 16\n        if (t&gt;100) then\n        t=t-4096\n        end\n        ow.reset(pin)\n        ow.write(pin,0xcc,1)\n        ow.write(pin, 0x44,1)  \n        return t          \nend\n\n-- Return module table\nreturn M\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/Yves-Arbour\/ds18b20.lua\" target=\"_blank\">View raw code<\/a><\/p>\n<p>Finally upload the main script to your ESP and name it <em>init.lua<\/em>.<\/p>\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">-- Yves Arbour wireless weather station project with data logging to Excel sheets with Things Gateway\n-- code based on the following\n-- Rui Santos - ESP8266 Client\n-- DS18B20 one wire module for NODEMCU \n-- Vowstar &lt;vowstar@nodemcu.com&gt; \n-- Peter Scargill \n-- Wimp Weather Station by sparkfun Nathan Seidle\n\nwifi.sta.disconnect()\nwifi.setmode(wifi.STATION)\nwifi.sta.config(&quot;test&quot;,&quot;12345678&quot;)\nwifi.sta.connect() \nprint(&quot;Looking for a connection&quot;)\ntemp=0\nfunction readds18b20sensor()\n    t=require(&quot;ds18b20.lua&quot;)   \n   -- print(t.readNumber(2))  for debuging\n    temp = (t.readNumber(2)) --GPIO 04\nend\n\nwinDirection=0\ngpio.mode(0,gpio.INPUT)\nfunction readWindDirection ()\n    windDirection = adc.read(0)\n        if (windDirection &lt; 26) then windDirection=90 --E\n       --if (windDirection &lt; 17) then windDirection=113      -- ESE\n       --elseif (windDirection &lt; 21) then windDirection=68   -- ENE\n       --elseif (windDirection &lt; 26) then windDirection=90   -- E\n       --elseif (windDirection &lt; 36) then windDirection=158  -- SSE\n       elseif (windDirection &lt; 43) then windDirection=135 --SE\n       --elseif (windDirection &lt; 60) then windDirection=203  -- SSW\n       elseif (windDirection &lt; 85) then windDirection=180 --S\n       --elseif (windDirection &lt; 98) then windDirection=23   -- NNE\n       elseif (windDirection &lt; 120) then windDirection=45 --NE\n       --elseif (windDirection &lt; 170) then windDirection=248  -- WSW\n       elseif (windDirection &lt; 210) then windDirection=225 -SW\n       --elseif (windDirection &lt; 275) then windDirection=338  -- NNW\n       elseif (windDirection &lt; 380) then windDirection=0 --N\n       --elseif (windDirection &lt; 500) then windDirection=293  -- WNW\n       elseif (windDirection &lt; 750) then windDirection=315 --NW\n       elseif (windDirection &lt; 1005) then windDirection=270 --W\n       else windDirection=-1\n       end\nend\nirqPin = 1  --GPIO5\nwindSpeed = 0\nwindClicks = 0\nlastWindCheck = 0\nfunction debounce (func)   \n    local delay = 100000   \n    return function (...)  \n        now = tmr.now() \n        now = now - lastWindCheck               \n        if now &lt; delay then return end\n        lastWindCheck = tmr.now()        \n        return func (...)\n    end\nend\n\nfunction windSpeedIrq ()    \n    windClicks = windClicks+1 * 10000000\n    print (windClicks)\nend  \nfunction calcWindSpeed ()\n    local deltaTime = tmr.now () - lastWindCheck        \n    windSpeed = windClicks \/ deltaTime\n    print(deltaTime)              \n    windSpeed = windSpeed * 1492 \/10000 -- Replace &quot; *1492\/10000 &quot; with &quot; *24\/100 &quot; for Km\/h instead of Mp\/h\n    windClicks = 0\n    lastWindCheck = tmr.now()\nend \ngpio.mode(irqPin,gpio.INT)\ngpio.trig(irqPin,&quot;down&quot;,debounce(windSpeedIrq))\n      \nfile.open(&quot;counterMax.lua&quot;,&quot;r&quot;)\ncounter=(file.read())\nfile.close()\n  tmr.alarm(0, 2000, 1, function()\n   if(wifi.sta.getip()~=nil) then\n          tmr.stop(0)\n          print(&quot;Client IP Address:&quot;,wifi.sta.getip())\n          cl=net.createConnection(net.TCP, 0)\n          cl:connect(80,&quot;192.168.4.1&quot;)\n          tmr.alarm(1, 5000, 1, function()\n          counter=counter+1       \n       \n        readds18b20sensor()            \n        readWindDirection()\n        calcWindSpeed()\n        print (temp)\n        print(windSpeed)\n-- Next is the properly formated string that Things Gateway needs to show Date,Time,Wind speed,Wind direction and  Temp.    \n  cl:send(&quot;XLS,write,Example,A&quot;..counter..&quot;,%date%\\nXLS,write,Example,B&quot;..counter..&quot;,%time%\\nXLS,write,Example,C&quot;..counter..&quot;,&quot;..windSpeed..&quot;\\nXLS,write,Example,D&quot;..counter..&quot;,&quot;..windDirection..&quot;\\nXLS,write,Example,E&quot;..counter..&quot;,&quot;..temp)\n  \n  cl:on(&quot;disconnection&quot;,function(reconnect)\n    file.open(&quot;counterMax.lua&quot;,&quot;w+&quot;)\n    file.writeline(counter)\n    file.close()\n   end)\n       end)\n   else\n         print(&quot;Connecting...&quot;)\n       end\nend)\nfunction reconnect()    \nwifi.setmode(wifi.STATION)\nwifi.sta.config(&quot;test&quot;,&quot;12345678&quot;)\nwifi.sta.connect()\nend  \n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/Yves-Arbour\/init_client.lua\" target=\"_blank\">View raw code<\/a><\/p>\n<h2>Client&nbsp;Circuit<\/h2>\n<p>Follow this circuit to build&nbsp;your ESP client and if you are using the ESP-12, you can view the schematics <a href=\"https:\/\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/esp-12-test-Sketch_bb-1.png\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>:<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/weatherStation-201-Sketch_bb.png?quality=100&#038;strip=all&#038;ssl=1\" rel=\"attachment wp-att-15619\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-15619\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/weatherStation-201-Sketch_bb.png?resize=776%2C491&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"weatherStation-201 Sketch_bb\" width=\"776\" height=\"491\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/weatherStation-201-Sketch_bb.png?w=1755&amp;quality=100&amp;strip=all&amp;ssl=1 1755w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/weatherStation-201-Sketch_bb.png?resize=300%2C190&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/weatherStation-201-Sketch_bb.png?resize=768%2C486&amp;quality=100&amp;strip=all&amp;ssl=1 768w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/weatherStation-201-Sketch_bb.png?resize=1024%2C648&amp;quality=100&amp;strip=all&amp;ssl=1 1024w\" sizes=\"(max-width: 776px) 100vw, 776px\" \/><\/a><\/p>\n<p>The right switch connected to IO05 is used to simulate wind speed. The program currently doesn&#8217;t&nbsp;give a real-time wind speed, but a last 5 seconds wind speed average.<\/p>\n<p>So it doesn&#8217;t mater how fast you press right switch. If you push right switch 5 times in the 5 seconds sampling period&#8230; that translates into&nbsp;once per second average giving 1.492 MPH or 2.4 KMH (at this point we&#8217;re&nbsp;using NodeMCU&nbsp;integer version, so you&#8217;ll get 1492 MPH and 24 KMH. You&#8217;ll have to divide in the spreadsheet by 100 and 10 respectively).<\/p>\n<h2>Writing Your Server Script<\/h2>\n<p>Upload the following script to your ESP and name it <em>init.lua<\/em>.<\/p>\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">-- Rui Santos - ESP8266 Server\n-- Modified by Yves Arbour to ennable print string to go directly to an Excel sheet with Things Gateway\n\nprint(&quot;ESP8266 Server&quot;)\nwifi.setmode(wifi.STATIONAP);\nwifi.ap.config({ssid=&quot;test&quot;,pwd=&quot;12345678&quot;});\nprint(&quot;Server IP Address:&quot;,wifi.ap.getip())\n \nsv = net.createServer(net.TCP)\nsv:listen(80, function(conn)\n    conn:on(&quot;receive&quot;, function(conn, receivedData)\n      --print(&quot;Received Data&quot;..receivedData)\n        print(receivedData)-- string &quot;Received Data&quot; removed...\n        --Things Gateway ignores strings that do not start with proper command...\n        --XLS in this case for Excel sheet        \n    end)\n    conn:on(&quot;sent&quot;, function(conn)\n      collectgarbage()\n    end)\nend)\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/Yves-Arbour\/init_server.lua\" target=\"_blank\">View raw code<\/a><\/p>\n<h2>Final Server&nbsp;Circuit<\/h2>\n<p>Follow this circuit to make your ESP server&nbsp;and if you are using the ESP-12, you can view the schematics <a href=\"https:\/\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/WirelessWeatherStationServer_12_bb.png\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>.<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/WirelessWeatherStationServer_201_bb-1.png?quality=100&#038;strip=all&#038;ssl=1\" rel=\"attachment wp-att-15636\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-15636\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/WirelessWeatherStationServer_201_bb-1.png?resize=416%2C618&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"WirelessWeatherStationServer_201_bb\" width=\"416\" height=\"618\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/WirelessWeatherStationServer_201_bb-1.png?w=626&amp;quality=100&amp;strip=all&amp;ssl=1 626w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/WirelessWeatherStationServer_201_bb-1.png?resize=202%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 202w\" sizes=\"(max-width: 416px) 100vw, 416px\" \/><\/a>We&#8217;ve created a custom PCB for the ESP-201. Here&#8217;s the details:<\/p>\n<ul>\n<li>Yellow wire: can either connect GPIO 0 to GND to flash NodeMCU&nbsp;firmware or to VCC&nbsp;to save scripts to ESP<\/li>\n<li>GPIO15 is hard wired to GND<\/li>\n<li>Reset button and 10K Ohm pull-up resistor to RST pin (in order to reset the board the RST pin has to be pulled down and then has to go back up)<\/li>\n<\/ul>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-15673\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/ESP8266-with-PCBs.jpg?resize=660%2C280&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP8266 with PCBs\" width=\"660\" height=\"280\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/ESP8266-with-PCBs.jpg?w=660&amp;quality=100&amp;strip=all&amp;ssl=1 660w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/ESP8266-with-PCBs.jpg?resize=300%2C127&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 660px) 100vw, 660px\" \/><\/p>\n<h3>Putting Everything Together<\/h3>\n<p>Power both your ESPs and make sure the ESP server still has the serial communication established with your computer, because that&#8217;s how you are going to post the data to your Excel spreadsheet.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-15626 \" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/PC140029.jpg?resize=560%2C420&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"\" width=\"560\" height=\"420\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/PC140029.jpg?w=640&amp;quality=100&amp;strip=all&amp;ssl=1 640w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/PC140029.jpg?resize=300%2C225&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 560px) 100vw, 560px\" \/><\/p>\n<h2>Downloading and Installing Things Gateway<\/h2>\n<p>For this project&nbsp;we are&nbsp;going to use Things Gateway a software by Roberto Valgolio to write data on an Excel spreadsheet and display a self updating real time charts.<\/p>\n<p>Things Gateway is a PC application that connects a microcontroller&nbsp;and makes it able to:<\/p>\n<ul>\n<li>Get data from Excel files<\/li>\n<li>Write Excel files<\/li>\n<li>Write CSV log files<\/li>\n<li>Send emails (when certain conditions are met)<\/li>\n<li>Show values and charts (charts are Excel independent)<\/li>\n<\/ul>\n<p>Things Gateway can also connect a GPS and show on the screen:<\/p>\n<ul>\n<li>Speed, heading, altitude and other navigation info<\/li>\n<li>Real-time tracks in Google Maps<\/li>\n<\/ul>\n<p>Go to the <a href=\"http:\/\/www.robertovalgolio.com\/sistemi-programmi\/ecosystemofthings\" target=\"_blank\" rel=\"noopener noreferrer\">Things Gateway<\/a> website, download the program and install it. This project was tested with the&nbsp;Beta4 version.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-15642\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/ThingsGatewaydownload.jpg?resize=367%2C151&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ThingsGatewaydownload\" width=\"367\" height=\"151\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/ThingsGatewaydownload.jpg?w=367&amp;quality=100&amp;strip=all&amp;ssl=1 367w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/ThingsGatewaydownload.jpg?resize=300%2C123&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 367px) 100vw, 367px\" \/><\/p>\n<h2>Launching Your Things Gateway Application<\/h2>\n<p>To launch the Things Gateway application is very straight forward. Go to <em>Your PC &gt; Documents &gt; ThingsGateway<\/em> and open the application.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-15644\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/things-gateway-app.jpg?resize=530%2C211&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"things gateway app\" width=\"530\" height=\"211\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/things-gateway-app.jpg?w=899&amp;quality=100&amp;strip=all&amp;ssl=1 899w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/things-gateway-app.jpg?resize=300%2C119&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/things-gateway-app.jpg?resize=768%2C306&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 530px) 100vw, 530px\" \/><\/p>\n<p>Then&nbsp;follow these instructions:<\/p>\n<ol>\n<li>Go to the <em>Config&nbsp;<\/em>tab<\/li>\n<li>Select the <em>Serial COM Port<\/em> of your ESP8266 Server<\/li>\n<li>Set the Serial port <em>Speed<\/em> to <em>9600<\/em><\/li>\n<\/ol>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-15629\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/things-config.png?resize=361%2C384&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"things config\" width=\"361\" height=\"384\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/things-config.png?w=784&amp;quality=100&amp;strip=all&amp;ssl=1 784w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/things-config.png?resize=282%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 282w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/things-config.png?resize=768%2C818&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 361px) 100vw, 361px\" \/><\/p>\n<h2>Demonstration<\/h2>\n<p>Open the&nbsp;<em>RealTime<\/em> tab and select <em>From Serial to Excel<\/em>.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-15643\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/ThingsGateway-1.jpg?resize=460%2C492&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ThingsGateway\" width=\"460\" height=\"492\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/ThingsGateway-1.jpg?w=787&amp;quality=100&amp;strip=all&amp;ssl=1 787w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/ThingsGateway-1.jpg?resize=281%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 281w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/ThingsGateway-1.jpg?resize=768%2C821&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 460px) 100vw, 460px\" \/><\/p>\n<p>An Excel spreadsheet should appear and your data should start appearing there every few seconds!<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-15669\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/ThingsGateway-excel.jpg?resize=488%2C446&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ThingsGateway excel\" width=\"488\" height=\"446\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/ThingsGateway-excel.jpg?w=488&amp;quality=100&amp;strip=all&amp;ssl=1 488w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/ThingsGateway-excel.jpg?resize=300%2C274&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 488px) 100vw, 488px\" \/><\/p>\n<p>Your data is being stored in the example Excel spreadsheet in that folder:<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-15645\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/things-gateway-example.jpg?resize=775%2C310&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"things gateway example\" width=\"775\" height=\"310\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/things-gateway-example.jpg?w=890&amp;quality=100&amp;strip=all&amp;ssl=1 890w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/things-gateway-example.jpg?resize=300%2C120&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/things-gateway-example.jpg?resize=768%2C307&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 775px) 100vw, 775px\" \/><\/p>\n<h2>Future&nbsp;Improvements<\/h2>\n<p>In this tutorial we established a basic system to send data wirelessly to an Excel spreadsheet using 2 ESP8266 and Things Gateway software.<\/p>\n<p>With this example, you&#8217;ll be able to explore more features from Things Gateway like:<\/p>\n<ul>\n<li>Real-time self updating graph (not Excel dependent)<\/li>\n<li>Data logging in .csv files<\/li>\n<li>Auto email sending when custom conditions are met (strong wind above so many kmh, temp to low\u2026 warning of heating system failure or freezer not cold enough etc)<\/li>\n<li>Data logging in stream.txt that can be replayed at speed 0.1, 0.5, 1, 5, 10, 60 or 3600 times faster<\/li>\n<li>GPS track can also be streamed on Google map at actual speed or 0.1, 0.5, 5, 10, 60 or 3600 times faster<\/li>\n<\/ul>\n<p>Further development could also include:<\/p>\n<ul>\n<li>Other sensors like bmp180 barometric pressure sensor<\/li>\n<li>Light sensors<\/li>\n<li>Humidity sensor<\/li>\n<li>Any other digital or analog sensor with the use of multiplexing<\/li>\n<\/ul>\n<p>Please note that Things Gateway was designed to use with Arduino board, but as long as you send the proper string via serial, it can be used with any board.<\/p>\n<p><strong>I hope you found this guide helpful and huge thanks to&nbsp;Yves Arbour that created this project!<\/strong><\/p>\n<p>Do you have any questions or feedback?&nbsp;Leave a comment down below.<\/p>\n<p>Thanks for reading. If you like this post probably you might like my next ones, so please support me by subscribing my <a href=\"https:\/\/randomnerdtutorials.com\/download\" target=\"_blank\" rel=\"noopener noreferrer\">blog<\/a> and my&nbsp;Facebook Page.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this project we are going to establish a wireless communication between two ESPs and send&nbsp;data from three&nbsp;sensors to an Excel spreadsheet. This tutorial shows a&nbsp;wireless weather station with data &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"ESP8266 &#8211; Wireless Weather Station with Data Logging to Excel\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/esp8266-wireless-weather-station-with-data-logging-to-excel\/#more-15496\" aria-label=\"Read more about ESP8266 &#8211; Wireless Weather Station with Data Logging to Excel\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":1,"featured_media":15640,"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":true,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[249,214,265,300,240,220,250,264,218],"tags":[],"class_list":["post-15496","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-adc-analog","category-esp8266","category-esp8266-project","category-0-esp8266","category-esp8266-projects","category-http-client","category-nodemcu","category-project","category-web-server"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2015\/12\/Wireless-Weather-Station-with-Data-Logging-to-Excel-thumb.jpg?fit=1288%2C864&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/15496","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=15496"}],"version-history":[{"count":0,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/15496\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/15640"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=15496"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=15496"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=15496"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}