<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>TvE&#39;s Blog </title>
		<link>https://blog.voneicken.com/</link>
		<generator>Hugo -- gohugo.io</generator>
		<language>en-us</language>
		<author>Thorsten von Eicken</author>
		<rights>Copyright (c) 2019</rights>
		<updated>2018-12-16 00:00:00 &#43;0000 UTC</updated>
		
		<item>
			<title>MediaTek and RDA WiFi Microcontrollers</title>
			<link>https://blog.voneicken.com/2018/lp-wifi-other/</link>
			<pubDate>Sun, 16 Dec 2018 00:00:00 UTC</pubDate>
			<author>Thorsten von Eicken</author>
			<guid>https://blog.voneicken.com/2018/lp-wifi-other/</guid>
			<description>&lt;p&gt;Unisoc&amp;rsquo;s RDA5981 and MediaTek&amp;rsquo;s MT7697 microcontrollers (as well as variants of these two) also
incorporate a WiFi radio on the chip and target low-power embeded IoT applications.
&lt;/p&gt;

&lt;h3 id=&#34;unisoc-rda5981&#34;&gt;Unisoc RDA5981&lt;/h3&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/RDA5981-HLK-M50.jpg# fr w-30pct ml-3&#34; alt=&#34;Hi-Link HLK-M50 module with RDA5981&#34; /&gt;
The RDA5981 incorporates an ARM Cortex-M4 core with 352KB RAM and 1MB flash in one chip.
The HLK-M50 is one low-cost module that incorporates the chip and I&amp;rsquo;m expecting one in the mail
soon. In the meantime I&amp;rsquo;ve taken a closer look at the
&lt;a href=&#34;https://github.com/RDA5981/RDA5981/blob/master/Datasheet/RDA5981A%20DataSheet%20V1.5.pdf&#34;&gt;datasheet&lt;/a&gt;
to see what I might expect.&lt;/p&gt;

&lt;p&gt;One interesting feature of the chip is that its recommended supply voltage range is from 3.3V to
4.2V, which means that one can run it straight off a LiPo without regulator!
A first glipse at what to expect in terms of power consumption is provided by the following table
from the datasheet:&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/rda5981-power-consumption.png# w-60pct ml-3 cb
nocaption&#34; alt=&#34;RDA5981 power consumption&#34; /&gt;&lt;/p&gt;

&lt;p&gt;The deep-sleep, RX and TX mode power levels look very comparable to the other microcontrollers
examined so far. I don&amp;rsquo;t know what the &amp;ldquo;WIFI OFF&amp;rdquo; refers to but I wonder whether it&amp;rsquo;s really
supposed to read 22 &lt;em&gt;milliamperes&lt;/em&gt; with the CPU running and the RF section being off.&lt;/p&gt;

&lt;p&gt;Another module which uses the RDA5891 is MxChip&amp;rsquo;s EMW3080 and &lt;a href=&#34;https://adelectronics.ru/2018/03/04/%D0%BE%D0%B1%D0%B7%D0%BE%D1%80-%D0%BC%D0%BE%D0%B4%D1%83%D0%BB%D1%8F-rda5981x1/&#34;&gt;A_D
Electronics&lt;/a&gt;
uncovered a more interesting power consumption table in its docs:&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/rda5981-emw3080-power-consumption.png# w-80pct ml-3
center nocaption&#34; alt=&#34;EMW3080 power consumption&#34; /&gt;&lt;/p&gt;

&lt;p&gt;Is this table the power consumption while Wifi is connected is listed at 47mA, which certainly does
not compete with the Espressif microcontrollers or the RTL8710.
But as seen with the other microcontrollers, until the thing is running some test apps on the bench
it&amp;rsquo;s impossible to tell what the actual power consumption will be.&lt;/p&gt;

&lt;h3 id=&#34;mediatek-mt7697&#34;&gt;MediaTek MT7697&lt;/h3&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/MT7697-LinkIt.jpg# fr w-30pct ml-3&#34; alt=&#34;LinkIt 7697 board with MT7697&#34; /&gt;
The MT7697 is a little different from all the other microcontrollers examined so far in that it
includes a separate processor for the Wifi portion. The application processor is an ARM Cortex-M4
with on-board RAM and a Flash interface. The Wifi processor is unspecified but some of the diagrams
show that it&amp;rsquo;s also an ARM processor. While this dual-core set-up might look similar to the ESP32 it
differs in that the two microprocessors are completely separated and the Wifi processor is not
accessible to application code at all.&lt;/p&gt;

&lt;p&gt;One of the benefits of the dual-processor architecture is that the application processor can be
completely shut down when sleeping while keeping the Wifi processor active to maintain a connection
to the access point. The downside is that there&amp;rsquo;s more to power when both are on.&lt;/p&gt;

&lt;p&gt;The most interesting document I&amp;rsquo;ve found so far is the
&lt;a href=&#34;https://s3-ap-southeast-1.amazonaws.com/mediatek-labs-imgs/downloads/73f2af6bc5e82c6be0d533fdfedb4527.pdf&#34;&gt;power mode developer&amp;rsquo;s guide&lt;/a&gt;
which shows a 9.6mA sleep mode using FreeRTOS tickless idle and a 1.1mA &amp;ldquo;legacy sleep&amp;rdquo; mode:&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/mt7697-legacy-power-chart.png# w-70pct center nocaption&#34; alt=&#34;MT7697 Legacy sleep chart&#34; /&gt;&lt;/p&gt;

&lt;p&gt;Another interesting &lt;a href=&#34;https://docs.labs.mediatek.com/resource/mt7687-mt7697/en/tutorials/low-power-mode-and-power-measurement&#34;&gt;document on low power
modes&lt;/a&gt;
has the following table:&lt;/p&gt;

&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Scenario&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;Typical Results [mA]&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;

&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Legacy Sleep&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0.667&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;WiFi Radio off (tickless)&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;10.79&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;WiFi Radio off (legacy sleep)&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0.97&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;WiFi Connected (DTIM 1, tickless)&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;14.18&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;WiFi Connected (DTIM 1, legacy cleep tickless)&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;4.64&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;WiFi Connected (DTIM10, legacy sleep tickless)&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;2.07&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;That looks right in the ballpark of the esp32 to me, but only experimentation will tell for sure&amp;hellip;&lt;/p&gt;

&lt;p&gt;Stay tuned for the next post&amp;hellip;&lt;/p&gt;</description>
		</item>
		
		<item>
			<title>RTL8710 Deep-Sleep with Periodic Wake-up</title>
			<link>https://blog.voneicken.com/2018/lp-wifi-rtl8710-deep/</link>
			<pubDate>Sat, 15 Dec 2018 00:00:00 UTC</pubDate>
			<author>Thorsten von Eicken</author>
			<guid>https://blog.voneicken.com/2018/lp-wifi-rtl8710-deep/</guid>
			<description>

&lt;p&gt;Is the RTL8710 faster at waking up and connecting to a Wifi network than the Espressif
microcontrollers?&lt;/p&gt;

&lt;h3 id=&#34;open-network&#34;&gt;Open Network&lt;/h3&gt;

&lt;p&gt;The sketch used for this test is very simple: connect to the open Wifi network, connect to a local server
using TCP and send a short message, then go back to sleep.&lt;/p&gt;

&lt;p&gt;Unfortunately, the way LwIP is compiled into the firmware exposes the same local port issue
as in the esp8266, e.g., LwIP always uses the same port for the first connection and this causes
connection resets and additional delays.
I had to modify the Arduino WiFiClient library to add a hack so it explicitly binds the socket to a
pseudo-random local port.
After this fix the result is the following scope capture:&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/rtl8710-deep-sleep-open.png#&#34; alt=&#34;RTL8710 Deep-Sleep Scope Capture using an Open Network&#34; /&gt;&lt;/p&gt;

&lt;p&gt;The wake cycle starts with a 270ms initialization phase before &lt;code&gt;setup()&lt;/code&gt; is called. Then, after
another 250-300ms of RF init or calibration the rtl8710
spends 1 second probing for the access point. There are 11 spikes during this time which matches the
11 Wifi channels in the US, so evidently it spends about 90ms per channel. Then comes a 300ms dead period
where nothing happens, not unlike in the Espressif microcontrollers, and finally the rtl8710
associates and gets an IP address via DHCP all in about 100ms.&lt;/p&gt;

&lt;p&gt;At the end of the DHCP exchange the rtl8710 sends a gratuitous ARP to detect whether anyone else has
that same IP address. This repeats twice over about 500ms before the firmware reports to the sketch
that wifi is connected. The sketch then opens the TCP connection, which results in an ARP request
for the destination server followed by the TCP connection in almost no time.&lt;/p&gt;

&lt;p&gt;Overall, the performance is roughly in-line with the equivalent unoptimized sketch on the esp8266.
I then tried to perform the same optimizations but the Arduino libraries provided with the
rtl8710 allow neither the BSSID nor the channel number to be specified. It turns out, however, that
the underlying Wifi firmware does allow the BSSID to be set (but not the channel),
so I hacked in calls to do that.
Sadly I saw absolutely no difference in the probing.
The end result is that the wake-cycle on an open network takes about ten times as long as on the
esp8266 or esp32.&lt;/p&gt;

&lt;h3 id=&#34;secure-network&#34;&gt;Secure Network&lt;/h3&gt;

&lt;p&gt;The next scope capture shows the same sketch with a secure network.
It uses the same simple TCP connection instead of the MQTT/TLS pub/sub used in the esp8266 and esp32
sketches because the TLS library does not support any of the PSK ciphers.&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/rtl8710-deep-sleep-secure.png#&#34; alt=&#34;RTL8710 Deep-Sleep Scope Capture using a Secure Network&#34; /&gt;&lt;/p&gt;

&lt;p&gt;Here the horizontal scale had to be changed from 200ms/div to 500ms/div. The probing on the left
still takes about 1 second and once the rtl8710 decides to associate it gets through the remainder
of the sketch in about 600ms like in the open network case. But in the middle there is a 3 second
pause where nothing seems to happen, very similar to the delay in the esp8266 and esp32, but longer.&lt;/p&gt;

&lt;p&gt;The bottom line here is that the wake-cycle takes a little over 5 seconds, which is more than twice
as long as for the esp8266 and esp32.&lt;/p&gt;

&lt;h3 id=&#34;conclusions&#34;&gt;Conclusions&lt;/h3&gt;

&lt;p&gt;It is pretty clear that for low-power Wifi the RTL8710 cannot compete with the esp32: it&amp;rsquo;s &amp;ldquo;leisure
power sleep&amp;rdquo; uses much more power than the esp32&amp;rsquo;s automatic light-sleep and the deep-sleep with
periodic wake-up it takes much longer to associate with an AP. It also cannot compete with the esp8266
in deep-sleep mode but is roughly comparable in light-sleep mode where both have bugs/mis-features
that keep them awake half the time when they should be sleeping.&lt;/p&gt;

&lt;p&gt;I did revisit the summary chart from the esp8266 vs. esp32 comparison and added the rtl8710 using
bold lines. The actual leisure sleep performance assumes a &lt;sup&gt;50&lt;/sup&gt;&amp;frasl;&lt;sub&gt;50&lt;/sub&gt; split between light-sleep
and periods where it stays powered-up due to the &amp;ldquo;N packets in 2 seconds&amp;rdquo; stay-awake algorithm in
the Wifi firmware. I&amp;rsquo;m not sure what the correct split really is as I&amp;rsquo;ve seen some variability
depending on the number of background packets, the loop iteration interval, and other factors that I
don&amp;rsquo;t understand.&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/ESP8266 vs. ESP32 vs. RTL8710 in Light-Sleep and Deep-Sleep.png# w-100pct nocaption&#34; alt=&#34;RTL8710 added to the esp8266 vs esp32 comparison&#34; /&gt;&lt;/p&gt;

&lt;p&gt;I did model what would happen if RealTek fixed the leisure sleep issue and the performance would
actually lie somewhere between the esp8266 and the esp32, which would be pretty sweet. The
deep-sleep with periodic wake-up performance is worse than for the esp32 and esp8266 due to the long
time it takes to connect with the access point.&lt;/p&gt;

&lt;p&gt;The &lt;a href=&#34;https://blog.voneicken.com/2018/lp-wifi-other&#34;&gt;next post&lt;/a&gt; which will take a brief look at some other low-power Wifi microcontrollers.&lt;/p&gt;
</description>
		</item>
		
		<item>
			<title>RTL8710 First Impressions</title>
			<link>https://blog.voneicken.com/2018/lp-wifi-rtl8710-lps/</link>
			<pubDate>Thu, 13 Dec 2018 00:00:00 UTC</pubDate>
			<author>Thorsten von Eicken</author>
			<guid>https://blog.voneicken.com/2018/lp-wifi-rtl8710-lps/</guid>
			<description>

&lt;p&gt;The RealTek RTL8710 is pitched directly at the esp8266 and it even comes in an RTL-00 module that has
the same pinout as an esp-12f module. How does it fare at low-power Wifi?&lt;/p&gt;

&lt;h3 id=&#34;experimental-set-up&#34;&gt;Experimental set-up&lt;/h3&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/rtlduino.jpg# fr w-50pct ml-3&#34; alt=&#34;RTL-00 Module with an RTL8710AF ARM Cortex-M3&#34; /&gt;
&lt;em&gt;RTLDuino with an RTL-00 Module which houses the RTL8710AF ARM Cortex-M3 Microcontroller.
The AMS1117 regulator it comes with is replaced by an AP7361C-33ER to enable powering with a LiPo.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;To test the RTL8710 I purchased a NodeMCU-like development board shown in the photo on the right.
Like many similar esp8266 and esp32 boards it is ready to stick into a breadboard, has
a USB-serial interface, and a voltage regulator.&lt;/p&gt;

&lt;p&gt;Unfortunately the RTLDuino comes with the dreaded AMS1777 &amp;ldquo;high-dropout regulator&amp;rdquo; that is unusable on a LiPo,
which I need to make accurate power consumption measurements. Fortunately after spending an hour
looking at the datasheets of all SOT223 LDOs I could find, I hit paydirt: the Diodes Incorporated
AP7361C-33ER is pin-compatible with the AMS1777, is a true LDO (360mV @1A typ), &lt;em&gt;and&lt;/em&gt; is stocked by
Digikey. (If you order one be sure to get the &amp;ldquo;ER&amp;rdquo; version and not the &amp;ldquo;E&amp;rdquo;, which is not pin
compatible.) I used some hot air to swap the regulators out and so far it&amp;rsquo;s working like a charm!&lt;/p&gt;

&lt;p&gt;Another problem with the RTLduino is that it&amp;rsquo;s not self-sufficient: the USB port is a bit of an
illusion because one can&amp;rsquo;t program the thing through it. The processor in the RTL8710 is an ARM
Cortex-M3 and does not have any serial programming capability. Instead one has to resort to a
CMSIS-DAP, ST-Link, J-Link, or some JTAG programmer. I ended up using a bit of a hacked up set-up
with OpenOCD and an ST-Link-V2.&lt;/p&gt;

&lt;h3 id=&#34;specifications&#34;&gt;Specifications&lt;/h3&gt;

&lt;p&gt;RealTek seems to have made an effort to make the RTL8710 (and the very similar RTL8795) accessible, but
between the language barrier and the ever-present secrecy the truth is that they&amp;rsquo;re light years
behind Espressif. Documents are most readily available from the github repos of a number of russian
makers that discovered the module a couple of years ago. So it goes&amp;hellip;&lt;/p&gt;

&lt;p&gt;When I first saw the power specs in the datasheet I had to laugh. Here is the table I saw next to
the esp8266 table I&amp;rsquo;m quite familiar with. Copying? Naaah&amp;hellip;&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/RTL8710-power-specs.png# fl w-50pct mh0&#34; alt=&#34;RTL8710 Power Specifications&#34; /&gt;
&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/Esp8266-power-specs.png# dib w-50pct mh0&#34; alt=&#34;ESP8266 Power Specifications&#34; /&gt;&lt;/p&gt;

&lt;p class=&#34;cb&#34;&gt;&lt;/p&gt;

&lt;p&gt;The specs are basically the same, no magic here. (I have no idea what &amp;ldquo;normal stand-down&amp;rdquo; refers to.)
The question is really whether RealTek does a
better job at putting the processor to sleep while maintaining an association with the
access point.&lt;/p&gt;

&lt;h3 id=&#34;leisure-power-save&#34;&gt;Leisure Power Save&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Leisure Power Save&lt;/em&gt; or Ameba LPS is the name RealTek gives to the RTL8710 mode where it maintains
an association with the access point while being asleep by periodically waking-up to catch a beacon.
LPS can be turned on easily and there is also a function to set the DTIM interval (the
equivalent to Espressif&amp;rsquo;s listen-interval).&lt;/p&gt;

&lt;p&gt;I decided to cut right to the chase and modified the RealTek sample SleepWithWifiIdle Arduino sketch
following the lines of &lt;a href=&#34;https://github.com/pvvx/RtlDuino/tree/master/development/rtl87xx/libraries/PowerSave/examples/SleepWithWifiIdle&#34;&gt;PVVX&amp;rsquo;s
changes&lt;/a&gt;
to set the DTIM interval to every 4th beacon.
I added the code I used for the esp8266 to open a TCP connection to my local server and
send a message plus to toggle the LED so I could easily trigger the scope.&lt;/p&gt;

&lt;p&gt;The resulting scope capture is shown below. It spans a total of 12 seconds and shows 3 loop
iteration wake-ups that are 5.4 seconds apart.&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/rtl8710-leisure-power-save-all.png# nocaption&#34; alt=&#34;RTL8710 Leisure Power Save&#34; /&gt;&lt;/p&gt;

&lt;p&gt;Just in case you&amp;rsquo;re wondering: nope, I didn&amp;rsquo;t mix-up my scope captures, this is really an RTL8710
capture and not a misplaced esp8266 one! They really look that similar.&lt;/p&gt;

&lt;p&gt;In the capture one can easily make out the various power levels and they
match up with the specs. The TCP connection happens very rapidly (in 11ms according to a packet trace
I captured) and one can see the very brief
wake-up periods every 400ms to catch a beacon.
Something I don&amp;rsquo;t like at all are the very long
high-power periods at ~60mA: those will ruin the low-power performance!&lt;/p&gt;

&lt;p&gt;Looking a bit closer at the activity, here is a zoom-in of the same capture focusing on one loop
iteration:&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/rtl8710-leisure-power-save-zoom.png# nocaption&#34; alt=&#34;RTL8710 Leisure Power Save zoomed&#34; /&gt;&lt;/p&gt;

&lt;p&gt;The pulse on the yellow trace spans the entire loop iteration. The corresponding TCP packet
transmissions can be seen as power spikes. In addition, the capture shows a beacon with a
packet pending. The three TX power spikes of that wake-up period should look familiar:
power-save-off, then an ACK for the packet
received, and a power-save-on packet. The total duration is shorter than for the esp8266 or esp32:
the RTL8710 re-enters power save in just under 40ms.&lt;/p&gt;

&lt;p&gt;Here is a Wifi packet capture of such a beacon with three packets to pick-up:&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/rtl8710-beacon-pickup.png# nocaption&#34; alt=&#34;RTL8710 Beacon Pick-up&#34; /&gt;&lt;/p&gt;

&lt;p&gt;First comes the beacon with the TIM field stating that there&amp;rsquo;s a packet for the RTL8710 (I checked
the packet details to confirm), then the RTL8710 sends a null packet without &amp;ldquo;P&amp;rdquo; flag, meaning it&amp;rsquo;s
exiting power-save. The AP ACKs that packet and follows with a 3-packet sequence that it had stored
up. The RTL8710 ACKs each one and then 30ms after the last one sends a null packet with the &amp;ldquo;P&amp;rdquo; flag
to tell the AP that it is re-entering power-save mode.&lt;/p&gt;

&lt;p&gt;Now to the very long periods at high power. The RTL8710 datasheet says the following about the
Leisure Power Save mode:&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/rtl8710-lps-spec-1.png# w-80 ml-5 nocaption&#34; alt=&#34;RTL8710 LPS Spec&#34; /&gt;
&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/rtl8710-lps-spec-2.png# w-80 ml-5 nocaption&#34; alt=&#34;RTL8710 LPS Spec&#34; /&gt;&lt;/p&gt;

&lt;p&gt;So somehow there is a 2-second timer involved and, looking at the scope captures, indeed one of the
high-power periods is a tad over 2 seconds long and the other a tad over 4 seconds. This pattern of
2-second and 4-second high-power periods repeats consistently although I can&amp;rsquo;t quite figure out
what exactly triggers the periods.&lt;/p&gt;

&lt;p&gt;In a last attempt at LPS I changed the settings to the ones I used with the esp32: a DTIM interval
of 50 (5 seconds) and a loop interval of 23 seconds. The following scope capture shows a total
elasped time of 1 minute:&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/rtl8710-leisure-power-save-1m.png# nocaption&#34; alt=&#34;One minute of RTL8710 Leisure Power Save&#34; /&gt;&lt;/p&gt;

&lt;p&gt;In this trace the RTL8710 spends more time at RX and modem-sleep power levels
than powering down to light-sleep. Clearly cranking the DTIM interval up does not help.&lt;/p&gt;

&lt;p&gt;So far it does not look like the RTL8710 provides a better alternative to the Espressif
microcontrollers for low-power operation. The LPS mode may be usable given some tweaking but
I very much doubt that it can be made to use less power than the esp32.&lt;/p&gt;

&lt;p&gt;The &lt;a href=&#34;https://blog.voneicken.com/2018/lp-wifi-rtl8710-deep&#34;&gt;next post&lt;/a&gt; examines how the RTL8710 performs in deep-sleep with periodic
wake-up.&lt;/p&gt;
</description>
		</item>
		
		<item>
			<title>ESP8266 vs. ESP32 on Battery Power</title>
			<link>https://blog.voneicken.com/2018/lp-wifi-esp-comparison/</link>
			<pubDate>Mon, 10 Dec 2018 00:00:00 UTC</pubDate>
			<author>Thorsten von Eicken</author>
			<guid>https://blog.voneicken.com/2018/lp-wifi-esp-comparison/</guid>
			<description>&lt;p&gt;Having examined the esp8266 and esp32 power consumption in detail it is time to
compare the two.
&lt;/p&gt;

&lt;p&gt;In all the comparisons in this post the following definitions/assumptions are made:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;run-time is calculated based on an idealized 1000mAh battery,&lt;/li&gt;
&lt;li&gt;the access point used is fairly idle, but there are other hosts on the network and thus
there is a constant low rate of background broadcast packets (ARP requests, spanning tree, etc),&lt;/li&gt;
&lt;li&gt;TCP connections contain a minimal data packet,&lt;/li&gt;
&lt;li&gt;TLS connections use a PSK cipher suite, and&lt;/li&gt;
&lt;li&gt;MQTTS uses TLS and contains a publish message and a subscription message delivery.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&#34;deep-sleep-with-periodic-wake-up&#34;&gt;Deep-sleep with periodic wake-up&lt;/h3&gt;

&lt;p&gt;The comparison starts with the deep-sleep with periodic wake-up mode of operation.
It is assumed that all the optimizations described in earlier posts are made,
such as providing all the parameters to &lt;code&gt;wifi.begin&lt;/code&gt; and &lt;code&gt;wifi.config&lt;/code&gt;.&lt;/p&gt;

&lt;h4 id=&#34;open-access-point&#34;&gt;Open access point&lt;/h4&gt;

