<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>lua &#8211; Squix &#8211; TechBlog</title>
	<atom:link href="https://blog.squix.org/tag/lua/feed" rel="self" type="application/rss+xml" />
	<link>https://blog.squix.org</link>
	<description></description>
	<lastBuildDate>Thu, 09 Dec 2021 08:14:01 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.5.8</generator>
<site xmlns="com-wordpress:feed-additions:1">121913304</site>	<item>
		<title>ESP8266: Internet connected baby nightlight for less than $10</title>
		<link>https://blog.squix.org/2014/12/esp8266-internet-connected-baby.html</link>
					<comments>https://blog.squix.org/2014/12/esp8266-internet-connected-baby.html#comments</comments>
		
		<dc:creator><![CDATA[Daniel Eichhorn]]></dc:creator>
		<pubDate>Sun, 28 Dec 2014 11:39:00 +0000</pubDate>
				<category><![CDATA[Common]]></category>
		<category><![CDATA[ESP8266]]></category>
		<category><![CDATA[esplorer]]></category>
		<category><![CDATA[lua]]></category>
		<category><![CDATA[nightlight]]></category>
		<category><![CDATA[nodemcu]]></category>
		<category><![CDATA[time client]]></category>
		<guid isPermaLink="false">http://blog.squix.org/2014/12/28/esp8266-internet-connected-baby/</guid>

					<description><![CDATA[A while ago a wanted to build one of those nightlights for my daughter that tell her when to sleep and when to call for the parents: an orange light behind a sun depicts the day, a blue light behind a moon the night. My ... <p><a class="read-more btn btn-secondary" href="https://blog.squix.org/2014/12/esp8266-internet-connected-baby.html">Read More</a></p>]]></description>
										<content:encoded><![CDATA[<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="separator" style="clear: both; text-align: left;">
<a href="https://i0.wp.com/blog.squix.org/wp-content/uploads/2014/12/IMG_4772-1024x768.jpg?ssl=1" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img data-recalc-dims="1" fetchpriority="high" decoding="async" border="0" src="https://i0.wp.com/blog.squix.org/wp-content/uploads/2014/12/IMG_4772.jpg?resize=320%2C240&#038;ssl=1" height="240" width="320" /></a></div>
<p>
A while ago a wanted to build one of those nightlights for my daughter that tell her when to sleep and when to call for the parents: an orange light behind a sun depicts the day, a blue light behind a moon the night. My first attempt was based on a Spark Core which is a bit pricy (~$40) to just connect to the internet to synchronise the time.<br />
Playing with the ESP8266 I needed an actual project to use it and the nightlight came in handy. It uses both GPIO pins available on the ESP8266-ESP01 and calls google.com to synchronise the time every 30 minutes as soon as the device is connected to the access point. I currently still need an Arduino but just as power source and debugging tool. So the actual components are:</p>
<ul style="text-align: left;">
<li>plastic box (from food delivery)</li>
<li>black paper as mask</li>
<li>sun and moon downloaded and printed from the internet</li>
<li>cardboard from a cereal box to shield the LEDs</li>
<li>2 LEDs (orange and blue)</li>
<li>a mini bread board</li>
<li>an ESP8266</li>
<li>2 resistors</li>
<li>some jumper wires</li>
</ul>
<p><a href="https://i0.wp.com/blog.squix.org/wp-content/uploads/2014/12/IMG_5207-1024x768.jpg?ssl=1" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img data-recalc-dims="1" decoding="async" border="0" src="https://i0.wp.com/blog.squix.org/wp-content/uploads/2014/12/IMG_5207.jpg?resize=320%2C240&#038;ssl=1" height="240" width="320" /></a></p>
<h3 style="text-align: left;">
Prepare the ESP8266</h3>
<div>
First you need to put the LUA firmware from nodemcu on the ESP8266. I described <a href="https://blog.squix.org/2014/12/esp8266-flashing-lua-firmware-and.html">in this post</a>&nbsp;how it is done. Once this is done you can use the <a href="http://esp8266.ru/esplorer/">Esplorer</a>&nbsp;to transfer lua files to the ESP8266.</div>
<div>
</div>
<h3 style="text-align: left;">
Check out the code and adapt it</h3>
<div>
Checkout the two lua files from <a href="https://github.com/squix78/ESP8266-lua-nightlight">here</a>&nbsp;and adapt them to your needs. Especially your access point and credentials need to be set in the init.lua file. If you&#8217;re not living in the GMT+1 timezone you&#8217;ll also need to adapt your offset in the nightlight.lua script. In the current version the day/night phases can only be set within the code, but this might change in the future. There is a lightweight webserver available for the lua firmware which might allow setting the time through a web browser.</div>
<div>
</div>
<h3 style="text-align: left;">
Transfer the files to the ESP8266</h3>
<div>
The current version of the firmware crashes and restarts the unit if you try to call the dofile function for a non-existing file. Since the init.lua scripts calls the nightlight.lua script transfer them in the appropriate order (first nightlight, then init). Note: I had some cases where the module would connect to the AP and receive an IP but would further fail to call the google server to get the time. This only happened after clean updates of the firmware and disappeared after a short while.</div>
<div>
</div>
<h3 style="text-align: left;">
Sources</h3>
<div>
<ul style="text-align: left;">
<li><a href="https://github.com/nodemcu/nodemcu-firmware">Lua firmware</a></li>
<li><a href="http://esp8266.ru/esplorer/">Esplorer (ESP8266 IDE)</a></li>
<li><a href="http://www.esp8266.com/viewtopic.php?f=19&amp;t=809">ESP8266 example for google time client</a>&nbsp;(thanks to GeoNomad)</li>
</ul>
</div>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.squix.org/2014/12/esp8266-internet-connected-baby.html/feed</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">73</post-id>	</item>
		<item>
		<title>ESP8266: flashing the lua firmware and running some code</title>
		<link>https://blog.squix.org/2014/12/esp8266-flashing-lua-firmware-and.html</link>
					<comments>https://blog.squix.org/2014/12/esp8266-flashing-lua-firmware-and.html#respond</comments>
		
		<dc:creator><![CDATA[Daniel Eichhorn]]></dc:creator>
		<pubDate>Sun, 07 Dec 2014 12:22:00 +0000</pubDate>
				<category><![CDATA[Common]]></category>
		<category><![CDATA[ESP8266]]></category>
		<category><![CDATA[esptool]]></category>
		<category><![CDATA[firmware]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[lua]]></category>
		<guid isPermaLink="false">http://blog.squix.org/2014/12/07/esp8266-flashing-lua-firmware-and/</guid>

					<description><![CDATA[After you setup your ESP8266 module as described here you can go on and write Arduino code that talks to the ESP8266 or even flash new firmware directly on the device. Someone has put together a firmware which allows you to send lua code to the ... <p><a class="read-more btn btn-secondary" href="https://blog.squix.org/2014/12/esp8266-flashing-lua-firmware-and.html">Read More</a></p>]]></description>
										<content:encoded><![CDATA[<div dir="ltr" style="text-align: left;">After you setup your ESP8266 module as described <a href="https://blog.squix.org/2014/12/esp8266-using-seeeduino-to-talk-to.html">here</a> you can go on and write Arduino code that talks to the ESP8266 or even flash new firmware directly on the device. Someone has put together a firmware which allows you to send <a href="http://www.lua.org/start.html">lua</a> code to the module and run it through the serial console. This is a nice way to get started with programming the module directly instead of using an Arduino intermediary. This post describes how you can flash a new firmware on the module.</p>
<h3 style="text-align: left;">Getting the wiring right</h3>
<div class="separator" style="clear: both; text-align: center;"><a style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;" href="https://i0.wp.com/blog.squix.org/wp-content/uploads/2014/12/ESP8266_pinout.png?ssl=1"><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/blog.squix.org/wp-content/uploads/2014/12/ESP8266_pinout.png?w=730&#038;ssl=1" border="0" /></a></div>
<div>Make sure you already have the wires setup as described in the previous <a href="https://blog.squix.org/2014/12/esp8266-using-seeeduino-to-talk-to.html">post</a>. Now the module needs to be put in a ready-to-flash-firmware state.</div>
<div>
<ol style="text-align: left;">
<li>Add a wire between GPIO0 pin and the Ground pin (GND)</li>
<li>Now reset the module be quickly connecting the RST pin to the GND pin (in my case the blue LED flashes quickly)</li>
</ol>
</div>
<h3 style="text-align: left;">Getting the flash tool ready</h3>
<div>In order to write new firmware to the module you&#8217;ll need to use a tool, the serial console isn&#8217;t helpful in this case.</div>
<div>
<ol style="text-align: left;">
<li>Download the esptool.py from <a href="https://github.com/themadinventor/esptool">here</a>.</li>
<li>Make it executable and run it with ./esptool.py &#8211;help. On my Mac OS X machine I got an error, that the serial library is nowhere to be found. Because of this I had to
<ol>
<li>
<div class="p1">
<pre>brew install python</pre>
</div>
</li>
<li>
<pre>pip install pyserial
</pre>
</li>
<li>make sure that you will use the python installed by brew</li>
</ol>
</li>
<li>Download the lua firmware from <a href="https://github.com/nodemcu/nodemcu-firmware/tree/master/0.9.2/512k-flash">here</a> (the nodemcu_512k.bin file)</li>
<li>Find out the port your FTDI controller or your Seeeduino is connected to. In my case I used the Arduino IDE to find the port and make sure no console is currently connected to the Arduino</li>
<li>Replace tty.usbserial-A901LKQM with your actual com-port
<pre>esptool.py --port /dev/tty.usbserial-A901LKQM write_flash 0x000000 nodemcu_512k.bin</pre>
</li>
<li>Remove the connection between GPIO0 and GND</li>
<li>Reset the module again by connecting RST quickly to GND</li>
</ol>
</div>
<div>
<h3 style="text-align: left;">Running Lua examples on the module</h3>
</div>
<div>
<ol style="text-align: left;">
<li>Open a serial console and connect it with your Arduino or FTDI controller. I opened the console in the Arduino IDE and set the baud rate to <b>9600</b></li>
<li>Run enter this Lua code into the console (you may have to enter it line by line):
<pre>print(wifi.sta.getip())
--0.0.0.0
wifi.setmode(wifi.STATION)
wifi.sta.config("SSID","password")
print(wifi.sta.getip())
--192.168.18.110
</pre>
</li>
<li>Run more examples from <a href="https://github.com/nodemcu/nodemcu-firmware#start-play">here</a></li>
</ol>
<h3 style="text-align: left;">Update 2015-01-04</h3>
</div>
<div>I had some problems with the stability of the ESP8266 chip. It would reboot randomly and quite soon I suspected the power supply. After I switched from the Seeeduino 3.3V power to this power supply, those problems went away:</div>
<div><a href="https://www.banggood.com/MB102-2-Channel-3_3V-5V-Breadboard-Power-Supply-Module-White-Breadboard-Dedicated-Power-Module-MB-102-Solderless-Bread-Board-p-1524894.html?p=0P21061109440201501M" target="_parent" rel="noopener"><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/i00.i.aliimg.com/wsphoto/v0/1718017194_1/Special-promotions-1lot-MB102-Breadboard-Power-Supply-Module-3-3V-5V-830-Tie-Point-Breadboard-Excellent.jpg_220x220.jpg?resize=283%2C320" width="283" height="320" />Breadboard Power Supply Module 3.3V/5V</a></div>
<h3 style="text-align: left;">Links</h3>
<div>
<ul style="text-align: left;">
<li><a href="http://playground.boxtec.ch/doku.php/wireless/esp8266">How to use the esptool to write firmware</a></li>
<li><a href="https://github.com/themadinventor/esptool">esptool</a> for flashing firmware</li>
<li><a href="https://github.com/nodemcu/nodemcu-firmware#start-play">Lua Examples</a></li>
<li><a href="https://github.com/nodemcu/nodemcu-firmware/wiki/nodemcu_api_en">Available commands</a></li>
</ul>
</div>
</div>
<div>Advertisement:</div>
<div>
<p><a href="http://s.click.aliexpress.com/e/VR72vzrbI" target="_parent" rel="noopener"><img data-recalc-dims="1" decoding="async" src="https://i0.wp.com/i00.i.aliimg.com/wsphoto/v0/2030821422/-font-b-ESP8266-b-font-font-b-Serial-b-font-font-b-Port-b-font.jpg_220x220.jpg?w=730" />ESP8266 Serial Port WIFI</a></p>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.squix.org/2014/12/esp8266-flashing-lua-firmware-and.html/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">75</post-id>	</item>
	</channel>
</rss>