&lt;p&gt;The two following charts compare the run-time in days between the esp8266 and the esp32
when running a test app that sends a simple packet to a server over TCP. The left
chart shows wake-up intervals of 10 and 60 minutes while the right-hand one shows wake-up intervals
of 20 seconds and 1 minute. This could really be one chart except that a single vertical scale would
cause the 20-second interval bars to be one pixel tall&amp;hellip;&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/Deep-sleep periodic wake-up - Open AP 2.png# fr w-50pct nocaption&#34; alt=&#34;Deep-sleep - open AP&#34; /&gt;
&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/Deep-sleep periodic wake-up - Open AP 1.png# w-50pct nocaption&#34; alt=&#34;Deep-sleep - open AP&#34; /&gt;&lt;/p&gt;

&lt;p&gt;The charts show that when using an open access point the esp8266 uses less power than the esp32.
The reason is that the consumption is dominated by the current used when active,
which is higher in the esp32 case,
and both are active for about the same amount of time,
which is dominated by the probing for the access point.&lt;/p&gt;

&lt;h4 id=&#34;secure-access-point&#34;&gt;Secure access point&lt;/h4&gt;

&lt;p&gt;The next two charts compare the run-times when using a secure AP and adding MQTTS/TLS in the esp32
case.&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/Deep-sleep periodic wake-up - Secure AP 2.png# fr w-50pct nocaption&#34; alt=&#34;Deep-sleep - secure AP&#34; /&gt;
&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/Deep-sleep periodic wake-up - Secure AP 1.png# w-50pct nocaption&#34; alt=&#34;Deep-sleep - secure AP&#34; /&gt;&lt;/p&gt;

&lt;p&gt;When using a secure access point the esp8266 and esp32 show roughly the same performance.
The reason is that while the esp32 uses more power when active it completes the WPA2-PSK
association more rapidly then the esp8266.&lt;/p&gt;

&lt;p&gt;Adding MQTT and TLS to the exchange doesn&amp;rsquo;t cost a lot of extra power because of the speed at which
the esp32 performs the crypto and the rapid Wifi packet exchanges.&lt;/p&gt;

&lt;h3 id=&#34;light-sleep-maintaining-an-association&#34;&gt;Light-sleep maintaining an association&lt;/h3&gt;

&lt;p&gt;The next chart shows automatic light-sleep where the microcontroller automatically goes to sleep
when there is no activity and wakes-up periodically to maintain an association with the access point.
The chart varies the iteration period and assumes one broadcast packet causing a wake-up every 10
seconds.&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/Light-sleep - Secure AP.png# fr w-50pct ml3 nocaption&#34; alt=&#34;Light-sleep - secure AP&#34; /&gt;&lt;/p&gt;

&lt;p&gt;In the esp32 case the chart uses the values for the &lt;a href=&#34;https://blog.voneicken.com/2018/lp-wifi-esp32-pushed#to-the-limit&#34;&gt;&amp;ldquo;pushed&amp;rdquo;
version&lt;/a&gt;,
which sets the listen_interval
to 5 seconds and removes the ACK delay in LwIP.&lt;/p&gt;

&lt;p&gt;The comparison is a little skewed because the esp8266 just sends a small amount of data over TCP
while the esp32 publishes a message over MQTT/TLS and receives a subscription message.
However, as we&amp;rsquo;ve seen before, the exact nature of the connection tends not to be the dominant
factor in the overall power consumption.&lt;/p&gt;

&lt;p&gt;In light-sleep mode the esp32 performs much better than the esp8266 in large part due to the
esp8266&amp;rsquo;s bug where it drops into modem-sleep instead of light-sleep about half the time after a
beacon.&lt;/p&gt;

&lt;p&gt;The fact that the esp32 allows the listen interval to be set explicitly is also an advantage, not
just in terms of the numbers shown here but also because it reduces the impact of Wifi broadcast
activity.&lt;/p&gt;

&lt;h3 id=&#34;conclusions&#34;&gt;Conclusions&lt;/h3&gt;

&lt;p&gt;To conclude the esp8266 and esp32 low-power wifi exploration the graph below summarizes the
tradeoffs between the two microcontrollers and the two sleep modes. It&amp;rsquo;s a bit of an eye chart with
so many lines but the lines comes in pairs making it not all that difficult to walk though (see
below). The chart
shows the run-time on an idealized 1000mAh battery on the vertical axis (i.e. higher is better) vs.
the interval at which the code is waking up to communicate.
All the numbers are based on modeling the observed behavior of the microcontrollers.&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/ESP8266 vs. ESP32 in Light-Sleep and Deep-Sleep.png# w-100pct nocaption&#34; alt=&#34;Esp8266 vs. esp32, light-sleep and deep-sleep&#34; /&gt;&lt;/p&gt;

&lt;p&gt;The lines that go off the top of the chart are for deep-sleep with periodic wake-up using an
insecure open access point.
Deep-sleep without crypto uses the least power of all options when
iteration times exceed a few seconds.
The esp8266 fares better than the esp32 because it uses less power when active and has a shorter
start-up sequence. Both cases specify all parameters to &lt;code&gt;WiFi.begin&lt;/code&gt; and &lt;code&gt;WiFi.config&lt;/code&gt;, i.e. they&amp;rsquo;re
the optimized cases.&lt;/p&gt;

&lt;p&gt;The other two straight lines that are right on top of one another are for deep-sleep with periodic
wake-up but using a secure WPA2-PSK access point.
Somewhat surprisingly the two microcontrollers perform basically the same, although the comparison
is slightly skewed because the esp32 communicates with an MQTT/TLS server at each wake-up while the
esp8266 only sends a brief TCP message.
The esp32 performs the WPA2 crypto faster than the esp8266 but uses more power while doing so.&lt;/p&gt;

&lt;p&gt;The two solid curved lines are for automatic light-sleep where &lt;code&gt;loop()&lt;/code&gt; iterates periodically and
there is approximately one broadcast packet every 10 seconds on the network that also wakes-up the
microcontroller. In both cases a secure access point is used.
The lines are curved because at short intervals the &lt;code&gt;loop()&lt;/code&gt; wake-up is the dominant effect while at
long intervals the broadcast packet wake-up becomes dominant.
Here the esp32 performs much better than the esp8266 primarily because it reliably goes back to light-sleep.
In addition, its power save listen interval is 5x as long and
it goes to sleep more rapidly after waking up.&lt;/p&gt;

&lt;p&gt;The final two dotted lines are idealized: they cannot be achieved with the current Espressif WiFi
firmware.
In the esp32 case the dotted line represents automatic light-sleep where the lingering interval
before re-entering power-save mode has been shortened from 50ms to 10ms. In the esp8266 case it
represents fixing a bug that puts the microcontroller into modem-sleep instead of light-sleep about
half the time. These two lines show what might be achievable if Espressif fixed these issues.&lt;/p&gt;

&lt;p&gt;Comparing the esp32 light-sleep and deep-sleep cases shows a cross-over around an interval of 60
seconds. This means that use-cases that only require a wake-up every minute or longer should
use deep-sleep as expected, but use-cases where the microcontroller needs to remain reachable at all
times work better in the light-sleep mode.&lt;/p&gt;

&lt;p&gt;My personal opinion on this comparison is biased towards security, and that strongly favors the
esp32 not only because of the power consumption but also because of its larger memory, which makes
the use of TLS much more practical.&lt;/p&gt;

&lt;p&gt;While there are some more loose end I&amp;rsquo;d like to explore with the esp8266 and esp32 the
&lt;a href=&#34;https://blog.voneicken.com/2018/lp-wifi-rtl8710-lps&#34;&gt;next post&lt;/a&gt; switches gears a little and investigates the RealTek RTL8710
in the form of the RTLDuino.&lt;/p&gt;</description>
		</item>
		
		<item>
			<title>ESP32 Pushing the Envelope</title>
			<link>https://blog.voneicken.com/2018/lp-wifi-esp32-pushed/</link>
			<pubDate>Sun, 09 Dec 2018 00:00:00 UTC</pubDate>
			<author>Thorsten von Eicken</author>
			<guid>https://blog.voneicken.com/2018/lp-wifi-esp32-pushed/</guid>
			<description>&lt;p&gt;With a few more hacks the esp32 light-sleep power consumption can be pushed to the limit. This post
explores the limit and calculates light-sleep mode run-times.
&lt;/p&gt;

&lt;h3 id=&#34;to-the-limit&#34;&gt;To the limit&lt;/h3&gt;

&lt;p&gt;The &lt;a href=&#34;https://blog.voneicken.com/2018/lp-wifi-esp32-light&#34;&gt;previous post&lt;/a&gt; uncovered a number of problems with the automatic light
sleep mode.
In addition, the Arduino framework does not officially support the esp32&amp;rsquo;s automatic power management,
and hence I used a trivial app to measure just the basic behavior.
In order to push the envelope I hacked ESP-IDF as well as the arduino framework.
I configured ESP-IDF to include the arduino framework
as a &amp;ldquo;component&amp;rdquo;. The steps for that are best outlined in &lt;a href=&#34;https://github.com/espressif/arduino-esp32/issues/1142#issuecomment-367867856&#34;&gt;this reply to a
ticket&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Using this method it is possible to make a number of fixes to push the envelope and measure real
application-level communication &amp;ndash; an encrypted MQTT exchange in my case.
The specific changes are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;remove the ACK delay in LwIP (this will have negative effects on high bandwidth connections)&lt;/li&gt;
&lt;li&gt;enable dynamic power management and frequency scaling while using arduino&lt;/li&gt;
&lt;li&gt;push the listen_interval (how long to sleep between beacon-check wake-ups) to large values&lt;/li&gt;
&lt;li&gt;run the MQTT/TLS sketch used in previous posts&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The specific settings I experimented with are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;listen_interval = 5 seconds (e.g. a value of 50)&lt;/li&gt;
&lt;li&gt;wake-up interval to pub/sub MQTT messages = 23 seconds (I picked an odd interval)&lt;/li&gt;
&lt;li&gt;MQTT keep-alive = 70 seconds (effectively no keep-alives are sent)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The final code is &lt;a href=&#34;https://github.com/tve/low-power-wifi/tree/master/esp32-pow-save-mqtt&#34;&gt;available on
github&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Another setting that could be tweaked is to disable the periodic sending of gratuitous ARPs by LwIP,
but because it only happens once a minute I&amp;rsquo;m not convinced it makes a real difference here.
The setting I really wanted to change as well is the Wifi RX lingering period before re-entering power-save
mode, but it appears to be buried in the Wifi binary blob.&lt;/p&gt;

&lt;p&gt;After making these changes I took a fair number of measurements and had some difficulties interpreting
them because the loop iterations are not always successful. I was using my general home wifi and it
appeared as if the esp32 had difficulties maintaining the association. I switched to a test AP (on
the same LAN) and the association appeared more stable. I suspect that a listen interval of 5
seconds is too long but I left it as-is in order to get a &amp;ldquo;very best case&amp;rdquo; number. For a real
deployment one most likely has to tweak this setting to find a happy medium.&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/esp32-auto-light-sleep-scope.png&#34; alt=&#34;Esp32 auto power save scope capture over 60 seconds&#34; /&gt;
&lt;em&gt;Scope capture showing the esp32 automatic light sleep over a period of 60 seconds with two
wake-ups to exchange MQTT packets over TLS and several additional wake-ups to pick-up broadcast
packets. The average power consumption is approx 3.8mA and not 14.9mA as incorrectly averaged by the
scope.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The scope capture above shows the general behavior with two loop iterations just barely visible in
the yellow trace. The corresponding MQTT exchanges can be seen in the blue trace that captures the
power consumption. The Wifi wake-ups every 5 seconds are clearly visible and a number of them result
in the transmitter powering up to pick-up a packet that is pending at the AP. Unfortunately the
average power consumption displayed by the scope is inaccurate due to the degree of averaging being
performed in this capture of 60 second duration.&lt;/p&gt;

&lt;p&gt;In order to get an accurate average power consumption reading I used a 1F supercap, which I measured
to have an actual 940mF (the tolerance spec is -20%/+80%).
I ran the app for 10 minutes and measured the voltage
drop which resulted in a calculated average power consumption of 3.8mA.&lt;/p&gt;

&lt;h3 id=&#34;esp32-run-time-in-automatic-light-sleep&#34;&gt;Esp32 run-time in automatic light-sleep&lt;/h3&gt;

&lt;p&gt;With all the measurements we can put together a model for the power consumption when using automatic
light-sleep. The following chart shows the power consumption in terms of the expected
run-time on a 1000mAh battery as the wake-up interval is varied from 1 second to 60 seconds.&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/esp32-auto-light-sleep-chart.png#
nocaption w-90pct center&#34; alt=&#34;ESP32 automatic light-sleep run-times&#34; /&gt;&lt;/p&gt;

&lt;p&gt;Three different models are shown:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the &lt;em&gt;std&lt;/em&gt; model uses the off-the-shelf power management features as available in the ESP-IDF,&lt;/li&gt;
&lt;li&gt;the &lt;em&gt;pushed&lt;/em&gt; model uses the hacks described in the previous section, and&lt;/li&gt;
&lt;li&gt;the &lt;em&gt;ideal&lt;/em&gt; model shows what could hypothetically be achieved by reducing the lingering time to 10ms.&lt;/li&gt;
&lt;li&gt;the &lt;em&gt;deep-sleep&lt;/em&gt; model uses deep-sleep with periodic wake-up as &lt;a href=&#34;https://blog.voneicken.com/2018/lp-wifi-esp32-2&#34;&gt;previously described&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All the models assume:&lt;/p&gt;

&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;operation&lt;/th&gt;&lt;th&gt;std model&lt;/th&gt;&lt;th&gt;pushed model&lt;/th&gt;&lt;th&gt;ideal model&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;light-sleep current&lt;/td&gt;&lt;td colspan=&#34;3&#34; align=&#34;center&#34;&gt;1.1mA&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;listen_interval&lt;/td&gt;&lt;td align=&#34;center&#34;&gt;1s&lt;/td&gt;&lt;td colspan=&#34;2&#34; align=&#34;center&#34;&gt;5s&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;beacon check&lt;/td&gt;&lt;td colspan=&#34;3&#34; align=&#34;center&#34;&gt;10ms @125mA&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;lingering&lt;/td&gt;&lt;td colspan=&#34;2&#34; align=&#34;center&#34;&gt;50ms @125mA&lt;/td&gt;&lt;td align=&#34;center&#34;&gt;10ms @125mA&lt;/td&gt;&lt;/tr&gt; 
&lt;tr&gt;&lt;td&gt;loop iteration&lt;/td&gt;&lt;td colspan=&#34;3&#34; align=&#34;center&#34;&gt;20ms @125mA&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;broadcast packet rate&lt;/td&gt;&lt;td align=&#34;center&#34;&gt;1 pps and 0.1 pps&lt;/td&gt;&lt;td colspan=&#34;2&#34; align=&#34;center&#34;&gt;0.1 pps&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;security&lt;/td&gt;&lt;td colspan=&#34;3&#34; align=&#34;center&#34;&gt;WPA2-PSK &amp;amp; MQTT/TLS using PSK cipher suite&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;The &lt;a href=&#34;https://blog.voneicken.com/2018/lp-wifi-esp-comparison&#34;&gt;next post&lt;/a&gt; compares the low-power performance of the esp32 with
the esp8266.&lt;/p&gt;</description>
		</item>
		
		<item>
			<title>ESP32 Dynamic Frequency Scaling</title>
			<link>https://blog.voneicken.com/2018/lp-wifi-esp32-dfs/</link>
			<pubDate>Tue, 04 Dec 2018 00:00:00 UTC</pubDate>
			<author>Thorsten von Eicken</author>
			<guid>https://blog.voneicken.com/2018/lp-wifi-esp32-dfs/</guid>
			<description>&lt;p&gt;Dynamic frequency scaling allows the esp32 to go into light-sleep mode when it is idle.&lt;/p&gt;

&lt;p&gt;In the ESP IDF framework dynamic frequency scaling with light-sleep is enabled by turning on power
management (a compile-time option) and then calling a few functions as described in this
&lt;a href=&#34;https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/system/power_management.html&#34;&gt;documentation&lt;/a&gt;.
Unfortunately the arduino framework does not currently support enabling the power management because
its interaction with peripheral clocks is non-trivial.&lt;/p&gt;

&lt;p&gt;To evaluate the potential of the frequency scaling and light sleep I started with the &lt;code&gt;power_save&lt;/code&gt;
&lt;a href=&#34;https://github.com/espressif/esp-idf/tree/master/examples/wifi/power_save&#34;&gt;ESP IDF example app&lt;/a&gt;.
At first I had difficulties getting it to work, which resulted in a
&lt;a href=&#34;https://github.com/espressif/esp-idf/issues/2711&#34;&gt;ticket&lt;/a&gt; and
a quick &lt;a href=&#34;https://github.com/espressif/esp-idf/issues/2711#issuecomment-441863113&#34;&gt;patch&lt;/a&gt;.
This made the example app work on my Wifi network.&lt;/p&gt;

&lt;p&gt;I then modified the example app slightly and set the listen interval to 9, i.e., wake up every 900ms
to check the beacon. The app just connects to Wifi and then does nothing, which is not terribly
representative, so I generated some Wifi activity by running a ping to the esp32 with an interval
of 6 seconds.
A snippet of the ping output is:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;64 bytes from 192.168.0.165: icmp_seq=60 ttl=255 time=79.9 ms
64 bytes from 192.168.0.165: icmp_seq=61 ttl=255 time=528 ms
64 bytes from 192.168.0.165: icmp_seq=62 ttl=255 time=54.3 ms
64 bytes from 192.168.0.165: icmp_seq=63 ttl=255 time=504 ms
64 bytes from 192.168.0.165: icmp_seq=64 ttl=255 time=24.8 ms
64 bytes from 192.168.0.165: icmp_seq=65 ttl=255 time=471 ms
64 bytes from 192.168.0.165: icmp_seq=66 ttl=255 time=2.33 ms
64 bytes from 192.168.0.165: icmp_seq=67 ttl=255 time=440 ms
64 bytes from 192.168.0.165: icmp_seq=68 ttl=255 time=886 ms
64 bytes from 192.168.0.165: icmp_seq=69 ttl=255 time=411 ms
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The response time varies as expected from anywhere between a couple of milliseconds up to almost
900ms, which is the interval at which the esp32 wakes up.&lt;/p&gt;

&lt;p&gt;A scope capture of the power consumption looks as follows:&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/esp32-light-sleep-all.png&#34; alt=&#34;Automatic light sleep&#34; /&gt;
&lt;em&gt;Esp32 in automatic light sleep with a listen interval of 900ms and being pinged every 6 seconds.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The capture uses a 1 second per horizontal division and thus shows 12 seconds total. Two pings can
be discerned from the TX power spikes that are 6s apart. An additional power spike must be due to
some broadcast traffic on the network that the esp32 picks up. The wake-up every 900ms to listen to
the beacon can also be seen and finally the most frequent power level is very close to zero in light
sleep.&lt;/p&gt;

&lt;p&gt;The following zoomed scope capture magnifies the period where some broadcast traffic and a ping are
received. One can now see the familiar pattern where the esp32 wakes up, transmits a power-save-off
packet, receives packets from the AP, potentially responds (in the case of the ping), then lingers
for 50ms and finally sends a power-save-on packet before dropping to sleep.&lt;/p&gt;

&lt;p&gt;The capture also shows some timer activity every 100ms and the light-sleep power save level. Not
really discernible in this capture is the fact that the light-sleep consumption is about 1.1mA.&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/esp32-light-sleep-zoom.png&#34; alt=&#34;Automatic light sleep zoomed&#34; /&gt;&lt;/p&gt;

&lt;p&gt;The big question now is what the average power consumption is and as previously mentioned in the
esp8266 light-sleep post this really depends on the amount of network activity that causes the esp32
to wake up! I measured the following average power consumption figures for this particular set-up:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;overall with pings and bcast traffic: 6.1mA&lt;/li&gt;
&lt;li&gt;100ms period without wifi activity and one &amp;ldquo;timer tick&amp;rdquo;: 2.1mA&lt;/li&gt;
&lt;li&gt;100ms period with wifi RX-only wake-up for beacon: 7.1mA&lt;/li&gt;
&lt;li&gt;100ms period with wifi wake-up incl packet pick-up: I forgot to measure, but since at least 50ms
are spent lingering at ~115mA the average is certainly above 50mA&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It is quite clear that the power consumption is primarily related to how frequently the esp32
wakes-up. I don&amp;rsquo;t understand why Espressif doesn&amp;rsquo;t:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;allow the listen interval to be set larger than 10&lt;/li&gt;
&lt;li&gt;allow the lingering period to be controlled by the app&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Obviously tweaking these settings has an effect on how responsive the esp32 is to network traffic
and requests, but surely the app designer knows better what is appropriate in a given setting.&lt;/p&gt;

&lt;p&gt;The &lt;a href=&#34;https://blog.voneicken.com/2018/lp-wifi-esp32-pushed&#34;&gt;next post&lt;/a&gt; pushes the limits of automatic light sleep and calculates
run-times.&lt;/p&gt;</description>
		</item>
		
		<item>
			<title>ESP32 Maintaining an Association</title>
			<link>https://blog.voneicken.com/2018/lp-wifi-esp32-light/</link>
			<pubDate>Mon, 03 Dec 2018 00:00:00 UTC</pubDate>
			<author>Thorsten von Eicken</author>
			<guid>https://blog.voneicken.com/2018/lp-wifi-esp32-light/</guid>
			<description>&lt;p&gt;The esp32 can also maintain an association with an access point while going to sleep on
its own when it is idle. Is this a good alternative to periodically waking up from deep-sleep?&lt;/p&gt;

&lt;p&gt;There are actually several different modes that allow the esp32 to maintain an association and
reduce power when it is not active. The modes are described in
&lt;a href=&#34;https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/system/power_management.html&#34;&gt;the API reference&lt;/a&gt;
and they all take advantage of the Wifi power save mode and DTIM
interval (see my &lt;a href=&#34;https://blog.voneicken.com/2018/lp-wifi-association&#34;&gt;earlier post&lt;/a&gt; on the topic).
To save power, the device tells the access point (AP) that it&amp;rsquo;s turning its radio off
and the AP holds packets destined for the device until it wakes-up again.
In addition, the AP includes a flag in its
beacons to tell the device whether it has packets pending so the device only neeeds to turn RX on
periodically and check the beacon.&lt;/p&gt;

&lt;h3 id=&#34;modem-sleep&#34;&gt;Modem sleep&lt;/h3&gt;

&lt;p&gt;The arduino framework automatically supports the &amp;ldquo;modem sleep&amp;rdquo; mode where the esp32 turns off
the radio but keeps the cpu cores running.
I tested this by modifying &lt;a href=&#34;https://github.com/tve/low-power-wifi/esp32-light-sleep-mqtt&#34;&gt;the MQTT test
app&lt;/a&gt;
so it connects to Wifi and the MQTT server in the
&lt;code&gt;setup&lt;/code&gt; function and then publishes to a loop-back topic once every few seconds in the &lt;code&gt;loop&lt;/code&gt;
function.&lt;/p&gt;

&lt;p&gt;I ended up using an open access point and unencrypted MQTT connection so I could analyze the packets
more easily. (I did later test using a secure AP and MQTT over TLS and the observed behavior is almost
indistinguishable.)
A tcpdump running on the MQTT server showed the following for a loop iteration:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;13:25:39.900240 IP 192.168.0.165.52345 &amp;gt; 192.168.0.14.1883: Flags [P.], seq 24:48, ack 25, win 4976, length 24
13:25:39.900471 IP 192.168.0.14.1883 &amp;gt; 192.168.0.165.52345: Flags [P.], seq 25:49, ack 48, win 29200, length 24

13:25:40.133252 IP 192.168.0.165.52345 &amp;gt; 192.168.0.14.1883: Flags [.], ack 49, win 4952, length 0
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Just 3 packets, that&amp;rsquo;s pretty impressive! The first packet contains the publish request (using MQTT QoS 0), the
server turns around and sends the message back on the pre-existing subscription 230 &lt;em&gt;microseconds&lt;/em&gt;
later and piggy-backs the TCP ACK on the same packet. Finally the esp32 ACKs the server&amp;rsquo;s packet at
the TCP level. This is as minimal as one could wish for!&lt;/p&gt;

&lt;p&gt;The following scope capture shows the loop iteration and power consumption:&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/esp32-modem-sleep-mqtt.png&#34; alt=&#34;MQTT pub-sub with modem sleep&#34; /&gt;&lt;/p&gt;

&lt;p&gt;The yellow trace is high from the start to the end of the &lt;code&gt;loop&lt;/code&gt; function.
That takes under 15ms and includes publishing a message and then waiting for it to come back on a
subscription to the same topic.
Rather impressive, to be honest!&lt;/p&gt;

&lt;p&gt;The blue trace shows the power consumption at a resolution of 50mA per vertical division. One can
easily make out the modem sleep power level around 40mA, the radio RX power level around 115mA,
and the short transmit spikes. The RX power spikes to 1125mA every 100ms are clearly visible where the
esp32 captures the AP&amp;rsquo;s beacon to see whether it has a packet pending.&lt;/p&gt;

&lt;p&gt;The shape of the active period around the loop iteration should look familiar from the equivalent
&lt;a href=&#34;https://blog.voneicken.com/2018/lp-wifi-esp8266-assoc#wake-cycle-activity&#34;&gt;esp8266 scope captures&lt;/a&gt;:
the esp32 powers the radio up, transmits
a &amp;ldquo;exiting power-save mode&amp;rdquo; packet, then transmits and receives data packets, and finally lingers for some
time to give the AP an opportunity to send additional packets. Eventually the esp32 transmits a
&amp;ldquo;entering power-save mode&amp;rdquo; packet and turns the radio off.&lt;/p&gt;

&lt;p&gt;In the esp8266 the time spent lingering was around 80ms, in the esp32 this got shortened to 50ms,
which is better in the many cases where there are no packets. I wish it was smarter and cut that
time down more. For example, it could determine whether the AP is idle by monitoring the radio and,
when that is the case, conclude early on that the AP must not have any queued packet.&lt;/p&gt;

&lt;p&gt;The odd feature of this scope capture is the fact that there are two long high-power periods
spaced only 150ms apart.
The &lt;code&gt;loop&lt;/code&gt; function iterations are several seconds apart, so that&amp;rsquo;s not the cause.
The second of the two periods in this scope capture does not start at a beacon interval thus it
must be caused by something other than the AP having some packet pending.
The answer is seen in the tcpdump above: the TCP stack on
the esp32 delays the final ACK by about 100ms, i.e., longer than the lingering time and this causes
a second wake-up period. Delaying ACKs
is a common TCP optimization that reduces the number of packets transmitted. It works well on the
server end where delaying the ACK allowed it to be piggy-backed on the response data packet but it
back-fires in the case of the ACK from the esp32 and doubles the power-cost of the whole exchange.&lt;/p&gt;

&lt;p&gt;Unfortunately it is not easily possible to disable the ACK delay. It is possible to disable
the TCP Nagle algorithm by calling &lt;code&gt;WiFiClient.setNoDelay&lt;/code&gt; but that does not affect delayed ACKs.
Looking at the LwIP code, a TCP_QUICKACK socket option is not implemented and in fact
there is no configuration setting to affect ACK delay: the code to send the ack when receiving
data on a connection is
&lt;a href=&#34;https://github.com/espressif/esp-lwip/blob/046fadde072b5fca94bea84c16cce5ecbfd6948e/src/core/tcp_in.c#L1541&#34;&gt;here&lt;/a&gt;
and would need to be changed to &lt;code&gt;tcp_ack_now(pcb)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Overall all this is interesting to understand the timing behavior of the esp32 but from a power
point of view the minimum consumption of 40mA at modem-sleep level is not what I&amp;rsquo;m looking for.
The &lt;a href=&#34;https://blog.voneicken.com/2018/lp-wifi-esp32-dfs&#34;&gt;next post&lt;/a&gt; turns on automatic power saving with dynamic frequency scaling.&lt;/p&gt;</description>
		</item>
		
		<item>
			<title>Low-Power ESP32 Boards</title>
			<link>https://blog.voneicken.com/2018/lp-wifi-esp32-boards/</link>
			<pubDate>Sat, 01 Dec 2018 00:00:00 UTC</pubDate>
			<author>Thorsten von Eicken</author>
			<guid>https://blog.voneicken.com/2018/lp-wifi-esp32-boards/</guid>
			<description>&lt;p&gt;&lt;em&gt;Updated 2019-08-25 to include EzSBC&amp;rsquo;s ESP32-01 Breakout and Development Board&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In order to test the low-power performance of the esp32 I had to acquire a few boards and
I didn&amp;rsquo;t really like any of them.
&lt;/p&gt;

&lt;p&gt;The main characteristic I am looking for is the power consumption from a LiPo in deep sleep.
When I ordered the first board, I didn&amp;rsquo;t think much about it. Oh, how wrong I was!
I then consulted Andreas Spiess&amp;rsquo; excellent &lt;a href=&#34;https://www.youtube.com/watch?v=-769_YIeGmI&#34;&gt;youtube&lt;/a&gt;
about battery powered esp32 boards, but most of them have frills I don&amp;rsquo;t care for.
In the end, I&amp;rsquo;m concluding that I need to make my own minimal board, but first let&amp;rsquo;s see how I got
there.&lt;/p&gt;

&lt;h3 id=&#34;nodemcu-esp32s&#34;&gt;NodeMCU Esp32S&lt;/h3&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/esp32-boards-nodemcu.jpg# fr w-30pct&#34; alt=&#34;Esp32s NodeMCU board&#34; /&gt;
I ordered a NodeMCU Esp32s a while back because the price seemed right and it was one of these &amp;ldquo;I
may want to have this some day&amp;rdquo; type of purchases. I developed the first apps having it attached to
USB.&lt;/p&gt;

&lt;p&gt;Then came the time to measure power consumption and for that I hooked up a LiPo so I don&amp;rsquo;t have
a ground loop through the scope ground probes. To my shock the app didn&amp;rsquo;t run! After quite some head
scratching I had the brilliant idea to measure the 3.3V rail. It showed only 2.3V!
(My LiPo was only ~30% full.) Ouch, that&amp;rsquo;s a no-go. How can that be?&lt;/p&gt;

&lt;p&gt;The answer is that there are LDOs and and LDOs&amp;hellip;
The board uses an AMS1117 and its drop-out voltage, i.e., minimal input-to-output voltage drop is over
1V.
Calling this an LDO seems like a marketing stunt to me&amp;hellip;
Anyway, probably a great board, but totally unsuitable for battery operation.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Update:&lt;/em&gt; I somehow ended up with some more boards with an AMS1117 LDO and finally spent some time looking
whether I could replace it with a better one. Finding an LDO with the same package is easy but they
don&amp;rsquo;t tend to have the same pin-out. I finally found the AP7361C-33ER, which has a low drop-out
and the same pin-out &lt;em&gt;and&lt;/em&gt; Digikey has it in stock! I used some hot air to desolder an AMS1117 and
put the AP7361C in its place and it works like a charm on a LiPo! Be careful when ordering, the &amp;ldquo;R&amp;rdquo;
at the end of the part number is key, it refers to the &amp;ldquo;reverse&amp;rdquo; pin-out that the AMS1117 uses.&lt;/p&gt;

&lt;h3 id=&#34;adafruit-huzzah32&#34;&gt;Adafruit Huzzah32&lt;/h3&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/esp32-boards-huzzah32.jpg# fr w-50pct ml3&#34; alt=&#34;Esp32 Huzzah32 board&#34; /&gt;&lt;/p&gt;

&lt;p&gt;I wanted to get to my battery power measurements badly so I loked around on Amazon for options with
prime shipping.
I saw the Adafruit Huzzah32 at $20, ouch! But with a LiPo connector and an integrated charger it&amp;rsquo;s
clearly designed for battery operation. Ok, gotta pay for quality. Buy now!&lt;/p&gt;

&lt;p&gt;The good news: it ran my first test apps fine. The bad news: it consumes power like there&amp;rsquo;s no
tomorrow. Deep-sleep means 6.5mA. No, that&amp;rsquo;s not a typo: milliamperes. Or put differently, a cool
1000x more than it should.&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/huzzah32-fix.jpg# fr w-50pct ml3&#34; alt=&#34;CP2104 fix&#34; /&gt;&lt;/p&gt;

&lt;p&gt;At that point I wished I had ordered one of the cheap chinese boards. But I browsed around and found
the answer: the CP2104 USB-serial chip doesn&amp;rsquo;t power down. More browsing later, I found that it can
be seduced into USB suspend state, i.e., low-power state, by adding a pull down resistor on the USB
D- line. That brought power consumption down into the 200uA-250uA range. Great improvement, but still far
from the goal. At least it&amp;rsquo;s not totally ridiculous anymore.&lt;/p&gt;

&lt;p&gt;I had another &amp;ldquo;fun&amp;rdquo; experience with the Huzzah32. Long story short it produced weird errors that I
couldn&amp;rsquo;t reproduce with the NodeMCU. I eventually reached the hypothesis that the flash chip was not
working properly, so I decided to remove the esp32-wroom shield and replace the flash chip. Except
that I completely botched it and lifted two pads. Ouch. The result is a &amp;ldquo;creative&amp;rdquo; flash chip
placement visible in the first photo. It does work flawlessly now, though.&lt;/p&gt;

&lt;h3 id=&#34;sparkfun-esp32-thing&#34;&gt;Sparkfun Esp32 Thing&lt;/h3&gt;

&lt;p&gt;I continued browsing for what to buy, &amp;lsquo;cause I started to get curious about whether there are any
low-power Esp32 boards with USB out there. If you reject all boards that have an AMS1117 LDO or that
have a CP2104/CP2102 USB interface then the pickings become real slim.&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/esp32-boards-thing.jpg# fr w-30pct&#34; alt=&#34;Sparkfun Esp32 Thing board&#34; /&gt;&lt;/p&gt;

&lt;p&gt;The Sparkfun Esp32 Thing caught my eye. It has a different LDO and a FTDI USB chip. It also has a LiPo
charger and connector and seemed well designed. Again, $21. But that&amp;rsquo;s better than $8 for a board
that doesn&amp;rsquo;t even &lt;em&gt;run&lt;/em&gt; on LiPO. Buy now!&lt;/p&gt;

&lt;p&gt;I plugged the Thing in and measured deep-sleep current: 2mA! Ok, that&amp;rsquo;s unfair, it has a power-is-on
LED and a jumper-trace in the back that needs to be cut. After cutting the trace I measured 900uA.
At that point I got rather annoyed. This was the second expensive board that completely flunks the
deep-sleep test.&lt;/p&gt;

&lt;p&gt;I browsed the Sparkfun docs: nothing about the power consumption, except for other users complaining
about the same thing. Some more browsing later I found out that another jumper-trace in the back
needs to be cut and switched around so the flash chip gets powered by a special LDO inside
the esp32 instead of the 3.3v rail.
This way it gets powered down in deep-sleep. Now the power consumption got down to 63uA. Looking at
the LDO data sheet reveals that its typical quiescent consumption is 55uA, so it&amp;rsquo;s unlikely one can
get much lower.&lt;/p&gt;

&lt;p&gt;The good news: it&amp;rsquo;s better than the Huzzah32. The bad news: it&amp;rsquo;s 10x more than the esp32&amp;rsquo;s
deep-sleep consumption. In all fairness, the 55uA power consumption is good enough for the vast
majority of use-cases. Unless the esp32 is to sleep for hours between wake-ups the difference
between 63uA and 6.3uA does not matter much.&lt;/p&gt;

&lt;p&gt;All-in-all this is the best board I&amp;rsquo;ve seen, except for the fact that it doesn&amp;rsquo;t have an FCC certified
esp32 module. Not only does it have the best deep-sleep performance, it also has a well-engineered
usb/lipo power switchover/charge circuitry and it has a 32khz oscillator for accurate RTC timing.&lt;/p&gt;

&lt;h3 id=&#34;building-my-own-board&#34;&gt;Building my own board&lt;/h3&gt;

&lt;p&gt;I haven&amp;rsquo;t started yet but if I am to deploy battery-powered esp32&amp;rsquo;s I want a board that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;has no USB (it&amp;rsquo;s convenient for prototyping but unnecessary in the field)&lt;/li&gt;
&lt;li&gt;has an esp32-wroom-32 or esp32-wrover module so the flash chip is properly connected and the whole
thing is shielded&lt;/li&gt;
&lt;li&gt;has an LDO with a low drop-out voltage and low quiescent current.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;About the LDO, the AP2112 used in the Sparkfun Thing is probably good enough. I looked at other
options and in the 500mA LDO category the Ti TLV755p has a 25uA quiescent current (Iq).
Stepping down to 300mA the Richtek RT9078 LDO has an Iq of 2uA and
the 300mA On semi NCP703 3 has an Iq of 12uA.
Using a 300mA LDO may be a bit tight depending on what else it&amp;rsquo;s powering, but for the esp32 itself
it should be enough.&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/esp32-boards-ezsbc.jpg# fr w-30pct&#34; alt=&#34;EzSBC board&#34; /&gt;&lt;/p&gt;

&lt;h3 id=&#34;ezsbc-esp32-01-breakout-and-development-board&#34;&gt;EzSBC ESP32-01 Breakout and Development Board&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;This section was added 2019-08-25&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I became aware of this board through the designer&amp;rsquo;s (Daniel deBeer) comments below and
decided to order two for evaluation. The boards are nicely done and the inclusion of 2 RGB LEDs is
welcome. The price is good and I had no difficulties running some of my test programs.&lt;/p&gt;

&lt;p&gt;Long story short the boards use a TS9013 LDO and, true to Daniel&amp;rsquo;s claims, I see a 13uA-15uA average
power consumption in deep sleep. I&amp;rsquo;d say: mission accomplished! I only hope he will have more in
stock soon so I can order a couple more&amp;hellip;&lt;/p&gt;

&lt;p&gt;Stay tuned for more posts about the Esp32&amp;rsquo;s Wifi power consumption&amp;hellip;&lt;/p&gt;

&lt;p&gt;The &lt;a href=&#34;https://blog.voneicken.com/2018/lp-wifi-esp32-light&#34;&gt;next post&lt;/a&gt; switches from deep-sleep to experiments using automatic
light-sleep allowing the esp32 to maintain an association with the AP while going into low-power
modes.&lt;/p&gt;</description>
		</item>
		
		<item>
			<title>ESP32 Deep-Sleep Connecting to MQTT</title>
			<link>https://blog.voneicken.com/2018/lp-wifi-esp32-mqtt/</link>
			<pubDate>Fri, 30 Nov 2018 00:00:00 UTC</pubDate>
			<author>Thorsten von Eicken</author>
			<guid>https://blog.voneicken.com/2018/lp-wifi-esp32-mqtt/</guid>
			<description>&lt;p&gt;Periodically waking up from deep sleep and sending a short TCP message is interesting, but
how does the esp32 perform in a real scenario where it communicates with an MQTT server?
&lt;/p&gt;

&lt;p&gt;The previous posts cover the startup-time to connect to Wifi so this is really an extension of those
tests. To make it fully real, the connection to the MQTT server doesn&amp;rsquo;t just use a bare TCP connection
but additionally encrypts it using TLS. So this is a full-on real scenario!&lt;/p&gt;

&lt;p&gt;The only aspect that
may not be accurate in some use-cases is that the MQTT server is located on the local network and
not somewhere across the internet. The latter case obviously adds latency and thus will keep the
esp32 awake longer. How much longer depends on the local internet connection, the
distance to the server, and the server load.&lt;/p&gt;

&lt;p&gt;I had not set-up TLS for my local MQTT server, which runs mosquitto, so I took advantage of that
to skip public key crypto and go straight to the PSK key cipher suites, which are new to me.&lt;/p&gt;

&lt;p&gt;The more traditional path using public key crypto is to generate a root certifacte
authority (CA), then generate a cert/private-key combo for the server so the client can auth the
server. And then to either use name/password to auth the client to the server or to generate a
cert/key combo for each client as well. After a while this becomes unwieldy, plus the public
crypto involved is quite heavy, i.e. slow.&lt;/p&gt;

&lt;h3 id=&#34;tls-using-pre-shared-key-cipher-suites&#34;&gt;TLS using pre-shared key cipher suites&lt;/h3&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/mqtt-psk.png# fr w-40pct ml3&#34; alt=&#34;TLS PSK&#34; /&gt;
&lt;em&gt;Openssl output for TLS PSK connection from esp32&lt;/em&gt;
PSK stands for pre-shared key and means that the client and server share a key. This replaces all
the certs and private keys.
In addition to the PSK, the client also has a string ID,
and the entire set-up is not more involved than assigning each client an ID and a randomly generated key.
Practically the same as assigning each client a name/password combo, but more powerful and secure.&lt;/p&gt;

&lt;p&gt;Using the PSK cipher suites the client authenticates the server because the server has to prove that
it knows the key. Similarly the server authenticates the client using this key.
In this process the key itself is
never transmitted, so attempting to connect to the wrong server does not reveal the key. In the
end the client and server negotiate an encrypted connection just like with the more common
public key cipher suites.&lt;/p&gt;

&lt;p&gt;The esp32 framework (ESP-IDF) uses mbed TLS and conveniently it supports the PSK cipher suites, they
just need to be enabled. I prepared a pull-request for the arduino framework and as of Dec 3rd the
PSK cipher suites are supported in the git master version of the framework (easy to install using
platformio&amp;rsquo;s &amp;ldquo;staging&amp;rdquo; version of the framework).&lt;/p&gt;

&lt;h3 id=&#34;test-application&#34;&gt;Test application&lt;/h3&gt;

&lt;p&gt;As a test I use a &lt;a href=&#34;https://github.com/tve/low-power-wifi/tree/master/esp32-deep-sleep-mqtts&#34;&gt;simple app&lt;/a&gt;
that connects to Wifi, connects to the mqtt server, subscribes to a
topic, then publishes a short message to that topic and finally waits for the message to come back
on the subscription.
This simulates a use-case where the esp32 periodically wakes up, takes a measurement and sends it to
the MQTT server, but also subscribes to a topic so it can be sent commands to make changes or
perhaps to stay awake and accept interactive commands for a period of time.&lt;/p&gt;

&lt;p&gt;The first text output of the app is shown below. The duration labeled &amp;ldquo;Mqtt&amp;rdquo; is from start-up to
connecting to the MQTT server, including crypto. The duration labeled &amp;ldquo;Sleep&amp;rdquo; then further includes
subscribing, publishing, and waiting for the return message.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;===== Deep sleep MQTT test starting =====
Wifi connect in 948ms
Mode 3, Init 18 ms, Wifi 948 ms, Mqtt 977 ms, seq=138, SSID test, IDF v3.2-dev-39-gaaf12390
Sleep at 1001 ms
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;A scope capture of this process looks as follows:&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/esp32-deep-sleep-mqtt-annot.png&#34; alt=&#34;ESP32 deep sleep and MQTT scope capture&#34; /&gt;
&lt;em&gt;Scope capture of the esp32 waking from deep sleep and doing pub-sub with an MQTT server over TLS.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Here is becomes obvious that Wifi is fast: the added time compared to the simplest TCP connection is
at most 100ms, i.e. less than 10% of the total. So as long as the server is fast at responding it
doesn&amp;rsquo;t really matter what the esp32 does once it has gone through all the trouble of associating
with the access point. (I should caution that using public key crypto may take longer, I didn&amp;rsquo;t try.)&lt;/p&gt;

&lt;p&gt;The &lt;a href=&#34;https://blog.voneicken.com/2018/lp-wifi-esp32-boards&#34;&gt;next post&lt;/a&gt; takes a look at my quest for a low-power esp32 board.&lt;/p&gt;</description>
		</item>
		
		<item>
			<title>ESP32 Deep-Sleep with Periodic Wake-up</title>
			<link>https://blog.voneicken.com/2018/lp-wifi-esp32-2/</link>
			<pubDate>Tue, 27 Nov 2018 00:00:00 UTC</pubDate>
			<author>Thorsten von Eicken</author>
			<guid>https://blog.voneicken.com/2018/lp-wifi-esp32-2/</guid>
			<description>&lt;p&gt;The long probing for the access point can be optimized away. In addition, it&amp;rsquo;s not smart to use
open access points, so it&amp;rsquo;s time to measure the cost of security!
&lt;/p&gt;

&lt;h3 id=&#34;optimizing-the-probing&#34;&gt;Optimizing the probing&lt;/h3&gt;

&lt;p&gt;Mode 3 in
the &lt;a href=&#34;https://github.com/tve/low-power-wifi/tree/master/esp32-deep-sleep&#34;&gt;test sketch&lt;/a&gt;
specifies all possible Wifi parameters in &lt;code&gt;WiFi.begin()&lt;/code&gt; and &lt;code&gt;WiFi.config()&lt;/code&gt;
and therefore runs much faster:&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/esp32-deep-sleep-open-mode-3-all-annot.png&#34; alt=&#34;ESP32 deep sleep scope capture&#34; /&gt;
&lt;em&gt;Scope capture of the esp32 waking from deep sleep and making a TCP connection to a server.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The sketch changed a little bit for this scope capture and creates two shorter &amp;ldquo;blips&amp;rdquo; on the
yellow trace instead of a single long one:
one blip at the start of &lt;code&gt;setup()&lt;/code&gt; until just before calling &lt;code&gt;Wifi.begin()&lt;/code&gt; and a second starting when
&lt;code&gt;WiFi.status()&lt;/code&gt; reports that it is connected (has an IP address) until just before calling
deep-sleep.&lt;/p&gt;

&lt;p&gt;There are two things that immediately stand out on this trace. The first is that it takes longer for
the esp32 firmware to start-up (~270ms) than it takes for the sketch to fire-up Wifi and do its TCP
connection (~200ms)! I asked and was told by &lt;code&gt;@me-no-dev&lt;/code&gt; that this is due to the extensive chip/memory
verification that occurs at boot time and that I wasn&amp;rsquo;t missing some magic setting. The impact on
total power consumption is definitely noticeable but not quite as bad as it might seem at first
because the power consumption is much lower during this start-up period than during the active
portion.&lt;/p&gt;

&lt;p&gt;The second noticeable aspect of this trace is that probing &lt;em&gt;still&lt;/em&gt; takes the majority of the time and
includes a long idle period. I have to admit that I just don&amp;rsquo;t quite understand the intricacies of
probing&amp;hellip; The overall packet trace is quite sweet and instructive:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  117 37.633s -&amp;gt; Probe Request (test) [5.5* 11.0* 1.0* 2.0* 6.0 12.0 2 4.0 48.0 Mbit]
  119 37.637s &amp;lt;- Request who-has 192.168.0.130 tell 192.168.0.2, length 46
  120 37.638s -&amp;gt; Acknowledgment
  121 37.638s &amp;lt;- Probe Response (test) [1.0* 2.0* 5.5* 11.0* 6.0 9.0 1 2.0 18.0 Mbit] CH: 6
  122 37.639s -&amp;gt; Acknowledgment
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This was the probing! It took 121ms if we look at the time of the next packet in the dump below.
This matches the scope trace. The actual packets are a little odd: the first is the expected probe request
kicking things off, but then comes an ARP request from the server we&amp;rsquo;re going to contact!
This is really the server trying to get a MAC address to send some
FIN packets from the previous sketch iteration. What&amp;rsquo;s odd is that &lt;em&gt;the esp32 answers&lt;/em&gt; with
an ACK in packet 120. There is no ARP reply, though, which makes sense since it hasn&amp;rsquo;t really
associated with the AP yet.
So somehow more than expected of the Wifi stack must be hooked-up even though there is no
association, I wonder whether there&amp;rsquo;s an attack vector buried in here&amp;hellip;&lt;/p&gt;

&lt;p&gt;Quickly thereafter comes a probe response and ACK. What I don&amp;rsquo;t understand, again, is why this is
followed by a ~110ms pause. It seems to me that the esp32 should not be waiting since it found the
AP specified in &lt;code&gt;WiFi.begin()&lt;/code&gt;.
(I posted a &lt;a href=&#34;https://www.esp32.com/viewtopic.php?f=2&amp;amp;t=8202&#34;&gt;question&lt;/a&gt; on the Espressif Esp32 forum,
let&amp;rsquo;s see&amp;hellip;)&lt;/p&gt;

&lt;p&gt;The next set of packets associate, send gratuitous ARPs, and locate the MAC address of the server.
All in all this takes 21ms:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  125 37.754s -&amp;gt; Authentication (Open System)-1: Successful
  126 37.755s &amp;lt;- Acknowledgment
  127 37.759s &amp;lt;- Authentication (Open System)-2:
  128 37.760s -&amp;gt; Acknowledgment
  129 37.761s -&amp;gt; Assoc Request (test) [5.5* 11.0* 1.0* 2.0* 6.0 12.0 2 4.0 48.0 Mbit]
  130 37.762s &amp;lt;- Acknowledgment
  131 37.764s &amp;lt;- Assoc Response AID(1) :: Successful
  132 37.765s -&amp;gt; Acknowledgment
  133 37.767s -&amp;gt; Request who-has 192.168.0.130 tell 192.168.0.130, length 28
  134 37.768s &amp;lt;- Acknowledgment
  135 37.768s -&amp;gt; Request who-has 192.168.0.130 tell 192.168.0.130 , length 28
  136 37.769s &amp;lt;- Acknowledgment
  137 37.770s -&amp;gt; Request who-has 192.168.0.2 tell 192.168.0.130, length 28
  138 37.771s &amp;lt;- Acknowledgment
  139 37.773s -&amp;gt; Request who-has 192.168.0.130 tell 192.168.0.130, length 28
  140 37.774s -&amp;gt; Request who-has 192.168.0.2 tell 192.168.0.130, length 28
  141 37.774s &amp;lt;- Reply 192.168.0.2 is-at b8:97:5a:90:54:5a, length 46
  142 37.775s -&amp;gt; Acknowledgment
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now the TCP connection can occur:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  143 37.776s -&amp;gt; 192.168.0.130.50114 &amp;gt; 192.168.0.2.12345: Flags [S], seq 6509, win 5744, options [mss 1436], length 0
  144 37.777s &amp;lt;- Acknowledgment
              &amp;lt;- [Missed TCP SYN-ACK]
  145 37.782s -&amp;gt; Acknowledgment
  146 37.783s -&amp;gt; 192.168.0.130.50114 &amp;gt; 192.168.0.2.12345: Flags [.], ack 1120519907, win 5744, length 0
  147 37.784s &amp;lt;- Acknowledgment
  148 37.785s -&amp;gt; 192.168.0.130.50114 &amp;gt; 192.168.0.2.12345: Flags [P.], seq 0:87, ack 1, win 5744, length 87
  149 37.786s &amp;lt;- Acknowledgment
  150 37.787s -&amp;gt; 192.168.0.130.50114 &amp;gt; 192.168.0.2.12345: Flags [F.], seq 87, ack 1, win 5744, length 0
  151 37.787s &amp;lt;- Acknowledgment
              &amp;lt;- [Missed TCP ACK]
  152 37.791s -&amp;gt; Acknowledgment
              &amp;lt;- [Missed TCP FIN]
  153 37.791s -&amp;gt; Acknowledgment
  154 37.792s -&amp;gt; 192.168.0.130.50114 &amp;gt; 192.168.0.2.12345: Flags [.], ack 2, win 5743, length 0
  155 37.793s &amp;lt;- Acknowledgment
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And it&amp;rsquo;s a wrap! Other than the pause after the probe response and the two rounds of ARP requests
because my linux server is lazy in responding all this looks about as good as one might expect!&lt;/p&gt;

&lt;h3 id=&#34;secure-access-point&#34;&gt;Secure access point&lt;/h3&gt;

&lt;p&gt;Does security run into the same power increase as it does with the esp8266?
The following scope trace answers this question:&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/esp32-deep-sleep-secure-mode-3-all-annot.png&#34; alt=&#34;ESP32 deep sleep scope capture&#34; /&gt;
&lt;em&gt;Scope capture of the esp32 waking from deep sleep and making a TCP connection to a server on
a secure (WPA2) Wifi network.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Yes, we still have to pay a price when we choose security!
(Note the 200ms/div here vs. 50ms/div in the open-AP scope capture further up.)
The primary difference with respect to the open
access point trace is the approx 700ms period of elevated power consumption between the end of the
probes and the association (I verified this with a packet dump).
I can only surmise that this is some crypto calculation but I spent quite some time
looking through the WPA2-PSK standard and all the crypto key exchange happens way later.
Unless there is something that can be pre-computed or perhaps some random number
initialization I don&amp;rsquo;t quite grasp what is going on.
I posted another &lt;a href=&#34;https://www.esp32.com/viewtopic.php?f=2&amp;amp;t=8203&#34;&gt;question&lt;/a&gt; on the Espressif Esp32 forum,
let&amp;rsquo;s see whether anyone can provide an insight.&lt;/p&gt;

&lt;h3 id=&#34;power-calculations&#34;&gt;Power calculations&lt;/h3&gt;

&lt;p&gt;The following table and chart show the expected run-times on a 1000mAh battery assuming wake-up intervals
from once per hour down to once every 20 seconds. The &amp;ldquo;open&amp;rdquo; columns refer to open access points and
&amp;ldquo;secure&amp;rdquo; to WPA2-PSK. The &amp;ldquo;act%&amp;rdquo; columns refer to the percent of total power consumption that comes
from the active period (startup+wake).&lt;/p&gt;

&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;right&#34;&gt;sleep [min]&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;open [mA]&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;open [days]&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;open [act%]&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;secure [mA]&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;secure [days]&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;secure [act%]&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;

&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;right&#34;&gt;60&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0.02&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;2040.8&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;51%&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0.04&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;952.4&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;77%&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td align=&#34;right&#34;&gt;10&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0.07&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;574.7&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;86%&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0.21&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;196.1&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;95%&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td align=&#34;right&#34;&gt;1&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0.64&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;65.6&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;98%&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;2.04&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;20.5&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;100%&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td align=&#34;right&#34;&gt;0.33&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;1.90&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;21.9&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;99%&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;6.15&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;6.8&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;100%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/ESP32 Deep-Sleep with Periodic Wake-up.png# fr w-60pct nocaption&#34; alt=&#34;ESP32 Deep-Sleep with Periodic Wake-up&#34; /&gt;&lt;/p&gt;

&lt;p&gt;The assumptions underlying the table and chart are:&lt;/p&gt;

&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;metric&lt;/th&gt;
&lt;th&gt;value&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;

&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;startup [mA]&lt;/td&gt;
&lt;td&gt;50&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;running [mA]&lt;/td&gt;
&lt;td&gt;120&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;sleeping [mA]&lt;/td&gt;
&lt;td&gt;0.01&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;startup [ms]&lt;/td&gt;
&lt;td&gt;270&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;open wake [ms]&lt;/td&gt;
&lt;td&gt;200&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;secure wake [ms]&lt;/td&gt;
&lt;td&gt;900&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;The following scope capture adds a purple trace showing the power consumption integral.
This shows that the majority of the power is spent when the esp32 is running actively at 125-150mA.
The 270ms at start-up don&amp;rsquo;t add a significant amount to the power consumption, but they do add a
potentially problematic delay if the wake-up is caused by some external event (i.e. gpio input) and
the esp32 needs to react quickly to it.&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/esp32-deep-sleep-secure-mode-3-all-power.png&#34; alt=&#34;ESP32 deep sleep scope capture&#34; /&gt;
&lt;em&gt;Scope capture of wake-up with secure AP with power consumption integral added in purple.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Going back to the original goal of achieving a run-time of a week to a month on a 1000mAh battery
the esp32 provides a number of options when using the deep-sleep mode. Specifically, it can wake up
every 20 seconds when using an open access point (not really recommended!) and every minute when
using a secure access point.&lt;/p&gt;

&lt;p&gt;The &lt;a href=&#34;https://blog.voneicken.com/2018/lp-wifi-esp32-mqtt&#34;&gt;next post&lt;/a&gt; goes a step further and explores what happens if the esp32
makes a TLS connection to an MQTT server and sends &amp;amp; receives some messages.&lt;/p&gt;

&lt;h3 id=&#34;addendum&#34;&gt;Addendum&lt;/h3&gt;

&lt;p&gt;The esp32 provides an additional explicit light-sleep mode that has not been
explored here and that is closely related to deep-sleep.
Explicit light-sleep puts the cpu and radio into light-sleep mode for a fixed duration just
like deep-sleep does, but it preserves memory content. This allows the periodic wake-up to be
implemented without loosing memory state but at the cost of higher power consumption. The Wifi has
to be turned off prior to entering light-sleep, so the wake-cycle power is expected to be very similar
to the deep-sleep case since most of the power is spent on connecting to Wifi (especially in the
secure network case).&lt;/p&gt;</description>
		</item>
		
		<item>
			<title>Low-Power Wifi with the ESP32</title>
			<link>https://blog.voneicken.com/2018/lp-wifi-esp32-1/</link>
			<pubDate>Mon, 26 Nov 2018 00:00:00 UTC</pubDate>
			<author>Thorsten von Eicken</author>
			<guid>https://blog.voneicken.com/2018/lp-wifi-esp32-1/</guid>
			<description>&lt;p&gt;The esp32 is the successor of the esp8266 by Espressif. It is much faster, has two cores, more
memory, more I/O, more everything. Does it also have more low-power Wifi mojo?&lt;/p&gt;

&lt;h3 id=&#34;experimental-set-up&#34;&gt;Experimental set-up&lt;/h3&gt;

&lt;p&gt;To test this I used an experimental set-up that is basically the same as with the esp8266.&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/esp32-set-up.jpg# fr w-40pct ml-3&#34; alt=&#34;Experimental set-up&#34; /&gt;&lt;/p&gt;

&lt;p&gt;The set-up I use is as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;an Adafruit Huzzah32 powered by a LiPo, modified to lower the deep-sleep current to 250uA,&lt;/li&gt;
&lt;li&gt;a jumper hacked into the Huzzah32&amp;rsquo;s battery ground connector to measure the supply current,&lt;/li&gt;
&lt;li&gt;a uCurrent Gold to amplify the current (a 1 Ohm resistor would have probably done just fine given
the magnitude of the currents), and&lt;/li&gt;
&lt;li&gt;an oscilloscope to measure the current and a probe on the LED gpio pin to trigger the scope.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The Wifi set-up is identical to the one used for the esp8266 tests.&lt;/p&gt;

&lt;h3 id=&#34;deep-sleep&#34;&gt;Deep-Sleep&lt;/h3&gt;

&lt;p&gt;The esp32 promises to complete each wake-cycle in less time than the esp8266 thanks to its faster
dual cores. Is that really the case or will it simply consume more power as it waits for Wifi responses?&lt;/p&gt;

&lt;p&gt;Again, only experimentation provides an answer. The &lt;a href=&#34;https://github.com/tve/low-power-wifi/tree/master/esp32-deep-sleep&#34;&gt;test
sketch&lt;/a&gt; uses the Arduino framework and a
pre-release version of ESP-IDF v3.2 underneath. The code is adapted from the esp8266 version,
changing a few portions that were esp8266 specific. One notable difference is that the local port
number gets selected randomly automatically, so that&amp;rsquo;s one less work-around in the app code.&lt;/p&gt;

&lt;p&gt;The code has the same 4 modes as the esp8266 version.
They differ in the amount of information passed into the Wifi initialization functions
&lt;code&gt;WiFi.begin&lt;/code&gt; and &lt;code&gt;WiFi.config&lt;/code&gt;:&lt;/p&gt;

&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;center&#34;&gt;mode&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;ssid, passwd&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;channel, bssid&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;ip, mask, gw, dns&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;

&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;0&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;✔&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;1&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;✔&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;✔&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;2&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;✔&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;✔&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;3&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;✔&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;✔&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;✔&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;A quick look at the messages sent to the server shows the following:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Mode 0, Init 17 ms, Connect 798 ms, Total 815 ms, SSID test, IDF v3.2-dev-39-gaaf12390
Mode 1, Init 17 ms, Connect 205 ms, Total 222 ms, SSID test, IDF v3.2-dev-39-gaaf12390
Mode 2, Init 17 ms, Connect 766 ms, Total 783 ms, SSID test, IDF v3.2-dev-39-gaaf12390
Mode 3, Init 17 ms, Connect 163 ms, Total 180 ms, SSID test, IDF v3.2-dev-39-gaaf12390
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;We see the same behavior as with the esp8266 where modes that don&amp;rsquo;t specify the channel/BSSID (0 &amp;amp; 2) take
significantly longer than modes that do (1 &amp;amp; 3). The times for the slow modes are less than half of
those for the esp8266, so that&amp;rsquo;s good news. The not-so-good news is that the fast modes take
almost the same time.&lt;/p&gt;

&lt;h3 id=&#34;open-access-point&#34;&gt;Open access point&lt;/h3&gt;

&lt;p&gt;Diving past the numbers in the table above, here is a scope capture of what mode 0 (specify only
SSID in &lt;code&gt;Wifi.begin()&lt;/code&gt;) on an open access point looks like:&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/esp32-deep-sleep-open-mode-0-all-annot.png&#34; alt=&#34;ESP32 deep sleep scope capture&#34; /&gt;
&lt;em&gt;Scope capture of the esp32 waking from deep sleep and making a TCP connection to a server.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Given what we know from the esp8266 we can immediately assume that the long section (marked &amp;ldquo;probes&amp;rdquo;)
corresponds to the esp32 probing all the channels. A packet dump confirms this assumption
and overall looks as one might expect, so I won&amp;rsquo;t reproduce it here in its entirety.&lt;/p&gt;

&lt;p&gt;Looking at packet dumps I kept stumbling over oddities during probing. One of them is that the esp32
does not reliably ACK probe responses from the AP even though all other packets I see are ACKed
reliably.
Here is a snippet that shows it (&amp;ldquo;-&amp;gt;&amp;rdquo; refers to TX and &amp;ldquo;&amp;lt;-&amp;rdquo; to RX from the esp32 perspective):&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;              -&amp;gt; [Missed initial probe request]
  107 56.431s &amp;lt;- Probe Response (test) [1.0* 2.0* 5.5* 11.0* 6.0 9.0 1 2.0 18.0 Mbit] CH: 6
  108 56.432s &amp;lt;- Probe Response (test) [1.0* 2.0* 5.5* 11.0* 6.0 9.0 1 2.0 18.0 Mbit] CH: 6
  109 56.434s &amp;lt;- Probe Response (test) [1.0* 2.0* 5.5* 11.0* 6.0 9.0 1 2.0 18.0 Mbit] CH: 6
  110 56.435s &amp;lt;- Probe Response (test) [1.0* 2.0* 5.5* 11.0* 6.0 9.0 1 2.0 18.0 Mbit] CH: 6
  111 56.437s &amp;lt;- Probe Response (test) [1.0* 2.0* 5.5* 11.0* 6.0 9.0 1 2.0 18.0 Mbit] CH: 6
  112 56.438s &amp;lt;- Probe Response (test) [1.0* 2.0* 5.5* 11.0* 6.0 9.0 1 2.0 18.0 Mbit] CH: 6
  113 56.440s &amp;lt;- Probe Response (test) [1.0* 2.0* 5.5* 11.0* 6.0 9.0 1 2.0 18.0 Mbit] CH: 6
  116 56.546s -&amp;gt; Probe Request (test) [5.5* 11.0* 1.0* 2.0* 6.0 12.0 2 4.0 48.0 Mbit]
  117 56.551s &amp;lt;- Probe Response (test) [1.0* 2.0* 5.5* 11.0* 6.0 9.0 1 2.0 18.0 Mbit] CH: 6
  118 56.553s -&amp;gt; Acknowledgment
  119 56.556s &amp;lt;- Probe Response (test) [1.0* 2.0* 5.5* 11.0* 6.0 9.0 1 2.0 18.0 Mbit] CH: 6
  120 56.558s &amp;lt;- Probe Response (test) [1.0* 2.0* 5.5* 11.0* 6.0 9.0 1 2.0 18.0 Mbit] CH: 6
  121 56.559s &amp;lt;- Probe Response (test) [1.0* 2.0* 5.5* 11.0* 6.0 9.0 1 2.0 18.0 Mbit] CH: 6
  122 56.561s -&amp;gt; Acknowledgment
  125 56.667s -&amp;gt; Probe Request (test) [5.5* 11.0* 1.0* 2.0* 6.0 12.0 2 4.0 48.0 Mbit]
  126 56.672s &amp;lt;- Probe Response (test) [1.0* 2.0* 5.5* 11.0* 6.0 9.0 1 2.0 18.0 Mbit] CH: 6
  127 56.674s -&amp;gt; Acknowledgment
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Specifically, packets 108 through 113 are retransmissions from the AP because the esp32 doesn&amp;rsquo;t
respond with a Wifi ACK. Another oddity is that even after the esp32 ACKs a response (packets
117-118) it sends a fresh probe request later on (packet 125).&lt;/p&gt;

&lt;p&gt;I puzzled over this for a long time and eventually reached the following hypothesis:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;When the esp32 has to probe multiple channels it can only do so on one channel at a time, so it
may miss whole sets of responses due to switching away to the next channel. (My captures are
single-channel only.)&lt;/li&gt;
&lt;li&gt;The probing tries to discover &lt;em&gt;all&lt;/em&gt; APs for the given SSID so it can pick the best one and
therefore it goes through a certain number of request rounds and fixed wait periods
even if some AP has already responded.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I&amp;rsquo;m sure there are additional nuances I&amp;rsquo;m not understanding, if you have more info I&amp;rsquo;d appreciate if
you could leave a comment!&lt;/p&gt;

&lt;p&gt;The &lt;a href=&#34;https://blog.voneicken.com/2018/lp-wifi-esp32-2&#34;&gt;next post&lt;/a&gt; optimizes away the probing and switches some security on.&lt;/p&gt;</description>
		</item>
		
		<item>
			<title>ESP8266 Maintaining an Association</title>
			<link>https://blog.voneicken.com/2018/lp-wifi-esp8266-assoc/</link>
			<pubDate>Sun, 25 Nov 2018 00:00:00 UTC</pubDate>
			<author>Thorsten von Eicken</author>
			<guid>https://blog.voneicken.com/2018/lp-wifi-esp8266-assoc/</guid>
			<description>&lt;p&gt;In automatic light-sleep mode the esp8266 goes to sleep when there is no activity. From there it can
wake-up due to a timer or due to Wifi activity.
&lt;/p&gt;

&lt;p&gt;Used on its own, light-sleep mode wakes up according to the access point&amp;rsquo;s DTIM setting, i.e., the
period at which beacons contain a map of pending packets. In a recent SDK Espressif added a
twist on this that enables the application to specify the period explicitly, in which case the access
point&amp;rsquo;s setting is ignored. This allows the esp8266 to control its wake-up interval instead of being
at the mercy of the settings in the access point.&lt;/p&gt;

&lt;p&gt;The assumption behind the explicit interval setting is that the access point most likely keeps
pending packets around for a while before discarding them. In theory, it only has to keep them for a
DTIM period but when the network is congested that&amp;rsquo;s most likely too short anyway.&lt;/p&gt;

&lt;p&gt;The &lt;a href=&#34;https://github.com/tve/low-power-wifi/tree/master/esp8266-light-sleep&#34;&gt;test sketch&lt;/a&gt;
starts by connecting to the access point and putting the esp8266 into light-sleep mode with an
interval of 5 beacons, i.e., 500ms. The &lt;code&gt;loop()&lt;/code&gt; then consists of setting a gpio pin to high to
trigger the scope, opening a TCP connection to a test server, sending some data, and closing the
connection. It then sets the gpio pin to low and calls &lt;code&gt;delay(2000)&lt;/code&gt;. At that point there&amp;rsquo;s nothing
more for the esp8266 to do so we expect it to go into light sleep mode for 2 seconds, interrupted
only by the periodic wake-up every 500ms to catch a beacon.&lt;/p&gt;

&lt;p&gt;So long for the theory, the following screen capture shows what happens in practice. This is using
an open access point for starters.&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/esp8266-light-sleep-open-all.png&#34; alt=&#34;Light sleep&#34; /&gt;
&lt;em&gt;Scope capture of 12 seconds in automatic light sleep mode with a &lt;code&gt;loop()&lt;/code&gt; iteration in the middle.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The yellow trace shows the gpio pin which very briefly goes high in the center of the capture (not really
visible). Each horizontal division corresponds to one second, the full capture lasts 12 seconds. The
blue trace shows power consumption at 20mA per vertical division.&lt;/p&gt;

&lt;p&gt;In the blue trace there are power spikes up to about 75mA clearly visible every 500ms.
These correspond to the wake-ups where the esp8266 catches a beacon.
Some of these spikes last longer (see green arrows) and contain some faint TX power spikes.
These correspond to periods where the beacon contains a flag that there&amp;rsquo;s
a packet pending and then the esp8266 asks for the packet to be delivered.
In the middle of the trace more transmission activity can be seen, which is when the &lt;code&gt;loop()&lt;/code&gt;
iteration occurs. It is also noticeable by the fact that it&amp;rsquo;s offset with respect to the regular
500ms wake-ups.&lt;/p&gt;

&lt;p&gt;So far everything looks as expected, but the power consumption when in sleep mode is not as
expected! In this particular capture, half the time when the esp8266 powers down after a beacon it
goes into light-sleep mode consuming less than 2mA. The the other half of the time it goes into
modem-sleep, which consumes about 16mA, ouch! Other captures show a different pattern and sometimes
more than half the time is spent in modem-sleep.
As we will see, this frequent operation at 16mA really eats into the run-time!&lt;/p&gt;

&lt;h3 id=&#34;wake-cycle-activity&#34;&gt;Wake-cycle activity&lt;/h3&gt;

&lt;p&gt;The following screen capture zooms in on the activity in the middle of the previous capture where
the &lt;code&gt;loop()&lt;/code&gt; iteration and corresponding TCP connection occur.&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/esp8266-light-sleep-open-zoom.png&#34; alt=&#34;Light sleep magnified&#34; /&gt;
&lt;em&gt;Scope capture of a &lt;code&gt;loop()&lt;/code&gt; iteration.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Towards the left the blue power trace shows a wake-up for a beacon. It lasts about 15ms and
evidently there was no packet to retrieve. Afterwards the esp8266 goes into modem-sleep until the
loop delay expires. As it wakes up the yellow trace shows the &lt;code&gt;loop()&lt;/code&gt; iteration lasting roughly
30ms and the blue trace shows a lot of Wifi activity, as we would expect. But when the sketch goes
back to sleep, the esp8266 does not power down, instead it lingers in high power mode for about
80ms, transmits a packet and goes to sleep (this time into light-sleep).&lt;/p&gt;

&lt;p&gt;Here is another capture, this time zooming in on a beacon where the access point had a packet to
deliver to the esp8266:&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/esp8266-light-sleep-open-beacon.png&#34; alt=&#34;Light sleep magnified&#34; /&gt;
&lt;em&gt;Scope capture of a beacon with data to be delivered.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Somehow there are three transmissions involved in receiving the pending packet.
The best way to understand what is happening is to look at a packet capture:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  125   0.304s &amp;lt;- Beacon (test)
  126   0.307s -&amp;gt; Null data packet
  127   0.307s &amp;lt;- Acknowledgment
               &amp;lt;- [Missing ICMP echo request packet]
  128   0.314s -&amp;gt; Acknowledgment
  129   0.316s &amp;lt;- 192.168.0.106 &amp;gt; 192.168.0.2: ICMP echo reply
  130   0.316s -&amp;gt; Acknowledgment
  132   0.396s -&amp;gt; Null data packet
  133   0.396s &amp;lt;- Acknowledgment
  134   0.407s &amp;lt;- Beacon (test)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The first packet is a beacon that presumably contains a flag telling the esp8266 that there is a
packet pending. 3ms later the esp8266 requests packet delivery by sending an empty data packet with
a header flag set to indicate that it is exiting power save mode, i.e., it is now receiving
continuously, which means that the AP can send stored packets and any additional incoming ones at will.&lt;/p&gt;

&lt;p&gt;After the Wifi-level ACK of the power-save-end packet the AP sends the data packet, which is an ICMP
ping request. Unfortunately the monitoring adapter missed it but one can see the ACK from the
esp8266 immeditaely after. Just 2ms later the esp8266 responds with an ICMP reply packet, which gets
ACKed. At this point the esp8266 doesn&amp;rsquo;t know whether the AP has additional packets stored for it,
so it has to wait for &amp;ldquo;some time&amp;rdquo; to give the AP a chance to transmit them. From the timing column
it is evident that 80ms go by until the esp8266 sends another packet (number 132), which is another
empty data packet but this time with a power-save start flag telling the AP to buffer up any
packets. The last two packets are the ACK for the empty data packet and then some time later the
next beacon comes in.&lt;/p&gt;

&lt;p&gt;The 80ms of delay are very consistent and can be seen both in this packet capture as well as the
scope capture above (the two don&amp;rsquo;t show the exact same events).&lt;/p&gt;

&lt;p&gt;I also looked at the performance when using a secure access point and surprisingly there is no
change in behavior to be seen. The TCP packet exchange may be happening a tad slower but when
looking at two traces side-by-side it is impossible to distinguish the two.&lt;/p&gt;

&lt;h3 id=&#34;putting-it-all-together&#34;&gt;Putting it all together&lt;/h3&gt;

&lt;p&gt;From all evidence the esp8266&amp;rsquo;s automatic light sleep mode operates more or less as expected, but
there is at least one bug and one unexpected issue:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;setting a light sleep interval causes the esp8266 to indeed go to sleep for the requested period
between brief wake cycles to catch a beacon&lt;/li&gt;
&lt;li&gt;there is a clear bug in that after a wake-cycle the esp8266 does not systematically go to
light-sleep mode and instead only goes into modem-sleep where it consumes 10 times more power&lt;/li&gt;
&lt;li&gt;when the esp8266 is stuck in modem-sleep it stays there until the next wake-up for a beacon, this
means that the light-sleep interval setting is practically useless&lt;/li&gt;
&lt;li&gt;on the otherwise idle test Wifi network it takes very little time to wake-up, catch a beacon,
request packet delivery and receive the packet&lt;/li&gt;
&lt;li&gt;after receiving the pending packet(s), there is a 80ms extra penalty where the esp8266 lingers
with the receiver on, consuming around 70mA, before it goes back to sleep&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A major issue with the lingering is that it is incurred each time some packet arrives, which is not
under the control of the esp8266 or its application. In the example above I used an ICMP ping so I
could relatively easily capture the activity, but under normal circumstances if nothing wants to
talk to the esp8266 there is still a regular cadence of broadcast packets that come through and wake
the esp8266 up.&lt;/p&gt;

&lt;p&gt;A perhaps extreme test is to ping the esp8266 every second. In that case it never goes to sleep at
all, keeping the receiver going at 70mA full-time! What this highlights is that the esp8266 is
really at the mercy of the network environment and thus its battery run-time can be compromised by
completely unrelated activity.&lt;/p&gt;

&lt;p&gt;The following table and chart show the average power consumption and run-time on a 1000mAh battery in a
variety of scenarios. The &lt;em&gt;iter period&lt;/em&gt; column specifies the rate at which &lt;code&gt;loop()&lt;/code&gt; iterations run,
the &lt;em&gt;pkts per second&lt;/em&gt; specifies the number of beacon-induced wake-up periods there are per second,
the &lt;em&gt;ideal&lt;/em&gt; columns show the resulting average current and run-time if the esp8266 always properly
went to light-sleep and the &lt;em&gt;actual&lt;/em&gt; columns show a 50-50 mix of light-sleep and modem-sleep.&lt;/p&gt;

&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;right&#34;&gt;iter period [sec]&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;pkts per second&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;ideal [mA]&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;ideal [days]&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;actual [mA]&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;actual [days]&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;

&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;right&#34;&gt;1&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0.1&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;12.6&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;3.3&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;19.8&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;2.1&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td align=&#34;right&#34;&gt;10&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0.1&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;4.4&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;9.5&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;11.6&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;3.6&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td align=&#34;right&#34;&gt;60&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0.1&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;3.6&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;11.5&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;10.9&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;3.8&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td align=&#34;right&#34;&gt;1&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;1&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;17.6&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;2.4&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;24.9&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;1.7&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td align=&#34;right&#34;&gt;10&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;1&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;9.4&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;4.4&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;16.7&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;2.5&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/ESP8266 Light-Sleep Run-Time.png# nocaption&#34; alt=&#34;ESP8266 Light-Sleep Run-Time&#34; /&gt;&lt;/p&gt;

&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Operation&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;duration [ms]&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;current [mA]&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;

&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;light-sleep&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;500&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;1.5&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;modem-sleep&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;500&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;16&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;beacon check&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;10&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;70&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;lingering&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;80&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;70&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;loop iteration&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;50&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;70&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;floatpara&gt;&lt;/floatpara&gt;&lt;/p&gt;

&lt;p&gt;The assumed durations and consumption levels are shown in the table on the right.&lt;/p&gt;

&lt;p&gt;It is quite clear from the chart above that the light-sleep mode is significantly more power-hungry than
the deep-sleep modes explored in a previous blog post.
In order to get a run-time of more than a couple of days one has to somehow ensure that there are
only very few broadcast packets on the network and
achieving run-times longer than a week assume that Espressif will someday fix the light-sleep bugs.&lt;/p&gt;

&lt;p&gt;To get a better sense of where the power is going
the following table breaks down the % of power consumed in each mode for two of the rows above:&lt;/p&gt;

&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;right&#34;&gt;iter period [sec]&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;pkts per second&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;ideal [mA]&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;sleep [%pow]&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;beacon [%pow]&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;linger [%pow]&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;loop [%pow]&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;

&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;right&#34;&gt;10&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0.1&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;4.4&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;34%&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;32%&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;26%&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;8%&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td align=&#34;right&#34;&gt;10&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;1&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;9.4&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;16%&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;15%&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;65%&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;4%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;The first row corresponds to contacting a server every 10 seconds and receiving some broadcast
packet every 10 seconds as well.
The run-time, if light-sleep was operating properly, would be 9.5
days, which meets the &amp;ldquo;run for at least a week&amp;rdquo; goal.
Given the even distribution of power consumption there is not one thing one could fix to
reduce the power significantly.
The second row shows the same server-contact rate but a 10x higher broadcast rate.
In that operating regime the power consumed by lingering after a packet becomes the single largest
power hog.&lt;/p&gt;

&lt;h3 id=&#34;conclusion&#34;&gt;Conclusion&lt;/h3&gt;

&lt;p&gt;This concludes the analysis of the esp8266&amp;rsquo;s sleep modes.
It is pretty clear that keeping the esp8266 associated to an access point cannot be done with
run-times of more than about a week, unless one uses a sizeable battery. In addition, the actual
run-time is difficult to predict and may vary significantly over time because a lot depends on other
activity on the Wifi network.&lt;/p&gt;

&lt;p&gt;To achieve long run-times one has to use deep-sleep and wake-up only intermittently. In that case
the run-time can be predicted with reasonable accuracy, although the time it takes the esp8266 to
successfully associate with the AP at each wake-up may vary quite a bit.&lt;/p&gt;

&lt;p&gt;An unfortunate reality is that when using deep-sleep the power consumption and thus run-time
varies dramatically between open Wifi networks and secure networks.
Specifically, the penalty for security can be a factor of 10x!
In contrast, the light-sleep mode shows little difference between open and secure networks.&lt;/p&gt;

&lt;p&gt;My personal conclusion is that trying to use the esp8266 for long-term battery operation is a
recipe for headaches, except in very narrow use-cases.
The reason is a combination of the fact that it requires the use of
deep-sleep, which is painful for anything but trivial applications, and
that security requires rather long sleep intervals (not to mention its high memory requirements).&lt;/p&gt;

&lt;p&gt;The &lt;a href=&#34;https://blog.voneicken.com/2018/lp-wifi-esp32-1&#34;&gt;next post&lt;/a&gt; examines whether the Espressif Esp32 is a better choice for
low-power wifi operation.&lt;/p&gt;</description>
		</item>
		
		<item>
			<title>Low-Power Wifi using Power Save Mode</title>
			<link>https://blog.voneicken.com/2018/lp-wifi-association/</link>
			<pubDate>Sat, 24 Nov 2018 00:00:00 UTC</pubDate>
			<author>Thorsten von Eicken</author>
			<guid>https://blog.voneicken.com/2018/lp-wifi-association/</guid>
			<description>&lt;p&gt;Instead of disconnecting from the AP before going to sleep and then reassociating it is also
possible to maintain the association while going to sleep.&lt;/p&gt;

&lt;p&gt;This is made possible at the Wifi level by the Power Save Mode (PSM) which was included in the
original 802.11 standard. PSM leverages the periodic beacon sent out by access points and addresses
the problem of sending packets from the access point (AP) to low-power devices without requiring that the
device keep its receiver on all the time.
(Sending &lt;em&gt;to&lt;/em&gt; the access point is easy in that the device can TX at will.)&lt;/p&gt;

&lt;p&gt;In a nutshell, the AP does not transmit packets to low-power devices as soon as it receives them.
Instead, it buffers them and includes a flag for the specific device in its beacons.
The device then arranges timers so it wakes up just in time to turn RX on and receive the
beacon. If its flag is set, indicating that it has one or more packets pending at the AP,
the device sends a poll packet to the AP requesting delivery and the AP transmits the packet.&lt;/p&gt;

&lt;p&gt;The device doesn&amp;rsquo;t actually have to wake-up for each and every beacon, instead the Ap can be
configured to include the packet-pending flags only in every Nth beacon.
Often N=3 is used, which would be a wake-up every 300ms assuming a standard 100ms beacon interval.&lt;/p&gt;

&lt;p&gt;There is a newer very similar mode called WMM Power Save which operates according to the same
principle but instead of including a map in beacons the low-power device wakes up periodically at
whatever rate it chooses and sends a probe to the access point to prompt delivery of any buffered
packets. The upside is that the device can fully control the interval instead of being bound by the AP&amp;rsquo;s
beacon interval. The downside is that each wake-up requires a transmission instead of the
lower-consumption RX, although the TX duration is shorter than the RX duration necessary to ensure
reception of the beacon.&lt;/p&gt;

&lt;p&gt;There are additional modes, such as scheduled WMM Power Save and Power Save Multi-poll but they get
more complicated and I haven&amp;rsquo;t seen embedded devices using them.&lt;/p&gt;

&lt;p&gt;A fundamental problem with Power Save Mode is that unrelated activity on the network can cause
packets to be queued for delivery to the sleeping device, causing a wake-up.
This means that the device is not really in control of its own power consumption.
A simple example of such activity are the ARP requests seen in
the deep-sleep mode: suppose there are 20 esp8266&amp;rsquo;s on the network, each of which wakes up every 20
seconds. That would result in an ARP packet being broadcast every second on average as some esp8266
wakes up and tries to find its server. The result would be that an unrelated esp8266 in Power Save
Mode would get woken up once per second!&lt;/p&gt;

&lt;p&gt;All this means that how well power save mode works can only be answered by experimentation.
On the test bench, when using an isolated test-Wifi network, everything may look
perfect, but then in a real-world deployment the activity on the network can raise the power
consumption by orders of magnitude.&lt;/p&gt;

&lt;p&gt;The &lt;a href=&#34;https://blog.voneicken.com/2018/lp-wifi-esp8266-assoc&#34;&gt;next post&lt;/a&gt; describes experiments using the Espressif esp8266.&lt;/p&gt;</description>
		</item>
		
		<item>
			<title>ESP8266 with Optimized Periodic Wake-up</title>
			<link>https://blog.voneicken.com/2018/lp-wifi-esp8266-2/</link>
			<pubDate>Fri, 23 Nov 2018 00:00:00 UTC</pubDate>
			<author>Thorsten von Eicken</author>
			<guid>https://blog.voneicken.com/2018/lp-wifi-esp8266-2/</guid>
			<description>&lt;p&gt;This post dives into optimizing deep-sleep with periodic wakeup on the esp8266 and ends
with some calculations about expected run-time on battery.
&lt;/p&gt;

&lt;p&gt;(If you haven&amp;rsquo;t read the &lt;a href=&#34;https://blog.voneicken.com/2018/lp-wifi-esp8266-1&#34;&gt;previous post&lt;/a&gt; on the unoptimized version you probably
should go back so you understand my set-up.)&lt;/p&gt;

&lt;p&gt;The following scope capture shows the wake cycle after optimization.
The Wifi probes scanning all channels and the DHCP queries have disappeared.
Note the horizontal scale of 50ms per division. That means that everything happens in about
175 milliseconds! I also changed from &lt;code&gt;ESP.deepSleep()&lt;/code&gt; to &lt;code&gt;ESP.deepSleepImmediate()&lt;/code&gt; to avoid the
90ms of lingering at the end of the activity before cutting the power.&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/ap-test-mode-3-all-annot.png# w-100pct&#34; alt=&#34;Wake-up cycle&#34; /&gt;
&lt;em&gt;Scope capture of a full wake cycle passing all possible parameters to &lt;code&gt;WiFi.begin&lt;/code&gt; and &lt;code&gt;WiFi.connect&lt;/code&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Now that the horizontal scale is a bit bigger we can see that the
microcontroller initialization takes about 80-90ms. The Wifi
sequence then starts with a probe request on the correct channel followed by an immediate response
by the AP:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;0.788s -&amp;gt; Probe Request (test) [5.5* 11.0* 1.0* 2.0* 6.0 12.0 24.0 48.0 Mbit]
0.793s &amp;lt;- Probe Response (test) [1.0* 2.0* 5.5* 11.0* 6.0 9.0 12.0 18.0 Mbit] CH: 6
0.795s -&amp;gt; Acknowledgment RA:74:da:38:06:52:32
0.820s &amp;lt;- Beacon (test) [1.0* 2.0* 5.5* 11.0* 6.0 9.0 12.0 18.0 Mbit] ESS CH: 6
0.851s &amp;lt;- Beacon (test) [1.0* 2.0* 5.5* 11.0* 6.0 9.0 12.0 18.0 Mbit] ESS CH: 6
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;After a 114ms idle period comes the association exchange
which is not shown here because it is identical to the one in the unoptimized sketch
shown in the previous post.&lt;/p&gt;

&lt;p&gt;Because the sketch specifies the IP address for the esp8266 there is no DHCP exchange and the
esp8266 proceeds with some gratuitous ARPs to confirm that no-one else has its IP address.
It then requests the MAC address of the server for the TCP connection.
This entire ARP sequence is identical to the unoptimzed case.&lt;/p&gt;

&lt;p&gt;With MAC address in hand the esp8266 opens the TCP connection and should transfer the data but what
the capture shows is this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;0.938s -&amp;gt; IP 192.168.0.106.55779 &amp;gt; 192.168.0.2.12345: Flags [S], seq 6509, win 2144, options [mss 536,nop,nop,sackOK], length 0
0.939s &amp;lt;- Acknowledgment RA:5c:cf:7f:05:c0:db
0.940s -&amp;gt; Acknowledgment RA:74:da:38:06:52:32
0.942s -&amp;gt; IP 192.168.0.106.55779 &amp;gt; 192.168.0.2.12345: Flags [R.], seq 1, ack 1, win 24584, length 0
0.943s &amp;lt;- Acknowledgment RA:5c:cf:7f:05:c0:db
0.943s -&amp;gt; IP 192.168.0.106.55779 &amp;gt; 192.168.0.2.12345: Flags [S], seq 6509, win 2144, options [mss 536,nop,nop,sackOK], length 0
0.944s &amp;lt;- Acknowledgment RA:5c:cf:7f:05:c0:db
0.948s -&amp;gt; Acknowledgment RA:74:da:38:06:52:32
0.949s -&amp;gt; Acknowledgment RA:74:da:38:06:52:32
0.950s -&amp;gt; IP 192.168.0.106.55779 &amp;gt; 192.168.0.2.12345: Flags [.], ack 50581235, win 2144, length 0
0.951s &amp;lt;- Acknowledgment RA:5c:cf:7f:05:c0:db
0.951s -&amp;gt; IP 192.168.0.106.55779 &amp;gt; 192.168.0.2.12345: Flags [P.], seq 4294967212:0, ack 50581235, win 2144, length 84
0.953s &amp;lt;- Acknowledgment RA:5c:cf:7f:05:c0:db
0.953s &amp;lt;- Beacon (test) [1.0* 2.0* 5.5* 11.0* 6.0 9.0 12.0 18.0 Mbit] ESS CH: 6
0.963s -&amp;gt; Acknowledgment RA:74:da:38:06:52:32
0.965s -&amp;gt; IP 192.168.0.106.55779 &amp;gt; 192.168.0.2.12345: Flags [F.], seq 0, ack 50581235, win 2144, length 0
0.966s &amp;lt;- Acknowledgment RA:5c:cf:7f:05:c0:db
0.975s &amp;lt;- IP 192.168.0.2.12345 &amp;gt; 192.168.0.106.55779: Flags [F.], seq 50581235, ack 1, win 29200, length 0
0.983s &amp;lt;- IP 192.168.0.2.12345 &amp;gt; 192.168.0.106.55779: Flags [F.], seq 50581235, ack 1, win 29200, length 0
0.983s &amp;lt;- IP 192.168.0.2.12345 &amp;gt; 192.168.0.106.55779: Flags [F.], seq 50581235, ack 1, win 29200, length 0
0.992s &amp;lt;- IP 192.168.0.2.12345 &amp;gt; 192.168.0.106.55779: Flags [F.], seq 50581235, ack 1, win 29200, length 0
[a few dozen more of the same...]
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;It starts out with a TCP SYN (&lt;code&gt;Flags [S]&lt;/code&gt;) as expected and the back-to-back Acknowledgment packets
indicate that the monitoring adapter missed some packets but the odd part is the second TCP packet,
which is a connection reset (&lt;code&gt;Flags [R]&lt;/code&gt;). That&amp;rsquo;s not expected. And the third packet appears to be a new
SYN for a fresh connection.&lt;/p&gt;

&lt;p&gt;Another oddity is that at the end the server (192.168.0.2) sends a pile of FIN packets (&lt;code&gt;Flags
[F]&lt;/code&gt;), which indicates that the esp8266 has gone to sleep before the connection closed properly
and the server is trying to get an ACK for its FIN.
So basically the server is left hanging trying to finish closing the connection.&lt;/p&gt;

&lt;p&gt;I then looked at a longer capture that shows multiple wake cycles and noticed that the esp8266
uses the same source port (55779) each time! Now we can explain the connection reset: the server
can&amp;rsquo;t close the connection at the end of a wake-up cycle and the esp8266 then comes along at the next
cycle with the same &amp;lt;src IP, src port, dst IP, dst port&amp;gt; combination. To the server this
appears like a continuation of the not quite closed TCP connection, which results in a protocol
violation which the esp8266 eventually resolves using a TCP reset.&lt;/p&gt;

&lt;p&gt;Fortunately we can fix this little problem by setting the local port number before opening the
connection using &lt;code&gt;WiFi.setLocalPortStart()&lt;/code&gt; and then incrementing and remembering it in the RTC RAM.
The result is a clean TCP connection:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;0.851s -&amp;gt; IP 192.168.0.106.10008 &amp;gt; 192.168.0.2.12345: Flags [S], seq 6509, win 2144, options [mss 536,nop,nop,sackOK], length 0
0.851s &amp;lt;- Acknowledgment RA:5c:cf:7f:05:c0:db
0.856s &amp;lt;- IP 192.168.0.2.12345 &amp;gt; 192.168.0.106.10008: Flags [S.], seq 1790078284, ack 6510, win 29200, options [mss
0.op,sackOK], length 0
0.856s -&amp;gt; Acknowledgment RA:74:da:38:06:52:32
0.858s -&amp;gt; IP 192.168.0.106.10008 &amp;gt; 192.168.0.2.12345: Flags [.], ack 1, win 2144, length 0
0.859s &amp;lt;- Acknowledgment RA:5c:cf:7f:05:c0:db
0.859s -&amp;gt; IP 192.168.0.106.10008 &amp;gt; 192.168.0.2.12345: Flags [P.], seq 1:85, ack 1, win 2144, length 84
0.861s &amp;lt;- Acknowledgment RA:5c:cf:7f:05:c0:db
0.865s &amp;lt;- IP 192.168.0.2.12345 &amp;gt; 192.168.0.106.10008: Flags [.], ack 85, win 29200, length 0
0.865s -&amp;gt; Acknowledgment RA:74:da:38:06:52:32
0.867s -&amp;gt; IP 192.168.0.106.10008 &amp;gt; 192.168.0.2.12345: Flags [F.], seq 85, ack 1, win 2144, length 0
0.868s &amp;lt;- Acknowledgment RA:5c:cf:7f:05:c0:db
0.869s &amp;lt;- IP 192.168.0.2.12345 &amp;gt; 192.168.0.106.10008: Flags [F.], seq 1, ack 86, win 29200, length 0
0.869s -&amp;gt; Acknowledgment RA:74:da:38:06:52:32
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This connection uses local port 10008, the next wake up will use 10009 and so forth. In this
connection dump we see the expected SYN, SYN-ACK, ACK, 84-byte data packet, ACK, FIN, ACK-FIN.
Missing is a final ACK and I still see FIN retransmissions from the server later on, but at least
they don&amp;rsquo;t interfere with the next connection anymore.&lt;/p&gt;

&lt;p&gt;For comparison, the following capture shows the full activity period zoomed-in. (It doesn&amp;rsquo;t match
the previous packet dump exactly, I didn&amp;rsquo;t capture the same iteration this time.)&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/ap-test-mode-3-end2-annot.png&#34; alt=&#34;Wake-up cycle zoomed&#34; /&gt;
&lt;em&gt;Magnification of the activity portion of the wake cycle after fixing the local port numbers.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The vertical cursors show that the entire activity period lasts only 31 milliseconds
and the horizontal cursors show that the power draw is just around 70mA most of the time.
The total wake cycle still lasts 170-180ms primarily due to the wait-time after the probe requests.&lt;/p&gt;

&lt;h3 id=&#34;secure-access-points&#34;&gt;Secure access points&lt;/h3&gt;

&lt;p&gt;All the experiments so far have used an open unencrypted access point. This made the packet dump
analysis easy because all is in the clear. But it&amp;rsquo;s also insecure: everything is in the clear and
can be hijacked at will. What happens when using a secure access point?
The following scope capture shows the same sketch when using the same AP with a WPA2 encrypted SSID:&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/ap-secret-mode-3-all-annot.png# w-100pct&#34; alt=&#34;Wake-up cycle with secure AP&#34; /&gt;
&lt;em&gt;Scope capture of a full wake-up cycle using a secure WPA2 access point.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The first thing to notice is the horizontal scale: back to 500ms per division!
Thus the wake-cycle went from under 200ms to about 2 seconds, ouch.
There is actually quite some variability with most wake cycles
taking from 2 to 3 seconds. To understand what is happening one has to look at the packet dump,
which starts with probing and associating as usual:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  123  7.269s Probe Request (test) [5.5* 11.0* 1.0* 2.0* 6.0 12.0 24.0 48.0 Mbit]
  124  7.274s Probe Response (test) [1.0* 2.0* 5.5* 11.0* 6.0 9.0 12.0 18.0 Mbit] CH: 6, PRIVACY
  125  7.276s Acknowledgment
  146  8.271s DeAuthentication: Deauthenticated because sending statione.avior has left) IBSS or ESS
  147  8.271s Acknowledgment
  148  8.271s Authentication (Open System)-1: Successful
  149  8.272s Acknowledgment
  150  8.276s Authentication (Open System)-2:
  151  8.277s Acknowledgment
  152  8.277s Assoc Request (test) [5.5* 11.0* 1.0* 2.0* 6.0 12.0 24.0 48.0 Mbit]
  153  8.277s Acknowledgment
  154  8.280s Assoc Response AID(1) : PRIVACY : Successful
  155  8.282s Acknowledgment
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;While this looks the same as previously the timestamps are not the same. Specifically, there is a
one second pause between the probe response and the authentication.
Looking carefully at the scope trace one can see that the power
consumption is slightly higher during that time compared to most of the other wake time
(except for TX spikes).
I wonder whether the esp8266 prepares some crypto calculations for
subsequent association request, but I don&amp;rsquo;t really know.&lt;/p&gt;

&lt;p&gt;The next set of packets are all encrypted which makes it difficult to make out what they are,
but looking at a tcpdump on the server end is helpful:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;09.337388 ARP, Request who-has 192.168.0.2 tell 192.168.0.106, length 46
09.337436 ARP, Reply 192.168.0.2 is-at b8:97:5a:90:54:5a, length 28
10.298977 ARP, Request who-has 192.168.0.2 tell 192.168.0.106, length 46
10.299012 ARP, Reply 192.168.0.2 is-at b8:97:5a:90:54:5a, length 28
10.303207 IP 192.168.0.106.10577 &amp;gt; 192.168.0.2.12345: Flags [S], seq 6509, win 2144, options [mss 536,nop,nop,sackOK], length 0
10.303259 IP 192.168.0.2.12345 &amp;gt; 192.168.0.106.10577: Flags [S.], seq 3659718700, ack 6510, win 29200, options [mss 1460,nop,nop,sackOK], length 0
10.307668 IP 192.168.0.106.10577 &amp;gt; 192.168.0.2.12345: Flags [.], ack 1, win 2144, length 0
10.307732 IP 192.168.0.106.10577 &amp;gt; 192.168.0.2.12345: Flags [P.], seq 1:87, ack 1, win 2144, length 86
10.307749 IP 192.168.0.2.12345 &amp;gt; 192.168.0.106.10577: Flags [.], ack 87, win 29200, length 0
10.311969 IP 192.168.0.106.10577 &amp;gt; 192.168.0.2.12345: Flags [F.], seq 87, ack 1, win 2144, length 0
10.312051 IP 192.168.0.2.12345 &amp;gt; 192.168.0.106.10577: Flags [F.], seq 1, ack 88, win 29200, length 0
10.316318 IP 192.168.0.106.10577 &amp;gt; 192.168.0.2.12345: Flags [.], ack 2, win 2143, length 0
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;What this shows is that there are two rounds of ARP resolutions for the server&amp;rsquo;s MAC address
that are spaced 1 second apart (192.168.0.2 is the server). So it appears that the first ARP
response gets lost and the first retry comes after one second. This pattern is so
systematic that it looks more like a bug than a packet loss issue.&lt;/p&gt;

&lt;p&gt;While I can&amp;rsquo;t explain all the delays when using a secure access point it is clear that it takes an
order of magnitude longer than when using an open one.
I have not seen a single wake-cycle take less than 2 seconds, also on my home Wifi which I tried
as a sanity check.&lt;/p&gt;

&lt;h3 id=&#34;power-calculations&#34;&gt;Power calculations&lt;/h3&gt;

&lt;p&gt;Now that we know the duration of the wake cycle we can construct a simple run-time table assuming
that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the power consumption while active is 70mA&lt;/li&gt;
&lt;li&gt;the power consumption while sleeping is 10uA (the bare module consumes less, this provides some
margin for a regulator and some sensors)&lt;/li&gt;
&lt;li&gt;the wake cycle time is 200ms for an open access point and 2 seconds for a secure one&lt;/li&gt;
&lt;li&gt;a 1000mAh LiPo battery is used to calculate the run-time&lt;/li&gt;
&lt;/ul&gt;

&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;right&#34;&gt;sleep [min]&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;open [mA]&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;open [days]&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;open [act%]&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;secure [mA]&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;secure [days]&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;secure [act%]&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;

&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;right&#34;&gt;60&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0.01&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;3000.2&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;28%&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0.05&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;852.7&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;80%&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td align=&#34;right&#34;&gt;10&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0.03&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;1250.4&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;70%&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0.24&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;171.8&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;96%&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td align=&#34;right&#34;&gt;1&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0.24&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;171.8&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;96%&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;2.27&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;18.4&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;100%&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td align=&#34;right&#34;&gt;0.33&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0.71&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;58.7&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;99%&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;6.43&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;6.5&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;100%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Notes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The columns labeled &lt;em&gt;open&lt;/em&gt; and &lt;em&gt;secure&lt;/em&gt; refer to an open access point vs. a secure one.&lt;/li&gt;
&lt;li&gt;The columns labeled &lt;em&gt;[act%]&lt;/em&gt; show the percentage of power spent during the wake cycle.&lt;/li&gt;
&lt;li&gt;The first row corresponds to a system that wakes up every hour, the last one every 20 seconds.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/ESP8266 Deep-Sleep with Periodic Wake-up Run-Time.png# nocaption&#34; alt=&#34;Esp8266 run-time using deep-sleep with periodic wake-up&#34; /&gt;&lt;/p&gt;

&lt;p&gt;The conclusion one can draw here is that it is should certainly be possible to run an esp8266 in
this periodic wake-mode for a week to over a year on a single 1000mAh LiPo battery!&lt;/p&gt;

&lt;p&gt;The &lt;a href=&#34;https://blog.voneicken.com/2018/lp-wifi-association&#34;&gt;next post&lt;/a&gt; investigates an alternative, which is to
maintain an association with the access point and leverage power save mode to reduce
power consumption.&lt;/p&gt;</description>
		</item>
		
		<item>
			<title>ESP8266 Deep-Sleep with Periodic Wake-up</title>
			<link>https://blog.voneicken.com/2018/lp-wifi-esp8266-1/</link>
			<pubDate>Thu, 22 Nov 2018 00:00:00 UTC</pubDate>
			<author>Thorsten von Eicken</author>
			<guid>https://blog.voneicken.com/2018/lp-wifi-esp8266-1/</guid>
			<description>&lt;p&gt;The esp8266 can last for years on battery in deep-sleep mode, so that&amp;rsquo;s a good place to start. The
question really is how often can it wake-up?&lt;/p&gt;

&lt;p&gt;The best way to find out is to run some experiments!
The experiments will have the esp8266 wake-up from deep-sleep (basically a reset),
send some data to a server on the local network using raw TCP, and go back to sleep.
Really basic.&lt;/p&gt;

&lt;p&gt;Diving one level deeper, the esp8266 will need to go through the following phases
during its waking time:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;initialize the microcontroller (set-up clocks, flash access, caches, etc)&lt;/li&gt;
&lt;li&gt;scan wifi channels to locate the Wifi access point&lt;/li&gt;
&lt;li&gt;exchange multiple packets to associate with the access point, including
crypto operations when dealing with secure access points&lt;/li&gt;
&lt;li&gt;request-response to DHCP server to obtain an IP address&lt;/li&gt;
&lt;li&gt;ARP broadcast and response to obtain the server&amp;rsquo;s MAC address&lt;/li&gt;
&lt;li&gt;TCP connection set-up, data transfer, and tear-down&lt;/li&gt;
&lt;li&gt;disconnect from the access point&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I tried to derive the time the above steps might take from first principles, e.g. the network
protocols, and I almost fell from my chair when I saw the first packet traces! I was off by an order
of magnitude! So I&amp;rsquo;ll spare you that derivation&amp;hellip;&lt;/p&gt;

&lt;h3 id=&#34;experimental-set-up&#34;&gt;Experimental set-up&lt;/h3&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/esp8266-set-up.jpg# fr w-40pct ml-3&#34; alt=&#34;Experimental set-up&#34; /&gt;&lt;/p&gt;

&lt;p&gt;The set-up I use is as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a small custom PCB that houses an esp-12e module with a switching power regulator and an
FTDI-style connector to access the serial port and programming pins&lt;/li&gt;
&lt;li&gt;a jumper on the ground connection leading into the esp8266 module to measure supply current&lt;/li&gt;
&lt;li&gt;a uCurrent Gold to amplify the current (a 1 Ohm resistor would have probably done just fine given
the magnitude of the currents)&lt;/li&gt;
&lt;li&gt;a LiPo battery to power the esp8266 without interfering with oscilloscope ground&lt;/li&gt;
&lt;li&gt;a FTDI USB-serial adapter to program the esp8266&lt;/li&gt;
&lt;li&gt;an oscilloscope to measure the current and a probe on a random esp8266 gpio pin to trigger
the scope&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In addition, I set-up a controlled Wifi environment:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;an open unencrypted access point using a USB-adapter attached to a ODROID SBC&lt;/li&gt;
&lt;li&gt;hostapd running on the ODROID with bridging to my home network where my DHCP server runs&lt;/li&gt;
&lt;li&gt;a second USB-Wifi adapter attached to my desktop box running in monitor mode to capture the Wifi
packets as they go through the air&lt;/li&gt;
&lt;li&gt;a simple TCP service cobbled together using netcat running on my desktop to accept the esp8266&amp;rsquo;s
TCP connections a log the data sent into a file&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And for comparison purposes I also used a secured/encrypted home Wifi network with a Senao access
point and an Android cell phone in hot-spot mode.&lt;/p&gt;

&lt;p&gt;As I dove in I found two issues with my set-up, which I want to mention up-front.
The first is that the Wifi adapter in monitor mode misses some packets, specially some back-to-back packet
combinations are systematically missed and I didn&amp;rsquo;t find any tricks to fix that.&lt;/p&gt;

&lt;p&gt;The second issue is that there seems to be a high packet loss between the esp8266 and the access
point on the ODROID, which I cannot explain.
It happens whether the two systems are 1ft/30cm or 10ft/3m apart.
I tried changing preamble sizes, etc, to no avail.
I compared with using my home Wifi and realized it&amp;rsquo;s not all that different plus, as we&amp;rsquo;ll see,
the number of retransmissions don&amp;rsquo;t actually affect the overall outcome.&lt;/p&gt;

&lt;h3 id=&#34;first-measurements&#34;&gt;First measurements&lt;/h3&gt;

&lt;p&gt;The esp8266 runs a &lt;a href=&#34;https://github.com/tve/low-power-wifi/tree/master/esp8266-deep-sleep&#34;&gt;simple sketch&lt;/a&gt;
in the Arduino framework. The sketch
starts by loading data from the real-time clock memory, which doesn&amp;rsquo;t get lost during deep-sleep.
Then it initializes the Wifi in one of 4 modes based on the config data,
connects to a TCP server on the network using the server&amp;rsquo;s IP address (no DNS lookup), and
sends a line of text with some timing info to the server.
Finally it goes back to deep-sleep.&lt;/p&gt;

&lt;p&gt;The 4 modes differ in the amount of information passed into the Wifi initialization functions
&lt;code&gt;WiFi.begin&lt;/code&gt; and &lt;code&gt;WiFi.config&lt;/code&gt;:&lt;/p&gt;

&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;center&#34;&gt;mode&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;ssid, passwd&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;channel, bssid&lt;/th&gt;
&lt;th align=&#34;center&#34;&gt;ip, mask, gw, dns&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;

&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;0&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;✔&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;1&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;✔&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;✔&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;2&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;✔&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;✔&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td align=&#34;center&#34;&gt;3&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;✔&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;✔&lt;/td&gt;
&lt;td align=&#34;center&#34;&gt;✔&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;A quick look at the information coming out of the sketch shows the following:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Mode 0, Init 34 ms, Connect 2927 ms, Total 2961 ms, SSID test, SDK 3.0.0-dev(c0f7b44)
Mode 1, Init 34 ms, Connect  177 ms, Total  211 ms, SSID test, SDK 3.0.0-dev(c0f7b44)
Mode 2, Init 34 ms, Connect 2877 ms, Total 2911 ms, SSID test, SDK 3.0.0-dev(c0f7b44)
Mode 3, Init 34 ms, Connect  137 ms, Total  171 ms, SSID test, SDK 3.0.0-dev(c0f7b44)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;These are representative messages for many iterations. The init time is from the start of the
microcontroller clock to the beginning of the sketch&amp;rsquo;s &lt;code&gt;setup()&lt;/code&gt; function, the connect time is from
the start of &lt;code&gt;setup()&lt;/code&gt; to the moment the wifi subsystem reports that it is connected to the access
point, and the total time is from the start of the clock to calling the function to go into
deep-sleep.&lt;/p&gt;

&lt;p&gt;It is immediately obvious that there is over an order of magnitude difference in those 4 modes, i.e.
from about 140ms to connect to Wifi to almost 3 seconds! We could start hypothesizing based on the
differences in the four modes, but it&amp;rsquo;s far more interesting to just focus on mode 0 and
to see what all goes on.&lt;/p&gt;

&lt;h3 id=&#34;mode-0-basic-wifi-begin&#34;&gt;Mode 0: basic WiFi.begin()&lt;/h3&gt;

&lt;p&gt;Diving right in, this is a scope capture of a full wake-up cycle:&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/ap-test-mode-0-all-annot.png&#34; alt=&#34;Wake-up cycle&#34; /&gt;
&lt;em&gt;Scope capture of a full wake-up cycle using just &lt;code&gt;WiFi.begin(ssid,passwd)&lt;/code&gt; on an open access
point.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The yellow trace is a gpio output that goes low at the start of the Arduino &lt;code&gt;setup()&lt;/code&gt; function and
rises again just before &lt;code&gt;loop()&lt;/code&gt; completes and puts the microcontroller back into deep sleep.
Each horizontal division corresponds to 500ms, thus the sketch runs for a tad under 3 seconds,
i.e. just about the time claimed by the sketch.&lt;/p&gt;

&lt;p&gt;The blue trace shows power consumption at the tune of 50mA per vertical division.
It starts with a couple of stair steps as the uC initializes and mostly sits at about 140-150mA.
The high peaks up to 350mA correspond to Wifi transmissions.&lt;/p&gt;

&lt;p&gt;In a first phase, shown as &amp;ldquo;Probes&amp;rdquo; in the scope capture,
the esp8266 sends probe requests on all channels in order to locate the access point.
These packets are shown in the packet dump below where packets sent by the esp8266 are marked with a &lt;code&gt;-&amp;gt;&lt;/code&gt;
and packets sent by the AP with a &lt;code&gt;&amp;lt;-&lt;/code&gt;.
The first column is a packet counter (the skipped packets are beacons) and the second column
shows the time elapsed with millisecond resolution since the start of the capture.
Note that the ACK packets are Wifi-level acks of the probe responses and due to the
limitations mentioned earlier it is likely that additional ACKs were missed.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;   51 66.208s -&amp;gt; Probe Request (test) [5.5* 11.0* 1.0* 2.0* 6.0 12.0 24.0 48.0 Mbit]
   57 66.519s &amp;lt;- Probe Response (test) [1.0* 2.0* 5.5* 11.0* 6.0 9.0 12.0 18.0 Mbit] CH: 6
   60 66.666s -&amp;gt; Probe Request (test) [5.5* 11.0* 1.0* 2.0* 6.0 12.0 24.0 48.0 Mbit]
   61 66.671s &amp;lt;- Probe Response (test) [1.0* 2.0* 5.5* 11.0* 6.0 9.0 12.0 18.0 Mbit] CH: 6
   62 66.673s -&amp;gt; Acknowledgment RA:74:da:38:06:52:32
   67 66.819s -&amp;gt; Probe Request (test) [5.5* 11.0* 1.0* 2.0* 6.0 12.0 24.0 48.0 Mbit]
   68 66.824s &amp;lt;- Probe Response (test) [1.0* 2.0* 5.5* 11.0* 6.0 9.0 12.0 18.0 Mbit] CH: 6
   69 66.826s -&amp;gt; Acknowledgment RA:74:da:38:06:52:32
   72 66.973s -&amp;gt; Probe Request (test) [5.5* 11.0* 1.0* 2.0* 6.0 12.0 24.0 48.0 Mbit]
   73 66.978s &amp;lt;- Probe Response (test) [1.0* 2.0* 5.5* 11.0* 6.0 9.0 12.0 18.0 Mbit] CH: 6
   74 66.979s -&amp;gt; Acknowledgment RA:74:da:38:06:52:32
   79 67.131s &amp;lt;- Probe Response (test) [1.0* 2.0* 5.5* 11.0* 6.0 9.0 12.0 18.0 Mbit] CH: 6
   80 67.133s &amp;lt;- Probe Response (test) [1.0* 2.0* 5.5* 11.0* 6.0 9.0 12.0 18.0 Mbit] CH: 6
   81 67.134s &amp;lt;- Probe Response (test) [1.0* 2.0* 5.5* 11.0* 6.0 9.0 12.0 18.0 Mbit] CH: 6
   82 67.136s &amp;lt;- Probe Response (test) [1.0* 2.0* 5.5* 11.0* 6.0 9.0 12.0 18.0 Mbit] CH: 6
   83 67.138s &amp;lt;- Probe Response (test) [1.0* 2.0* 5.5* 11.0* 6.0 9.0 12.0 18.0 Mbit] CH: 6
   84 67.139s &amp;lt;- Probe Response (test) [1.0* 2.0* 5.5* 11.0* 6.0 9.0 12.0 18.0 Mbit] CH: 6
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;After the probes complete, there is a 1.5-2 second radio pause (&amp;ldquo;Idle&amp;rdquo; in the capture).
Presumably during this time the esp8266
waits for other APs on other channels to potentially respond so it can pick the one with the best
signal. In this case there is only one AP so it eventually proceeds on the channel being monitored.
The rest of the activity (&amp;ldquo;Activity&amp;rdquo; in the capture) is concentrated in a rather short time
period at the end of the whole cycle.&lt;/p&gt;

&lt;h3 id=&#34;mode-0-activity&#34;&gt;Mode 0 activity&lt;/h3&gt;

&lt;p&gt;To view the activity at the end of the wake period here is a zoom-in of the same capture with a
horizontal resolution of 20ms per division.&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/ap-test-mode-0-end-annot.png&#34; alt=&#34;Wake-up cycle zoomed&#34; /&gt;
&lt;em&gt;Zooming into the activity period of the overall screen capture shows the individual phases.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Let&amp;rsquo;s go through all the phases marked-up in the scope capture using the packet captures to
understand exactly what is happening.&lt;/p&gt;

&lt;p&gt;In the first phase of the activity the esp8266 authenticates and associates with the AP
(there&amp;rsquo;s no password but an auth exchange still happens).
The very first packets seen on the air actually deassociate to ensure
that there is no old association state left in the AP:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  121 68.918s -&amp;gt; DeAuthentication (5c:cf:7f:05:c0:db): Deauthenticated because sending station is leaving (or has left) IBSS or ESS
  122 68.918s -&amp;gt; DeAuthentication (5c:cf:7f:05:c0:db): Deauthenticated because sending station is leaving (or has left) IBSS or ESS
  123 68.918s &amp;lt;- Acknowledgment RA:5c:cf:7f:05:c0:db
  124 68.918s -&amp;gt; Authentication (Open System)-1: Successful
  125 68.918s &amp;lt;- Acknowledgment RA:5c:cf:7f:05:c0:db
  126 68.924s &amp;lt;- Authentication (Open System)-2:
  127 68.924s -&amp;gt; Acknowledgment RA:74:da:38:06:52:32
  128 68.926s -&amp;gt; Assoc Request (test) [5.5* 11.0* 1.0* 2.0* 6.0 12.0 24.0 48.0 Mbit]
  129 68.926s &amp;lt;- Acknowledgment RA:5c:cf:7f:05:c0:db
  130 68.929s &amp;lt;- Assoc Response AID(1) :: Successful
  131 68.930s -&amp;gt; Acknowledgment RA:74:da:38:06:52:32
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now that the esp8266 is associated it can ask for an IP address using DHCP:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  133 68.932s -&amp;gt; IP 0.0.0.0.68 &amp;gt; 255.255.255.255.67: BOOTP/DHCP, Request from 5c:cf:7f:05:c0:db, length 308
  134 68.936s &amp;lt;- Acknowledgment RA:5c:cf:7f:05:c0:db
  135 68.944s -&amp;gt; IP 0.0.0.0.68 &amp;gt; 255.255.255.255.67: BOOTP/DHCP, Request from 5c:cf:7f:05:c0:db, length 308
  136 68.947s &amp;lt;- IP 192.168.0.1.67 &amp;gt; 192.168.0.106.68: BOOTP/DHCP, Reply, length 300
  137 68.950s -&amp;gt; Acknowledgment RA:74:da:38:06:52:32
  138 68.952s -&amp;gt; IP 0.0.0.0.68 &amp;gt; 255.255.255.255.67: BOOTP/DHCP, Request from 5c:cf:7f:05:c0:db, length 308
  139 68.955s &amp;lt;- Acknowledgment RA:5c:cf:7f:05:c0:db
  140 68.961s -&amp;gt; IP 0.0.0.0.68 &amp;gt; 255.255.255.255.67: BOOTP/DHCP, Request from 5c:cf:7f:05:c0:db, length 308
  142 68.971s &amp;lt;- IP 192.168.0.1.67 &amp;gt; 192.168.0.106.68: BOOTP/DHCP, Reply, length 300
  143 68.974s -&amp;gt; Acknowledgment RA:74:da:38:06:52:32
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;At this point the esp8266 has its IP address, it now sends gratuitous ARPs in order to ensure that
no-one else is using the same IP address. Shortly thereafter it requests the MAC address of the
server to which data is to be sent. This is repeated because for some reason the server didn&amp;rsquo;t
respond.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  144 68.975s -&amp;gt; ARP, Request who-has 192.168.0.106 tell 192.168.0.106, length 28
  145 68.976s &amp;lt;- Acknowledgment RA:5c:cf:7f:05:c0:db
  146 68.982s -&amp;gt; ARP, Request who-has 192.168.0.106 tell 192.168.0.106, length 28
  147 68.986s -&amp;gt; ARP, Request who-has 192.168.0.2 tell 192.168.0.106, length 28
  148 68.986s &amp;lt;- Acknowledgment RA:5c:cf:7f:05:c0:db
  149 68.992s -&amp;gt; ARP, Request who-has 192.168.0.2 tell 192.168.0.106, length 28
  150 68.992s &amp;lt;- ARP, Reply 192.168.0.2 is-at b8:97:5a:90:54:5a, length 46
  151 68.993s -&amp;gt; Acknowledgment RA:74:da:38:06:52:32
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Finally everything is ready for some data! This is the TCP connection:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  152 68.994s -&amp;gt; IP 192.168.0.106.49669 &amp;gt; 192.168.0.2.12345: Flags [S], seq 6509, win 2144, options [mss 536,nop,nop,sackOK], length 0
  153 68.995s &amp;lt;- Acknowledgment RA:5c:cf:7f:05:c0:db
  [SYN-ACK packet missing from capture]
  154 68.996s -&amp;gt; Acknowledgment RA:74:da:38:06:52:32
  155 68.998s -&amp;gt; IP 192.168.0.106.49669 &amp;gt; 192.168.0.2.12345: Flags [.], ack 2924126972, win 2144, length 0
  156 68.998s &amp;lt;- Acknowledgment RA:5c:cf:7f:05:c0:db
  157 68.999s -&amp;gt; IP 192.168.0.106.49669 &amp;gt; 192.168.0.2.12345: Flags [P.], seq 0:86, ack 1, win 2144, length 86
  158 69.001s &amp;lt;- Acknowledgment RA:5c:cf:7f:05:c0:db
  [TCP ack packet missing from capture]
  159 69.005s -&amp;gt; Acknowledgment RA:74:da:38:06:52:32
  160 69.007s -&amp;gt; IP 192.168.0.106.49669 &amp;gt; 192.168.0.2.12345: Flags [F.], seq 86, ack 1, win 2144, length 0
  161 69.008s &amp;lt;- Acknowledgment RA:5c:cf:7f:05:c0:db
  [FIN+ACK packet missing from capture]
  162 69.010s -&amp;gt; Acknowledgment RA:74:da:38:06:52:32
  163 69.011s -&amp;gt; IP 192.168.0.106.49669 &amp;gt; 192.168.0.2.12345: Flags [.], ack 2, win 2143, length 0
  164 69.012s &amp;lt;- Acknowledgment RA:5c:cf:7f:05:c0:db
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And it&amp;rsquo;s done! The code has a &lt;code&gt;delay()&lt;/code&gt; for 20ms that I forgot to remove before it puts the esp8266 to sleep.
A few of these are overlapped by the shutting down of TCP and
then the esp8266 disassociates from the AP. There are a total of 11 disassociation frames (not
all are shown here):&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;  165 69.029s -&amp;gt; Disassociation: Disassociated because sending station is leaving (or has left) BSS
  166 69.029s &amp;lt;- Acknowledgment RA:5c:cf:7f:05:c0:db
  167 69.030s -&amp;gt; Disassociation: Disassociated because sending station is leaving (or has left) BSS
  168 69.030s &amp;lt;- Acknowledgment RA:5c:cf:7f:05:c0:db
  169 69.030s -&amp;gt; Disassociation: Disassociated because sending station is leaving (or has left) BSS
  170 69.030s &amp;lt;- Acknowledgment RA:5c:cf:7f:05:c0:db
  171 69.030s -&amp;gt; Disassociation: Disassociated because sending station is leaving (or has left) BSS
  172 69.031s &amp;lt;- Acknowledgment RA:5c:cf:7f:05:c0:db
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;After the last packet it takes another 90ms before the esp8266 actually powers down, what it does
during that period is not entirely clear.&lt;/p&gt;

&lt;h3 id=&#34;what-have-we-learned&#34;&gt;What have we learned?&lt;/h3&gt;

&lt;p&gt;The most obvious observation from this trace is that the probing takes the bulk of the time! This
can be seen not only from the scope capture but also from the fact that the two modes that specify
the channel and bssid (modes 1 and 3) are much faster in connecting than the other two.
It&amp;rsquo;s clearly worthwhile to eliminate the probing from the wake-up, which is done in the code by
using the RTC RAM to remember the channel and bssid info from previous iterations.&lt;/p&gt;

&lt;p&gt;The DHCP and ARP phases also take up quite some time of the activity period. We should be able to
eliminate the DHCP phase by using a static IP or remembering the dynamic one but the ARP phase is
likely to stay.&lt;/p&gt;

&lt;p&gt;More about these optimizations in the &lt;a href=&#34;https://blog.voneicken.com/2018/lp-wifi-esp8266-2&#34;&gt;next post&lt;/a&gt;&lt;/p&gt;</description>
		</item>
		
		<item>
			<title>Running Wifi Microcontrollers on Battery</title>
			<link>https://blog.voneicken.com/projects/low-power-wifi-intro/</link>
			<pubDate>Sun, 18 Nov 2018 00:00:00 UTC</pubDate>
			<author>Thorsten von Eicken</author>
			<guid>https://blog.voneicken.com/projects/low-power-wifi-intro/</guid>
			<description>&lt;p&gt;Operating Wifi at low power is difficult, Wifi is just way more complex and chatty than simple RF
links. This project and blog post series explores what is available at the end of 2018.
&lt;/p&gt;

&lt;p&gt;In this exploration, low-power refers to a wifi-connected microcontroller that runs at least for a week on a 1000mAh
LiPo and could thus run indefinitely on a small 100mA/6V solar panel with good
sun exposure.
It focuses on use-cases where the microcontroller remains connected to Wifi or at least maintains
that illusion by being reachable with a few seconds of response time.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Tl;dr: this series is pretty long and in-depth, if you prefer to cut to the chase you
can zip right to the &lt;a href=&#34;https://blog.voneicken.com/2018/lp-wifi-esp-comparison#conclusions&#34;&gt;conclusions&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I looked into using the esp8266 on battery in 2015 when I first started using it and quickly gave
up.
At the time it became apparent that while the hardware could sleep at low power, the software was
not capable of keeping the lid on the power consumption.
I soon gave up and relegated the esp8266 to powered projects.
I recently decided to take another look at not only the esp8266 but also the esp32 to see whether
things have improved. I looked at two approaches.&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/low-power-wifi/20181119_231556.jpg# fr
w-50pct ml-3&#34; alt=&#34;Espressif esp8266 RF node and 2600mAh Li-Ion cell&#34; /&gt;&lt;/p&gt;

&lt;p&gt;The first approach is to build systems that spend most of their time in deep sleep mode and only
wake-up periodically to connect to Wifi. In deep sleep mode all RAM contents is lost, so the system
boots from scratch each time it wakes up. It&amp;rsquo;s really as if someone briefly flipped the on/off
switch to the on position every now and then.&lt;/p&gt;

&lt;p&gt;This type of periodic wake-up systems are well matched to sensor nodes
that can spend most of their time asleep with the Wifi
turned off and occasionally wake up, take a measurement, briefly connect to Wifi to
transmit their data and then sleep again.
In those systems the power calculation revolves around how often the Wifi has to be turned on
and how much power it takes to connect and send out a measurement.
There are a good number of projects that successfully use esp8266s for such systems and
achieve a year of run-time on a small battery given a low-enough duty cycle.&lt;/p&gt;

&lt;p&gt;The second approach to achieving low power Wifi is to make use of the power saving features of the
Wifi protocols and carefully manage when the processor and the radio are active to communicate over
Wifi and when they&amp;rsquo;re asleep.
The benefit of this approach is that the systems give the appearance of always being on: they can be
reached at any time so one can send them commands and queries.&lt;/p&gt;

&lt;p&gt;Somewhere in-between the always-on and mostly-asleep approaches there is a middle ground where it may
take a few seconds or a few minutes for a command to reach a system. This can be useful if, for
example, the command is a wake-up call and causes the system to stay awake for a short time period
so it can receive further commands or be used interactively.&lt;/p&gt;

&lt;p&gt;I am using two use-cases to drive my investigation.
The first one is a wifi-serial bridge like &lt;a href=&#34;http://github.com/jeelabs/esp-link&#34;&gt;Esp-Link&lt;/a&gt; or an
STM32 Black-Magic-Probe debug tool.
I use them all the time in a powered mode in my lab but when I deploy low-power sensors in the
field I often find problems that I didn&amp;rsquo;t spot before and it would be really convenient to be able
to deploy a serial-wifi bridge or debug probe for a couple of days or weeks on battery power to help
in the troubleshooting.&lt;/p&gt;

&lt;p&gt;The second use-case is an RF-MQTT gateway (e.g. RFM69-MQTT or LoRa-MQTT).
It would be very helpful to deploy such a gateway on battery power
as a stop-gap measure to fill-in an area with poor coverage
until I get real power installed.
Alternatively it would be awesome to be able to run a GW entirely on solar.&lt;/p&gt;

&lt;h3 id=&#34;a-concrete-target&#34;&gt;A concrete target&lt;/h3&gt;

&lt;p&gt;What does it take to run a microcontroller on battery for days or weeks?
The following table provides a first-level calibration by showing run-time
using a 1000mAh battery vs. average power consumption
over a 0.01mA to 100mA range.&lt;/p&gt;

&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th align=&#34;right&#34;&gt;avg [mA]&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;life @1000mAh [days]&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;solar @4h/day [mA]&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;

&lt;tbody&gt;
&lt;tr&gt;
&lt;td align=&#34;right&#34;&gt;100&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0.4&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;600&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td align=&#34;right&#34;&gt;10&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;4.2&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;60&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td align=&#34;right&#34;&gt;1&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;41.7&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;6&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td align=&#34;right&#34;&gt;0.1&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;416.7&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0.6&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;The left column lists various average power consumptions in mA, the center column the number of
expected days of run-time on a 1000mAh battery, and the right column how large a solar panel
(6V nominal type) would be required to run indefinitely. These are just back-of-the-envelope
calculations that get into the right ballpark and that sweep voltage differences and other
details under the rug.&lt;/p&gt;

&lt;p&gt;The goal then is find a way to stay connected to Wifi at an average power consumption of about
10mA. Using a relatively cheap 2500mAh 18650 Li-Ion cell such a device could plausibly run for
close to two weeks and using a 100mA solar panel with decent exposure it could plausibly run indefinitely.
Getting below 10mA would be really exciting because this would enable systems that run for about a
month on an 18650 Li-Ion cell, specially if one spends a bit more and gets a 3000mAh one&amp;hellip;&lt;/p&gt;

&lt;p&gt;The next question is how do low-power Wifi microcontrollers stack up against this goal?
The table below lists power consumption figures gleaned from datasheets (all at 3.3V) for
the Espressif esp8266, the Espressif esp32, and the RealTek RTL8710.&lt;/p&gt;

&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;mode&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;esp8266&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;esp32&lt;/th&gt;
&lt;th align=&#34;right&#34;&gt;rtl8710&lt;/th&gt;
&lt;th&gt;comment&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;

&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;deep-sleep&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0.01mA&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0.01mA&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0.02mA&lt;/td&gt;
&lt;td&gt;powered-down, memory lost, only wake-up timer running&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;sleep&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0.9mA&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0.8mA&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;0.5mA&lt;/td&gt;
&lt;td&gt;cpu stopped, timer running, memory&amp;amp;state preserved&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;cpu&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;15mA&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;20mA&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;25mA&lt;/td&gt;
&lt;td&gt;cpu running, RF off&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;rx&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;56mA&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;100mA&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;62mA&lt;/td&gt;
&lt;td&gt;receiving packet&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
&lt;td&gt;tx&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;320mA&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;400mA&lt;/td&gt;
&lt;td align=&#34;right&#34;&gt;162mA&lt;/td&gt;
&lt;td&gt;transmitting (see note)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;em&gt;Note: the esp32 datasheet says that the ~200mA TX power listed in its table 14 apply to
a 50% TX duty cycle, hence the 400mA listed here (and I can defintiely confirm that it consumes
that much using a scope). I also doubled the esp8266 power figure from its datasheet as I&amp;rsquo;m assuming
that this is also for a 50% duty cycle (I can also confirm seeing over 300mA myself).&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;These numbers make it very clear that the systems must spend the majority of their time in one of
the two sleep modes. Running the processor all the time is not in the cards and any form of radio
activity must be limited and carefully managed.&lt;/p&gt;

&lt;p&gt;The &lt;a href=&#34;https://blog.voneicken.com/2018/lp-wifi-esp8266-1&#34;&gt;next post&lt;/a&gt; explores using the esp8266 in periodic wake-up mode
where it spends most of its time in deep-sleep and only wakes-up every now and then.&lt;/p&gt;</description>
		</item>
		
		<item>
			<title>Solar-powered light barrier across the driveway</title>
			<link>https://blog.voneicken.com/2018/light-barrier/</link>
			<pubDate>Sun, 11 Nov 2018 00:00:00 UTC</pubDate>
			<author>Thorsten von Eicken</author>
			<guid>https://blog.voneicken.com/2018/light-barrier/</guid>
			<description>&lt;p&gt;Light barrier using pulsed IR. The transmitter is based on NE555 timers and the receiver
on a special-purpose IR receiver, an stm32 for control, and an rfm69 radio to transmit
interruptions.&lt;/p&gt;

&lt;p&gt;See &lt;a href=&#34;https://blog.voneicken.com/projects/driveway-chime&#34;&gt;driveway entrance chime powered by solar light barrier&lt;/a&gt;
for the project intro.&lt;/p&gt;

&lt;h3 id=&#34;ir-receiver&#34;&gt;IR receiver&lt;/h3&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/light-barrier/Vishay TSOP38338 a.png# fr w-50pct ml-3&#34; alt=&#34;Vishay TSOP38338 overview&#34; /&gt;
&lt;em&gt;Vishay TSOP38338 pins and description&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;At the core of the project lie very efficient IR LEDs to transmit light to a special-purpose
receiver that is tuned to a specific frequency and expects to receive a train of light pulses. The
specific receiver I use is a Vishay TSOP38338, which is a 3-pin device that outputs low when it
receives incoming IR light pulses and high when it doesn&amp;rsquo;t.&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/light-barrier/Vishay TSOP38338 d.png# fr w-40pct ml-3&#34; alt=&#34;Vishay TSOP38338 pulse train&#34; /&gt;&lt;/p&gt;

&lt;p&gt;The light pulse train it expects to receive must have a frequency of 38kHz and last for at least 6
and at most 35 pulses. Something like shown in the diagram on the right. A typical circuit is
shown below, the only
thing noteworthy really is the suggested power supply filtering capacitor, other than that all
that&amp;rsquo;s needed is to connect the detector output to a gpio input on the microcontroller.&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/light-barrier/Vishay TSOP38338 b.png# w-50pct ml-3&#34; alt=&#34;Vishay TSOP38xxx variants&#34; /&gt;&lt;/p&gt;

&lt;p&gt;There are other versions of the receiver
that respond to slightly different frequencies and burst lenths as summarized in the table below.&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/light-barrier/Vishay TSOP38338 c.png# w-90pct ml-3&#34; alt=&#34;Vishay TSOP38xxx variants&#34; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/light-barrier/20181006_103045.jpg# fr w-50pct ml-3&#34; alt=&#34;Semi assembled receiver&#34; /&gt;&lt;/p&gt;

&lt;p&gt;The photo at the right shows the semi-assembled unit with the solar charger at the bottom, the
JeeNode Zero half sticking out of the PVC pipe, the solar panel at the top, and a dipole antenna
sticking out at the bottom of the PVC pipe.&lt;/p&gt;

&lt;h3 id=&#34;ir-transmitter&#34;&gt;IR transmitter&lt;/h3&gt;

&lt;p&gt;The IR transmitter needs to generate the required light pulses at the right frequency and with an
appropriate duty cycle. I chose to emit around a dozen light pulses at a frequency of about 10Hz.
This way even someone walking rapidly through the light barrier blocks the light for a couple of pulse
trains, which is something the receiver should be able to detect reliably.
Hopefully an insect flying through the light barrier only causes at most one pulse
train to be blocked so it doesn&amp;rsquo;t cause false positives.&lt;/p&gt;

&lt;p&gt;The IR light is emitted by powerful LEDs. I chose Vishay TSAL6100 LEDs, which emit about 170mW/sr of
light at 100mA consumption with a beam angle of 20 degrees. Osram has some alternative LEDs which
are perhaps even better, specifically the SFH 4544. All of these emit quite powerful light focused
relatively narrowly but not as narrow as a laser beam!&lt;/p&gt;

&lt;p&gt;I haven&amp;rsquo;t used NE555 timers in over a decade but had a couple laying around so I thought I&amp;rsquo;d
refresh my skills and a NE556 instead of reaching to a
microcontroller just to implement two timers. That sounded fun and smart at the time, but in
hindsight I would not do that again and may actually replace the whole thing, but more on that
later.&lt;/p&gt;

&lt;p&gt;The circuit is really simple:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a 555 oscillator running at 10Hz to turn the light pulses on/off, the duty cycle is very skewed so
it turns on just long enough for about a dozen pulses to be emitted (the exact count is voltage
and temperature dependent).&lt;/li&gt;
&lt;li&gt;another 555 oscillator that is gated by the first one and that runs at 38kHz in order to pulse the
LEDs at the right frequency.&lt;/li&gt;
&lt;li&gt;a constant current drive that drives the LEDs (I use two LEDs in series) at approx 100mA.&lt;/li&gt;
&lt;li&gt;a voltage divider to reset the first 555 oscillator when the voltage drops way down
in order to save the battery.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/light-barrier/transmitter-schematic.png# w-90pct ml-3&#34; alt=&#34;IR transmitter schematic&#34; /&gt;&lt;/p&gt;

&lt;p&gt;I first prototyped the circuit and it all went well until I measured the current: whoa! Of course
when the LED is active that draws 100mA but when the LED was off the circuit was also consuming
several mA, which is not practical on battery. I realized that the culprits were the resistor voltage
dividers that set the oscillator frequencies! In order to fix the problem I changed them out for the
largest values that I had on-hand. This brought the LED-off power consumption down to 100µA, which
is nothing to rave about but at least tolerable.&lt;/p&gt;

&lt;p&gt;Overall, using the NE556 has been rather disappointing and I wouldn&amp;rsquo;t do it again. Here is the list
of disappointments:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The power consumption is at least 10x higher than if I had used an STM32L0 microcontroller.&lt;/li&gt;
&lt;li&gt;The low-voltage cut-off to protect the battery is crude and not really sufficient.&lt;/li&gt;
&lt;li&gt;The tuning of the frequency/duty cycle is less precise and less easy to change than with a µC.&lt;/li&gt;
&lt;li&gt;The number of parts is larger than with a µC (although cheaper).&lt;/li&gt;
&lt;li&gt;There is no monitoring of the battery voltage possible.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&#34;solar&#34;&gt;Solar&lt;/h3&gt;

&lt;p&gt;This is the first project I am trying to power via solar (oops). The reason is that the IR LEDs on
one end and the IR detector on the other end use an order of magnitude more power than my other
battery operated gizmos and that means that I&amp;rsquo;d either have to use a quite large battery or change
batteries weekly. So I&amp;rsquo;m looking for a small amount of solar power, which is not entirely trivial due
to the plant coverage around the driveway entrance.&lt;/p&gt;

&lt;p&gt;The first step is to do some power consumption calculations. The IR receiver is easy: the IR
detector&amp;rsquo;s consumption dwarfs everything else on the board as it consumes a steady 450µA. On a
1000mAh battery that translates to about 90 days of run-time. I&amp;rsquo;m using a 240mAh battery and thus
can expect about 2-3 weeks.&lt;/p&gt;

&lt;p&gt;The power consumption of the IR transmitter needs to model the duty cycle of the LEDs:&lt;/p&gt;

&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;LED [mA]&lt;/th&gt;
&lt;th&gt;freq [Hz]&lt;/th&gt;
&lt;th&gt;pulses&lt;/th&gt;
&lt;th&gt;period [ms]&lt;/th&gt;
&lt;th&gt;avg [mA]&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;

&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;110&lt;/td&gt;
&lt;td&gt;38000&lt;/td&gt;
&lt;td&gt;16&lt;/td&gt;
&lt;td&gt;100&lt;/td&gt;
&lt;td&gt;0.23&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;LED on-time for one pulse train is &lt;code&gt;16*(1/38000)/2 = 2.1ms&lt;/code&gt; which over 100ms results in an average
of 230µA power draw.&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/light-barrier/cn3065.jpg# fr w-30pct ml-3&#34; alt=&#34;Mini Solar Lipo Charger Board CN3065&#34; /&gt;&lt;/p&gt;

&lt;p&gt;To implement the solar charging I decided to start simple and use low-cost LiPo charger modules that
support solar. The modules are based on a chinese charger chip, the CN3065, available from the
typical low cost sources as &amp;ldquo;Mini Solar Lipo Charger Board CN3065&amp;rdquo;.&lt;/p&gt;

&lt;p&gt;The chip really is a USB-powered
LiPo charger, except that it handles low-voltage conditions gracefully by degrading into a sort of
PWM mode. This means that when a 6V solar panel provides ample power it charges the battery as if it
were on USB. When the solar power becomes marginal it turn the charging on, which lowers the
panel voltage such that the low-coltage cut-out disconnects the panel, which then goes up in voltage
again and the cycle repeats. It&amp;rsquo;s not the greatest set-up but worth seeing whether this does it.&lt;/p&gt;

&lt;p&gt;The solar panels I&amp;rsquo;m using are tiny 6V 16mA panels. In theory, if they get a few hours of sun per
day they should be sufficient. The key question is in the mounting and resulting exposure.&lt;/p&gt;

&lt;h3 id=&#34;code&#34;&gt;Code&lt;/h3&gt;

&lt;p&gt;The sketch running on the IR detector is relatively simple. The IR detector input pin is connected
to an interrupt routine which sets a &amp;ldquo;last seen&amp;rdquo; timestamp whenever the detector indicates that
light pulses are received. The main loop runs every 300ms and checks whether the timestamp is more
than 300ms old. If it is it sends an MQTT message to indicate that the light barrier has be
interrupted.&lt;/p&gt;

&lt;p&gt;The sketch also transmits the battery voltage every few minutes so I can track the charging vs.
consumption.&lt;/p&gt;

&lt;h3 id=&#34;mounting&#34;&gt;Mounting&lt;/h3&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/light-barrier/20181005_142037.jpg# fr w-50pct ml-3&#34; alt=&#34;Light barrier parts&#34; /&gt;
&lt;em&gt;Light barrier transmitter parts, clockwise: solar cell, NE556-based
controller, LiPo battery, solar charge controller.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;To keep everything simple I used PVC pipe left-overs to house the electronics. I drilled holes for
the LEDs and IR detector and used PVC caps at the top, leaving the bottoms open for now. I&amp;rsquo;ll
have to seal them with some tape or foam so spiders don&amp;rsquo;t set-up shop inside.&lt;/p&gt;

&lt;h3 id=&#34;status&#34;&gt;Status&lt;/h3&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/light-barrier/20181005_142801.jpg# fr w-30pct ml-3&#34; alt=&#34;Units ready to mount for testing&#34; /&gt;&lt;/p&gt;

&lt;p&gt;The light-barrier part is working very well. I am not getting spurious alerts and everything seems
quite reliable.&lt;/p&gt;

&lt;p&gt;The solar on the IR transmitter also appears to function OK, I wish I had remote
monitoring capability. The solar on the IR detector is not working so well, it just doesn&amp;rsquo;t get much
sun due to being under trees. Maybe a larger panel could do or maybe I can tweak the location a bit.
It&amp;rsquo;s too early to tell.&lt;/p&gt;

&lt;p&gt;The RF transmission of the interruptions is not working well, unfortunately. THere is just too much
green stuff between the unit and my current RF-MQTT gateway. I tried using a better antenna and that
improved things, but not enough. I am planning to add more gateways so this project will be a bit on
hold until that happens.&lt;/p&gt;

&lt;p&gt;To be continued&amp;hellip;&lt;/p&gt;</description>
		</item>
		
		<item>
			<title>Driveway entrance chime powered by solar light barrier</title>
			<link>https://blog.voneicken.com/projects/driveway-chime-intro/</link>
			<pubDate>Sat, 06 Oct 2018 00:00:00 UTC</pubDate>
			<author>Thorsten von Eicken</author>
			<guid>https://blog.voneicken.com/projects/driveway-chime-intro/</guid>
			<description>&lt;p&gt;Solar powered light barrier across a driveway to signal the entrance and departure of vehicles and pedestrians
using a door chime. Communication between the light barrier and the chime is via RF links and MQTT.
&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/light-barrier/20181005_145700.jpg# fr w-60pct ml-3&#34; alt=&#34;View of the entrance&#34; /&gt;
&lt;em&gt;Driveway entrance with light barrier mounted, visible as small white PVC pipe pieces on far left
and far right.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The entrance to our property is about 500ft/150m away from our house and partially obscured by a
large oak tree. As a result we want some entrance chime that lets us know when someone arrives.
I set out to build a light barrier that transmits interruptions of the light barrier via RF to my
home automation system (built around MQTT and Node-Red). From there I can initiate the capture of
some images, send notifications to cell phones, and also ring a set of door chimes around the property.&lt;/p&gt;

&lt;p&gt;The driveway is about 12ft/4m wide where the light barrier needs to go and there are a number of
trees that obscure the sunlight at various times of the day, often causing rapidly moving shade
patterns. Thus the light barrier has to be good enough to filter out sunlight as well as rapid light
changes.&lt;/p&gt;

&lt;h1 id=&#34;failed-attempts&#34;&gt;Failed attempts&lt;/h1&gt;

&lt;p&gt;My first attempt was to use a laser and photo sensor. I rather quickly abandoned that when I
realized how tiny the laser dot is at 12ft/4m distance. I&amp;rsquo;d have to pour some really solid concrete
to mount the laser so well that no matter how much wind or rain we have it doesn&amp;rsquo;t move away from
the target. Plus every time I&amp;rsquo;d touch it I would have to fiddle to get it back on target. Not
appealing at all.&lt;/p&gt;

&lt;p&gt;I then switched to an IR LED and IR detector. That worked at night but during the day the sunlight
just drove the thing crazy. There is so much light scattered in all directions and it changes so
much with wind that I could not establish any reasonable threshold.&lt;/p&gt;

&lt;h1 id=&#34;ir-pulse-light-barrier&#34;&gt;IR pulse light barrier&lt;/h1&gt;

&lt;p&gt;I finally searched on how one does this (would have been too easy to do this initially, wouldn&amp;rsquo;t
it?). The answer I came up with is to pulse the IR LED at a specific frequency and use a detector
that is tuned to that frequency. This way it can filter out ambient IR light.&lt;/p&gt;

&lt;p&gt;The &lt;a href=&#34;https://blog.voneicken.com/2018/light-barrier&#34;&gt;next post&lt;/a&gt; describes the light-barrier.&lt;/p&gt;</description>
		</item>
		
		<item>
			<title>Do electronics like saltwater?</title>
			<link>https://blog.voneicken.com/2018/saltwater-electronics/</link>
			<pubDate>Thu, 26 Jul 2018 00:00:00 UTC</pubDate>
			<author>Thorsten von Eicken</author>
			<guid>https://blog.voneicken.com/2018/saltwater-electronics/</guid>
			<description>&lt;p&gt;Picture yourself swimming in the ocean and looking at your electronics
bathing in the saltwater next to you&amp;hellip;&lt;/p&gt;

&lt;p&gt;Well, that&amp;rsquo;s what happened to me a couple of weeks ago! Surfing down a
wave I tipped to the side falling out of the surfski. I somehow managed
to flip open the latch of the tracker&amp;rsquo;s case with my toes. So there I
was, swimming next to the surfski and seeing the box open and the PCB
plus the battery plus the little foam dividers all happily bathing in
the ocean water! Before the next wave washed everything away I somehow
managed to stuff everything back into the box without too much water
and lock it back up. What&amp;rsquo;s your guess, anything salvagable here?&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/sports-tracker/20180807_205955_sml.jpg# fr w-30pct ml-3&#34; alt=&#34;LiIon cell&#34; /&gt;
&lt;em&gt;Li-Ion cell with gunked top after saltwater bath&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Back home I inspected the damage. The top of the battery had
a whole lot of dark goo. It must be toast. But still registered
3.1V! Interesting&amp;hellip; Lots of white crud all over the PCBs. I spent some
time cleaning them with denatured alcohol and then plugged everything
into a current-limited power supply and started to apply power. To my
great suprise the display came on and showed the normal info!?&lt;/p&gt;

&lt;p&gt;What didn&amp;rsquo;t seem to just work was the bluetooth heart rate info. After
a good hour of troubleshooting I concluded that the bluetooth radio&amp;rsquo;s
output stage must have gotten fried in the bath. Probably the radio was
transmitting and the output got short-circuited. The module seemed
to work perfectly and respond to commands as expected, but it simply
wasn&amp;rsquo;t seeing any of the bluetooth devices around my desk. I ended up
ordering a new one and when I put it in it worked right off the bat.&lt;/p&gt;

&lt;p&gt;Looks like I got really lucky that not more broke and that everything
was held in place by the cables long enough for me to collect it before
it would sink! For my next prototype I will make sure that the latch can&amp;rsquo;t
be accidentally opened with the toes!!!&lt;/p&gt;

&lt;p&gt;To be continued&amp;hellip;&lt;/p&gt;</description>
		</item>
		
		<item>
			<title>SPI kills LoRa radio</title>
			<link>https://blog.voneicken.com/2018/spi-kills-lora/</link>
			<pubDate>Sat, 21 Jul 2018 00:00:00 UTC</pubDate>
			<author>Thorsten von Eicken</author>
			<guid>https://blog.voneicken.com/2018/spi-kills-lora/</guid>
			<description>&lt;p&gt;I spent some time this week troubleshooting the LoRa communication
problems I encountered when testing long range links from the ocean
sports tracker. It led me to the SPI bus&amp;hellip;
&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/sports-tracker/20180924_145431.jpg# fr w-40pct ml-3&#34; alt=&#34;Tracker with dipole comparison&#34; /&gt;
&lt;em&gt;Tracker with the small antenna inside and a proper full dipole to its
right for size comparison.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;To recap: I&amp;rsquo;m sending tracking packets from the
tracker to the GW and the GW responds with an ACK to each packet. Both
sides use the same TX power but I see 9-10dB less SNR at the node end. I
thought it had something to do with the GW being a small linux SBC and
having more noise or something, so I put together a simple STM32-based
node to respond with ACKs like the GW does. I also displayed more info:
SNR, RSSI, and noise measurements taken there was no packet in
the air. It was all rather confusing, in part because the SNR on the
sx1276 LoRa chips doesn&amp;rsquo;t report above about 8dB and at close range
while testing it&amp;rsquo;s difficult to actually go that low.&lt;/p&gt;

&lt;p&gt;Long story short, I saw that RSSI was within 1dB on both ends but SNR
was off by 10dB. So both ends were getting the same signal strength but
not the same signal-to-noise. Thus noise had to be the issue. But when
I tried to measure the noise floor I got about the same values on both
ends. Mystery. The answer turned out to be that reception on the linux
end is fully interrupt driven while at the STM32 end the uC keeps polling
the radio chip&amp;rsquo;s registers to see the &amp;ldquo;RX done&amp;rdquo; flag being raised. That
polling over the SPI bus creates enough noise to reduce sensitivity
by 10dB!&lt;/p&gt;

&lt;p&gt;I did a quick test. Since the ACK comes in immediately I inserted a
long-enough sleep before starting to poll such that the first poll happens
after the reception is complete. Tada! This brought SNR to the same level
on both ends! I then tried something different: I changed the slew rate on
the SPI pins to &amp;ldquo;2Mhz&amp;rdquo;, which has the effect of creating ~6-8ns rise and
fall times instead of ~1.6ns. With the original polling that reduced the
sensitivity loss from the 10dB to about 1dB. So that creates some options:
a) sleep for the expected time required for the ACK to come in, b)
use an interrupt for RX-done, c) reduce the slew rate on the SPI pins.&lt;/p&gt;

&lt;p&gt;All this is fine and dandy for the test node I was using to try out
the different combinations, but on the tracker it&amp;rsquo;s somewhat more
complicated. First of all, the SPI bus is used to drive not only the
radio but also the flash chip and the display. That means that options
(a) and (b) are useless unless  the code also avoids talking to these
two devices while an ACK might be coming in. At the slow LoRa data rates
an ACK takes 300-400ms and currently I&amp;rsquo;m updating the display twice a
second, so there&amp;rsquo;s not much time left.&lt;/p&gt;

&lt;p&gt;The other problem is that the GPS and the BLE interface are constantly
sending stuff to the STM32 via serial ports and that is bound to also
create noise. Those lines don&amp;rsquo;t go to the radio module, but still. The
effect of that is unknown.&lt;/p&gt;

&lt;p&gt;As a first step forward I ended up reducing the slew rate on all outputs
from the STM32 chip. Testing at medium range seems to indicate a 2dB
loss in sensitivity, which is not great but a start. I yet have to do
a long range test.&lt;/p&gt;

&lt;p&gt;On the current STM32L082 chip package I&amp;rsquo;m out of pins, so I can&amp;rsquo;t separate
the radio&amp;rsquo;s SPI bus from the display&amp;rsquo;s. I will probably have to live with
the 2dB sensitivity loss for my prototype, if that&amp;rsquo;s what it comes out to
be at long distance. I&amp;rsquo;m pondering what to do for the &amp;ldquo;real&amp;rdquo; version. One
option is to use a uC chip with more pins so I can dedicate one SPI bus
just to the radio, under the assumption that it&amp;rsquo;s just the SPI bus that
matters and that I can decouple power sufficiently. The other would be to
break things up and use separate PCBs and uCs for radio vs. display, etc.&lt;/p&gt;

&lt;p&gt;Sometimes accidents happen, as described in the &lt;a href=&#34;https://blog.voneicken.com/2018/saltwater-electronics&#34;&gt;next post&lt;/a&gt;&lt;/p&gt;</description>
		</item>
		
		<item>
			<title>Ocean Sports Fitness Tracker initial status</title>
			<link>https://blog.voneicken.com/2018/sports-tracker-initial/</link>
			<pubDate>Sun, 15 Jul 2018 00:00:00 UTC</pubDate>
			<author>Thorsten von Eicken</author>
			<guid>https://blog.voneicken.com/2018/sports-tracker-initial/</guid>
			<description>

&lt;p&gt;I&amp;rsquo;ve now taken the prototype on several outings and it&amp;rsquo;s starting to
become useful. I&amp;rsquo;m learning how much I can display one the screen so
I can actually read it with a quick glance while paddling and bouncing
up&amp;amp;down in the ocean. It currently displays speed, min-max speeds over
the past 10 seconds, heading, heart rate, time, LoRa RSSI, as well as
number of stored trackpoints. Sorely missing is distance covered and to
do that properly will take some work.&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/sports-tracker/20180714_153457_sml.jpg# fr w-40pct ml-3&#34; alt=&#34;Tracker mount with velcro&#34; /&gt;
&lt;em&gt;The tracker is mounted with velcro on the footrest. The velcro mostly
works but is not really strong enough when plunging through a wave. The
yellow lanyard on the left saves the day in those cases.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The LoRa link has been giving me some trouble. It is working but not
quite at the distance I need. Right now, trackpoints are recorded to the
SPI flash chip and when radio connectivity is available the trackpoints
are sent. What is happening is that I don&amp;rsquo;t have connectivity while
paddling and then on the drive home as I get closer it starts &amp;ldquo;spooling&amp;rdquo;
the recorded tracks. So everything is pretty much working except for the
fact that I don&amp;rsquo;t quite have the range I need. I&amp;rsquo;ve narrowed the problem
down to two issues: I have poor antenna positioning in the waterproof
case (I knew that) and the anetenna isn&amp;rsquo;t great (knew that too) but in
addition I&amp;rsquo;m loosing close to 10dB of RX sensitivity at my GW, which is
&amp;ldquo;not good&amp;rdquo;. Put differently, both ends TX at the same power level and
RX SNR is almost 10dB worse at the GW end. I&amp;rsquo;m suspecting it&amp;rsquo;s because
the radio is on a linux box (a CHIP), but it may well be something else.&lt;/p&gt;

&lt;p&gt;From my LoRa GW packets are injected into Node-red where they&amp;rsquo;re processed
and injected into the node-red-contrib-web worldmap. The code is currently
displaying the &amp;ldquo;real-time&amp;rdquo; position (except for the fact that there&amp;rsquo;s
no real-time radio connectivity) as well as a track. One of the photos
attached here shows one outing of about 6.3mi I did with the tracker.&lt;/p&gt;

&lt;p&gt;So far the proof of concept shows lots of promise and at the same time
there&amp;rsquo;s lots left to do! Yay!&lt;/p&gt;

&lt;h3 id=&#34;next-steps&#34;&gt;Next steps&lt;/h3&gt;

&lt;p&gt;The thing that bugs me the most is the LoRa radio connection. I&amp;rsquo;ve tried
a better antenna (home made dipole) and I get connectivity using that,
but it&amp;rsquo;s not great from an ergonomic point of view. And it made it clear
that if I could solve the 10dB RX sensitivity loss I could do with a
smaller antenna. So that&amp;rsquo;s the next thing to fix.&lt;/p&gt;

&lt;p&gt;One of the other tasks is to add code both in the tracker an in node-red
to smooth the track in order to be able to calculate distance covered
without over-inflating it due to GPS-induced zigzags. The keyword here
seems to be Ramer-Douglas-Peucker algorithm and some on-line variants
thereof.&lt;/p&gt;

&lt;p&gt;The other task is to automatically determine the start and end of an
outing using some form of geofencing, and then storing the track of each
outing in a proper database so it can be processed in various manners and
also sent to endomondo or a similar sports tracking site automatically.&lt;/p&gt;

&lt;p&gt;The &lt;a href=&#34;https://blog.voneicken.com/2018/spi-kills-lora&#34;&gt;next post&lt;/a&gt; describes some radio problems with the prototype.&lt;/p&gt;
</description>
		</item>
		
		<item>
			<title>Ocean Sports Fitness Tracker</title>
			<link>https://blog.voneicken.com/projects/sports-tracker-intro/</link>
			<pubDate>Sat, 14 Jul 2018 00:00:00 UTC</pubDate>
			<author>Thorsten von Eicken</author>
			<guid>https://blog.voneicken.com/projects/sports-tracker-intro/</guid>
			<description>&lt;p&gt;Real-time GPS tracker for surfskiing (or kayaking, paddling, rowing)
with real-time display as well as LoRa and LTE radios for safety.
&lt;/p&gt;

&lt;p&gt;The ocean sports fitness tracker&amp;rsquo;s purpose is to track a paddler in the
ocean, provide real-time performance feedback to the paddler on a screen,
and to also provide real-time tracking to on-shore family or buddies for
safety purposes. After the outing the track is saved for performance
analysis and long term monitoring of progress, possibly using one of
the popular sports fitness tracking sites.&lt;/p&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/sports-tracker/20180717_175701_sml.jpg# fr w-40pct ml-3&#34; alt=&#34;Tracker on surfski on the ocean in Santa Barbara&#34; /&gt;
&lt;em&gt;Taking the tracker on a test spin out on the ocean off Santa Barbara.&lt;/em&gt;&lt;/p&gt;

&lt;h3 id=&#34;background&#34;&gt;Background&lt;/h3&gt;

&lt;p&gt;The background for this project is that I recently started to surfski,
which is paddling a high-performance sit-on-top kayak in the open
ocean. The more wind and waves the better because that&amp;rsquo;s where it is the
most fun: surfskis are designed specifically for surfing waves in the open
ocean. With this activity come several challenges, in particular safety
and tracking one&amp;rsquo;s performance in order to learn and improve. Despite
first appearances, it&amp;rsquo;s a very technical sport and there is a lot to
learn both about stroke technique as well as wave riding skill.&lt;/p&gt;

&lt;p&gt;Most surfskiers use a GPS watch, e.g. a Garmin or similar, attached to
the foot strap. Looking at the prices and limitations of these things,
plus the fact that one ends up tied into some vendor&amp;rsquo;s tracking platform
made me want to build my own. There are also a few more specialized
trackers, such as SpeedCoach or from Vaaka, but they&amp;rsquo;re very pricey and
don&amp;rsquo;t provide a real-time connection for someone on shore to track from
a safety point of view.&lt;/p&gt;

&lt;p&gt;I tried to use an Android phone for many months and have concluded that
it just doesn&amp;rsquo;t work. Right off the bat the battery life doesn&amp;rsquo;t make
it. I use an excellent GPS tracking app designed to track family members
and it works beautifully as long as the phone screen is off and tucked
in my PFD. But it provides no real-time information about the speed
I&amp;rsquo;m going at, my heart rate, etc. If I use a sports tracking app that
displays this type of data and mount the phone so I can see it then the
battery lasts at best for an hour. Plus Android tries hard to terminate
the app to save battery. It has been an exercise in frustration!&lt;/p&gt;

&lt;h3 id=&#34;goals&#34;&gt;Goals&lt;/h3&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/sports-tracker/20180714_153359_sml.jpg# fr w-30pct ml-3&#34; alt=&#34;Surfski with mounted tracker&#34; /&gt;&lt;/p&gt;

&lt;p&gt;So I thought &amp;ldquo;how hard can it be?&amp;rdquo; :-). The minimal goals I set for the
tracker are the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;real-time GPS track&lt;/li&gt;
&lt;li&gt;heart rate monitor data capture&lt;/li&gt;
&lt;li&gt;display speed, time, distance, and heart rate in real-time on a
screen mounted to the footstrap&lt;/li&gt;
&lt;li&gt;transmit tracking info via LoRa and/or 4G LTE&lt;/li&gt;
&lt;li&gt;display progress on a web map with heart rate, current speed, etc&lt;/li&gt;
&lt;li&gt;waterproof enclosure for shallow immersion&lt;/li&gt;
&lt;li&gt;screen must be legible in full sunlight&lt;/li&gt;
&lt;li&gt;battery sufficient for 3 hour outings&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I have some additional stretch goals:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;display min/max speed so I can see the acceleration going down a wave
and the slow-down hitting the back of one&lt;/li&gt;
&lt;li&gt;determine paddle stroke parameters, such as stroke rate, stroke
distance, etc. using either boat acceleration or a paddle mounted sensor&lt;/li&gt;
&lt;li&gt;determine wave parameters, such as wave height, speed frequency using an accelerometer&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&#34;initial-prototype&#34;&gt;Initial prototype&lt;/h3&gt;

&lt;p&gt;&lt;img src=&#34;https://blog.voneicken.com/img/sports-tracker/20180707_153359_sml.jpg# fr w-40pct ml-3&#34; alt=&#34;Initial prototype&#34; /&gt;
&lt;em&gt;Inside the initial prototype. Transflective LCD at the top attached the inside of the lid.
GPS breakout and unused IMU breakout on top of the Jeenode Zero in the case body,
together with a suboptimal antenna. 18650 LiPo at the bottom with charger/protector
circuit attached to the left of the holder.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The initial prototype I build consists of a number of parts I cobbled
together from previous projects:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Small stm32L082 board (Jeenode) with Hoperf RFM98 433Mhz LoRa radio&lt;/li&gt;
&lt;li&gt;Globaltop PA6H GPS on adafruit breakout board&lt;/li&gt;
&lt;li&gt;Bosch BNO055 compass, accelerometer, gyro on Adafruit breakout board&lt;/li&gt;
&lt;li&gt;Small protoboard tieing everything together and having a 16MB SPI flash chip mounted&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In addition I added:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Battery holder for an 18650, with small USB charger board&lt;/li&gt;
&lt;li&gt;Monochrome transflective (&amp;ldquo;sunlight readable&amp;rdquo;) 128x64 LCD with SPI interface&lt;/li&gt;
&lt;li&gt;HM-11 bluetooth BLE radio to get the heart rate from a polaris 7 heart rate monitor&lt;/li&gt;
&lt;li&gt;Waterproof case with quick latch&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I threw the prototype together so I could answer a number of questions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;How well does the GPS track quick accelerations and decelerations?
(The Garmin phones tend to be really sluggish, the tracker in my Android
phone reliably records impossible speed bursts). I figured I might have
to try a couple of different GPS devices in order to find one that works
for the purpose.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Can I make the LoRa link work? I live about 10 miles (16km) away from
the harbor where I usually paddle and at an altitude of 2100ft (about
650m) where I have line of sight. But that&amp;rsquo;s quite a distance and starts
to cut into speed vs distance tradeoffs on the LoRa end. (Note that I&amp;rsquo;m
using LoRa &amp;ldquo;raw&amp;rdquo; and not LoRaWAN, which would not be suited due to the
data rate constraints it imposes.)&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Can I get one of the newer 4G LTE Cat-1M (or NB-IoT) radios to work?
What do the costs look like as well as how does the physical integration
look like?&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Can I process the data using Node-Red and perhaps produce a decent UI in node-red.&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Can I make any productive use of the BNO055 or is that just an infinite rabbit hole?&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;a href=&#34;https://blog.voneicken.com/2018/sports-tracker-initial&#34;&gt;next post&lt;/a&gt; describes the initial build.&lt;/p&gt;</description>
		</item>
		
		<item>
			<title>Test post</title>
			<link>https://blog.voneicken.com/2018/test-post/</link>
			<pubDate>Sat, 01 Jan 2000 00:00:00 UTC</pubDate>
			<author>Thorsten von Eicken</author>
			<guid>https://blog.voneicken.com/2018/test-post/</guid>
			<description>&lt;p&gt;This is a test post, there&amp;rsquo;s nothing useful here, sorry&amp;hellip;&lt;/p&gt;
</description>
		</item>
		
	</channel>
</rss>
