tag:blogger.com,1999:blog-15780104609212749162024-03-13T00:11:33.619+01:00Embedded InnovationYveauxhttp://www.blogger.com/profile/16599434883652140617noreply@blogger.comBlogger7125tag:blogger.com,1999:blog-1578010460921274916.post-75281577750774675992015-08-23T11:01:00.000+02:002015-08-23T11:01:51.826+02:00Hacking a wireless weather display<span style="font-family: Trebuchet MS, sans-serif;">A couple of years ago my wireless weather station broke down. Apparently the transmitter of the base unit stopped working and both the indoors display unit and the base station ended somewhere in the attic.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;">I got a new Alecto DKW-2012 weather station as a birthday present and all was well again (at least for a while...)</span><br />
<span style="font-family: Trebuchet MS, sans-serif;">One feature both weather stations lacked is logging of data over longer periods. And so a new project was born, using a Raspberry Pi to gather weather related sensor data and store it in a database on my home server. The broken weather station was hacked in all possible ways (new pressure, humidity and temperature sensor) and was mounted next to my other station.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: left; margin-right: 1em; text-align: left;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1JaGKgk1UEvCqFEHTB4asUmAXZdBSnZVm_dEArrQr4B5lx6pArTdAR_oC5rhbv9ra2wuoVMQnMlyaQjVGN87KlTqteNdInXNQY6KHsar5jPPAIBCSHf6h-0S749tRVF-WSngcVJSB2Q4/s1600/2weerstations.jpg" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img border="0" height="212" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1JaGKgk1UEvCqFEHTB4asUmAXZdBSnZVm_dEArrQr4B5lx6pArTdAR_oC5rhbv9ra2wuoVMQnMlyaQjVGN87KlTqteNdInXNQY6KHsar5jPPAIBCSHf6h-0S749tRVF-WSngcVJSB2Q4/s320/2weerstations.jpg" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: Trebuchet MS, sans-serif;">Left: the hacked weather station<br />Right: Alecto DKW-2012</span></td></tr>
</tbody></table>
<span style="font-family: 'Trebuchet MS', sans-serif;">This setup has been runnning fine for over two years now. The database contains over 1 million samples which I can view using a web browser and the indoor unit displays both time and weather data from the DKW-2012.</span><br />
<span style="font-family: 'Trebuchet MS', sans-serif;">Apart from looking a bit silly having two weather stations mounted next to eachother, the indoor unit also suffers from reception problems every now and then.</span><br />
<span style="font-family: 'Trebuchet MS', sans-serif;">Wouldn't it be nice to have a single weather station that logs all of its data and at the same time display this data on the wireless indoor display?</span><br />
<span style="font-family: 'Trebuchet MS', sans-serif;">I searched the net for any info on the Alecto DKW-2012. The line of Alecto weather stations </span><span style="font-family: 'Trebuchet MS', sans-serif;">is very similar (or identical) to units produced by </span><a href="http://www.foshk.com/" style="font-family: 'Trebuchet MS', sans-serif;" target="_blank">Fine Offset Electronics</a><span style="font-family: Trebuchet MS, sans-serif;">. They operate at 868.3MHz and </span><span style="font-family: 'Trebuchet MS', sans-serif;">are reported to use either </span><a href="https://en.wikipedia.org/wiki/Frequency-shift_keying" style="font-family: 'Trebuchet MS', sans-serif;" target="_blank">FSK</a><span style="font-family: 'Trebuchet MS', sans-serif;"> or </span><a href="https://en.wikipedia.org/wiki/On-off_keying" style="font-family: 'Trebuchet MS', sans-serif;" target="_blank">OOK</a><span style="font-family: 'Trebuchet MS', sans-serif;"> modulation.</span><br />
<span style="font-family: 'Trebuchet MS', sans-serif;">Using a DVB-T USB stick I was able to capture the data sent by the base station.</span><br />
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5Ocl2ycVgE5eOdXlabwQTD5glhEz8w444H9zJsKtKI0JZ8kqwGUaXKwJhPsJJfZVkeh6MRr86MPQNogLTp4Q-VyoEGv9BqY8WWstBpF0ewOQTURPOZf6_8N9xm7NuTvB6MNkOM0l5kC8/s1600/message.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="49" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5Ocl2ycVgE5eOdXlabwQTD5glhEz8w444H9zJsKtKI0JZ8kqwGUaXKwJhPsJJfZVkeh6MRr86MPQNogLTp4Q-VyoEGv9BqY8WWstBpF0ewOQTURPOZf6_8N9xm7NuTvB6MNkOM0l5kC8/s640/message.png" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: Trebuchet MS, sans-serif;">Complete weather data message</span></td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: center;">
</div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhRVdwl852KjdVGPsg-Wd30-w_H6mskd8LLtA3Mgyz87LFilmRprFONh49wWPjK3u5o2TqQBtQvwWUZ7kgHSRuCMEdxveYAB74fe5lGDl52E-_a57wos8fhtqcvYouBqGN7rtXQfEbRhIs/s1600/detail.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="47" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhRVdwl852KjdVGPsg-Wd30-w_H6mskd8LLtA3Mgyz87LFilmRprFONh49wWPjK3u5o2TqQBtQvwWUZ7kgHSRuCMEdxveYAB74fe5lGDl52E-_a57wos8fhtqcvYouBqGN7rtXQfEbRhIs/s640/detail.png" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: Trebuchet MS, sans-serif;">Start of message</span></td></tr>
</tbody></table>
<span style="font-family: 'Trebuchet MS', sans-serif;">What I learned from capturing this data (and some research on the net):</span><br />
<ul>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">All data is sent using OOK modulation</span></li>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">Bitrate is 2kbit/s (the short yellow stripes show the bit time of 500us)</span></li>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">On air, a binary '1' is encoded as 100 and a binary '0' as 11100</span></li>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">The </span><a href="https://en.wikipedia.org/wiki/Syncword#Preamble" style="font-family: 'Trebuchet MS', sans-serif;" target="_blank">preamble</a><span style="font-family: 'Trebuchet MS', sans-serif;"> is 0xFF</span></li>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">A complete message consists of 11 bytes (including preamble)</span></li>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">Messages duration varies, depending on its content, roughly between 130 and 220 ms.</span></li>
</ul>
<br />
<span style="font-family: 'Trebuchet MS', sans-serif;">Some code found on the web details the protocol (e.g. <a href="http://www.nodo-domotica.nl/Download/Stable/Plugins/Plugin_009.c" target="_blank">nodo</a>) but I couldn't find any project that transmits weather data. I did however find some code by <a href="https://github.com/SevenW/embapps/blob/master/ArduinoRFM69/rfm69-RF12demo-ook-TX/rfm69-RF12demo-ook-TX.ino" target="_blank">SevenWatt</a> that uses an Arduino and RFM69W to transmit OOK modulated signals.</span><br />
<span style="font-family: 'Trebuchet MS', sans-serif;">Using this code as a base, a Moteino with RFM69W and the </span><span style="font-family: 'Trebuchet MS', sans-serif;">DVB-T USB stick to analyze the actual on-air data I was able to take control of my wireless indoor display!</span><br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgsRaXpUJ8PbBKkjLMjPnztvsL-arlg2HrjJh8e799oDuxiWocWr7SJ7XaVZeZmoKXs0yjyUAO0Ns8YA7E2jDjGSWQkIiJVkqmJqG02OOx3aitetjkiQih8_xzbyBXgApj0YZsIAwKDYI8/s1600/DKW2012.gif" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgsRaXpUJ8PbBKkjLMjPnztvsL-arlg2HrjJh8e799oDuxiWocWr7SJ7XaVZeZmoKXs0yjyUAO0Ns8YA7E2jDjGSWQkIiJVkqmJqG02OOx3aitetjkiQih8_xzbyBXgApj0YZsIAwKDYI8/s1600/DKW2012.gif" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: Trebuchet MS, sans-serif;">'Possessed' DKW-2012 weather display</span></td></tr>
</tbody></table>
<span style="font-family: Trebuchet MS, sans-serif;">As a proof-of-concept all values on the display are continuously increased by 3. The Arduino sketch can be found <a href="https://github.com/Yveaux/Weatherstation_Display/tree/master/Weatherstation_transmitter" target="_blank">here</a> (for RFM69W connections refer to the <a href="http://lowpowerlab.com/moteino/#pinout" target="_blank">Moteino pinouts</a>)</span><br />
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">Next step was to actually get some real values from my hacked weather station on the display. My home server, which stores the weather data in a database, also publishes this data to an <a href="http://mqtt.org/" target="_blank">MQTT</a> broker. A <a href="http://nodered.org/" target="_blank">Node-RED</a> installation subscribes to this data and re-publishes each value to topics recognized by an <a href="https://github.com/Yveaux/MySensors_MQTTGateway" target="_blank">MQTT MySensors Gateway</a> which I wrote some time ago. The gateway distributes these values to wireless sensor nodes in a </span><a href="http://www.mysensors.org/" style="font-family: 'Trebuchet MS', sans-serif;" target="_blank">MySensors</a><span style="font-family: Trebuchet MS, sans-serif;"> network.</span><br />
<br /></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">I hooked up an nRF24L01+ to the Moteino to be able to communicate with the MySensors network, using the following connections:</span></div>
<div>
<br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: right; text-align: right;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2XWs3dr7yuUtVg2FYVu-sc-2o4e0Z4KTUyK5qjVctNnK0h62ZqsMrV4kspizAfIydSYc-5TeyIMLrmFWPM9vagjlAbxx1kNUKojhe8rCwH4FsDFliV2mNZOzWNQkWe_knR1izxf2bN9w/s1600/nRF24L01.png" imageanchor="1" style="clear: right; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img border="0" height="106" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2XWs3dr7yuUtVg2FYVu-sc-2o4e0Z4KTUyK5qjVctNnK0h62ZqsMrV4kspizAfIydSYc-5TeyIMLrmFWPM9vagjlAbxx1kNUKojhe8rCwH4FsDFliV2mNZOzWNQkWe_knR1izxf2bN9w/s1600/nRF24L01.png" width="200" /></a></td></tr>
<tr><td class="tr-caption" style="font-size: 12.8000001907349px; text-align: center;"><span style="font-family: Trebuchet MS, sans-serif;">nRF24L01+ module pinout</span></td></tr>
</tbody></table>
<span style="font-family: Trebuchet MS, sans-serif;"></span><br />
<table style="table-layout: fixed; width: 305px;"><colgroup><col style="width: 87px;"></col><col style="width: 79px;"></col><col style="width: 26px;"></col><col style="width: 113px;"></col></colgroup><tbody>
<tr><th><span style="font-family: Trebuchet MS, sans-serif;">Function</span></th><th><span style="font-family: Trebuchet MS, sans-serif;">Moteino pin</span></th><th></th><th><span style="font-family: Trebuchet MS, sans-serif;">nRF24L01+</span><br />
<span style="font-family: Trebuchet MS, sans-serif;">pin</span></th></tr>
<tr><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">GND</span></div>
</td><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">GND</span></div>
</td><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">-</span></div>
</td><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">1</span></div>
</td></tr>
<tr><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">3.3V</span></div>
</td><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">3.3V</span></div>
</td><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">-</span></div>
</td><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">2</span></div>
</td></tr>
<tr><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">CE</span></div>
</td><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">7</span></div>
</td><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">-</span></div>
</td><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">3</span></div>
</td></tr>
<tr><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">CSN/CS</span></div>
</td><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">8</span></div>
</td><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">-</span></div>
</td><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">4</span></div>
</td></tr>
<tr><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">SCK</span></div>
</td><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">13</span></div>
</td><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">-</span></div>
</td><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">5</span></div>
</td></tr>
<tr><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">MOSI</span></div>
</td><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">11</span></div>
</td><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">-</span></div>
</td><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">6</span></div>
</td></tr>
<tr><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">MISO</span></div>
</td><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">12</span></div>
</td><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">-</span></div>
</td><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">7</span></div>
</td></tr>
<tr><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">IRQ</span></div>
</td><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">--</span></div>
</td><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">-</span></div>
</td><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">--</span></div>
</td></tr>
</tbody></table>
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span><br />
<span style="font-family: 'Trebuchet MS', sans-serif;">This <a href="https://github.com/Yveaux/Weatherstation_Display/tree/master/Weatherstation_transmitter_mysensors" target="_blank">Arduino sketch</a> has the MySensors stack integrated and executes the following tasks:</span><br />
<br />
<ul>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">Configure both the RFM69W and the MySensors library</span></li>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">Run 3 simultaneous statemachines:</span></li>
<ul>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">Request wallclock time from the MySensors Gateway and send this data as a DCF77 encoded message to the wireless display. This process repeats every hour.</span></li>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">Request the weather data we're interested in (temperature, humidity, windspeed, gust, rain) from the Gateway. This triggers automatic subscription to the corresponding MQTT topics. Once the statemachine has received a value for each topic (and thus subscription to all topics has succeeded) it becomes dormant, waiting for new values to be published by the Gateway. When one or more values come in, it triggers the next statemachine:</span></li>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">Send sensor data to the wireless display. If no new sensor data comes in for 1 minute, old data is repeated (to prevent the display from blanking after 6.5min without receiving new data)</span></li>
</ul>
</ul>
<span style="font-family: Trebuchet MS, sans-serif;"><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgeWyt_VBZ6aebtvyb3XO_an8O7bVXTHLFBiLs2whR5snVUbK63Q6j9UsksngY_QYfAnj7DUB_T6tD6qi-La_Nc8PdRYIdiwjhB9VOPzGyHvSyQ83scnifDv9jaNoj7zyR07AMBZ5frYkM/s1600/WS2900.gif" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgeWyt_VBZ6aebtvyb3XO_an8O7bVXTHLFBiLs2whR5snVUbK63Q6j9UsksngY_QYfAnj7DUB_T6tD6qi-La_Nc8PdRYIdiwjhB9VOPzGyHvSyQ83scnifDv9jaNoj7zyR07AMBZ5frYkM/s1600/WS2900.gif" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">The same hack also works for an Alecto WS-2900 display!</td></tr>
</tbody></table>
The hack is running rock-solid, and as a result there is a vacant position on my roof now!</span></div>
Yveauxhttp://www.blogger.com/profile/16599434883652140617noreply@blogger.com4tag:blogger.com,1999:blog-1578010460921274916.post-46901867667415475312014-08-17T19:02:00.000+02:002015-05-23T10:53:51.842+02:00WTV020-SD Regular SD Card hack<span style="font-family: Trebuchet MS, sans-serif;">I ordered a WTV020-SD audio player module from <a href="http://www.ebay.com/itm/MP3-Voice-module-U-disk-audio-player-SD-card-voice-module-WTV020-SD-16P-M5-/291105967190?pt=LH_DefaultDomain_0&hash=item43c7448c56" target="_blank">eBay</a> for an MP3-player doorbell project. These modules support an MP3-player mode, but do not play regular MP3 files. MP3 player mode just seems to hint at being able to play/pause/skip tracks on the micro-SD card. Furthermore these modules are <i>very picky</i> about the micro-SD cards used. I found exactly one Sandisk 2Gb card which plays correctly, all others tested don't play at all...</span><br />
<span style="font-family: Trebuchet MS, sans-serif;">As I planned to build multiple wireless doorbell nodes I needed more supported micro-SD cards.<a href="https://www.blogger.com/"></a></span><br />
<span style="font-family: 'Trebuchet MS', sans-serif;">After google'ing around it appeared I wasn't alone in the quest for micro-SD cards supported by this little player. Most reports of cards working were for relatively small cards of 1Gb or less, but I didn't plan on buying a batch of overprized micro-SD cards at random, hoping they would play in the WTV020-SD module.</span><br />
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span>
<br />
<h3>
<span style="font-family: 'Trebuchet MS', sans-serif;">SD cards to the rescue</span></h3>
<div>
<span style="font-family: 'Trebuchet MS', sans-serif;">Going through my collection of SD cards I found out I had quite a lot of small-capacity <i>regular </i>SD cards lying around.</span></div>
<div>
<span style="font-family: 'Trebuchet MS', sans-serif;">So I heated my soldering iron and attached a modified male header to function as SD card connector.</span></div>
<div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifnzgOV7eBaeZHd6YZedkFYwF02GDY_ulUqWdt2oXAV5SBtXKTT4gibiH0WwFeg_IMLjrBX9pAC1p4nAQ9Irc2-fWIuRMcWhI8Xn0QlBuU9Kc_hvWKnsE9gxrG4azz7leKj8R1wX8nHW0/s1600/WTV020M01a.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="185" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifnzgOV7eBaeZHd6YZedkFYwF02GDY_ulUqWdt2oXAV5SBtXKTT4gibiH0WwFeg_IMLjrBX9pAC1p4nAQ9Irc2-fWIuRMcWhI8Xn0QlBuU9Kc_hvWKnsE9gxrG4azz7leKj8R1wX8nHW0/s320/WTV020M01a.jpg" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: 'Trebuchet MS', sans-serif; font-size: x-small;">DIY SD card connector soldered to the WTV020-SD</span></td></tr>
</tbody></table>
</div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7kp2f0dNT8e_JfR5KvU6wrxIVWOshlzkehOidpGvEZBwqhoVspPvVxQgc985LXyI2fVxcUb03AFA5e5KrnJpaP4JAfCP2B8mKnqgzIhFdzM72RPkMHgvNP-DNGWC42CzjaFR9AN9tqgE/s1600/WTV020M01b.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="246" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7kp2f0dNT8e_JfR5KvU6wrxIVWOshlzkehOidpGvEZBwqhoVspPvVxQgc985LXyI2fVxcUb03AFA5e5KrnJpaP4JAfCP2B8mKnqgzIhFdzM72RPkMHgvNP-DNGWC42CzjaFR9AN9tqgE/s1600/WTV020M01b.jpg" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: Trebuchet MS, sans-serif;">Close-up of the WTV020-SD</span></td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: Trebuchet MS, sans-serif;">First I tried the supported 2Gb Sandisk using a SD to micro-SD adapter and voila, it worked!</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: Trebuchet MS, sans-serif;">Now I wrote a few audio tracks to all of the smaller SD cards and inserted them in the DIY SD card adapter one-by-one. Below are all the cards in my collection which appeared to work correctly with the sound module:</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhY2QvhGwJbdvKBwCZq7Ct84wbg8J2W8BMe43eBzfPaDLidJO37I0VJNZ90qt6Fyc-xUYnLhuB1L-2nfrELaKxavrwo0830hx2rklkxst_EmU6SeRouzuwvHlxQaVw8_Zgr2CZtW1Km1pY/s1600/WTV020M01c.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="252" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhY2QvhGwJbdvKBwCZq7Ct84wbg8J2W8BMe43eBzfPaDLidJO37I0VJNZ90qt6Fyc-xUYnLhuB1L-2nfrELaKxavrwo0830hx2rklkxst_EmU6SeRouzuwvHlxQaVw8_Zgr2CZtW1Km1pY/s1600/WTV020M01c.jpg" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: Trebuchet MS, sans-serif;">Regular SD Cards found working with the WTV020-SD</span></td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: Trebuchet MS, sans-serif;">Especially the Platinum cards are interesting. I once bought 3 of them simultaneously, but only 2 work correctly with the sound module... This once more confirms the hocus pocus going on in this module!</span></div>
<div>
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
Yveauxhttp://www.blogger.com/profile/16599434883652140617noreply@blogger.com3tag:blogger.com,1999:blog-1578010460921274916.post-40993421048529734932014-07-28T21:37:00.000+02:002015-05-23T10:56:35.178+02:00nRF24L01+ sniffer - part 3<span style="font-family: Trebuchet MS, sans-serif;">In the first two parts of this series I explained the mechanism behind 'promiscuous' capturing of nRF24L01+ packets on air. I explained how to build hardware and install software to be able to capture the packets and analyze them using Wireshark. This post will dive deeper into the possibilities of the wireless sniffer and Wireshark combo and give you some insight in what this powerful tool has to offer.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<br />
<h3>
<span style="font-family: Trebuchet MS, sans-serif;">Wireshark basics</span></h3>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<span style="font-family: Trebuchet MS, sans-serif;">If you followed the instructions to install the sniffer software and start Wireshark in the previous post, Wireshark should now be capturing:</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhC-7jC29QaspxlB8FWNH0u_tYcRxw6JYhfQEl3p5mgfkkdN5dNP6MsWZuOAAru9W6opWlGhJ6Er7blUk0sjIrYZUSPZemXPcjXVZDI4ZfwSlM4QEA6gWYqZ7luYxx-9mOXYeixszbXrm8/s1600/ws1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="444" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhC-7jC29QaspxlB8FWNH0u_tYcRxw6JYhfQEl3p5mgfkkdN5dNP6MsWZuOAAru9W6opWlGhJ6Er7blUk0sjIrYZUSPZemXPcjXVZDI4ZfwSlM4QEA6gWYqZ7luYxx-9mOXYeixszbXrm8/s1600/ws1.png" width="640" /></a></div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">The capture screen is divided in three parts: The packets captured, the details of the selected packet and the raw packet & payload data.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;">Packets captured each have a sequential number, and a timestamp (captured with microsecond resolution by the sniffer). These are shown in the first two columns of the packet list named <i>No.</i> and <i>Time</i>. Next two columns contain the <i>Source </i>node address and <i>Destination </i>node address (the base address has been omitted). As nRF24L01+ packets only contain a destination address, the source address will display a question mark. Later we will see that when a higher-level protocol contains the source node address this will be filled. Next is the <i>Protocol</i> column. When capturing the screenshot I only had the nrf24 dissector installed (nrf24.dll in the Wireshark plugins directory), so Wireshark only recognizes nRF24 packages. By adding extra dissectors (e.g. for MySensors) it will also recognize protocols that use the nRF24 as transport medium. Next column is the total packet <i>Length</i>, in bytes followed by the <i>Info</i> column which contains a short, textual description of the packet data. I chose to display the full address (base+node), payload length, pid and ack-flag (inverted NO_ACK).</span><br />
<span style="font-family: Trebuchet MS, sans-serif;">Packets of length 0 are interpreted by the nRF24 as acknowledgement packets.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;">The nrf24 dissector calculates the CRC value of every packet. This value should match with the CRC stored in the packet. The CRC for packet 165 apparently failed, therefore it is marked as 'CRC Error' in the info column and its contents cannot be trusted.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;">When a packet is selected its details appear in the section below. Here you can see, bit by bit, how the packet is dissected.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;">Click on one of the fields and its location in the raw packet data will be shown in the section at the bottom. When a packet contains a payload that can further be dissected its raw data are shown in a separate tab (e.g. 'Frame (22bytes)' for the raw frame data and 'NRF24 Payload Data (12 bytes)' for the actual payload data.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;">This observation is important as the nRF24 has a header which is not a multiple of 8 bits. Any bytes stored as payload will appear bit-shifted in the 'Frame' data, but are shown as regular bytes in the 'NRF24 Payload Data'. In the screenshot the 'NRF24 Payload Data' is shown, in which you might even recognize a MySensors payload: a temperature reading of 24.9 degrees.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<br />
<h3>
<span style="font-family: Trebuchet MS, sans-serif;">Filtering</span></h3>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<span style="font-family: 'Trebuchet MS', sans-serif;">One of the most powerful features of Wireshark is filtering. Packets captured can be filtered using expressions on the details of the packet data. The nrf24 dissector recognizes the folowing filter keywords:</span><br />
<br />
<div>
<ul>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">nrf24.node - full node addres, including base address</span></li>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">nrf24.ctrl - control field value</span></li>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">nrf24.ctrl.len - payload length</span></li>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">nrf24.ctrl.pid - pid value</span></li>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">nrf24.ctrl.noack - NO_ACK flag</span></li>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">nrf24.crc - CRC value</span></li>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">nrf24.crcvalid - flag indicating if CRC is valid or not</span></li>
</ul>
</div>
<span style="font-family: Trebuchet MS, sans-serif;">Filter expressions are entered in the 'Filter:' editbox on the top of the screen.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">Now lets display all packets captured with CRC errors:</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiV4wvpFxl2SYzvENJ4ch0oZ-wanJoqw8RjiqaNJ1VeWeGRON_KSJDDkK4ircYabslMOfn2bBXDLRVgUYjo4__aNOOdaut2L-QT9RPv22QYudUxT3Y-I02zZfr-fzviEVWbJeuT8IgovRU/s1600/ws2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="446" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiV4wvpFxl2SYzvENJ4ch0oZ-wanJoqw8RjiqaNJ1VeWeGRON_KSJDDkK4ircYabslMOfn2bBXDLRVgUYjo4__aNOOdaut2L-QT9RPv22QYudUxT3Y-I02zZfr-fzviEVWbJeuT8IgovRU/s1600/ws2.png" width="640" /></a></div>
<br />
<span style="font-family: Trebuchet MS, sans-serif;">Enter 'nrf24.crcvalid == false' and press Apply.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;">Or filter on all packets with payload of 22 bytes or more, and valid CRC:</span><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgeQM7fB2MgAB2nrdyHjdc6Ihuz3voLBLWHj_wK6vcPfIKxytDU3up6SaSsykuPJ6I9EKvMesdZL-UuSyzBkoxMgDJkxK6P-eOAjsQPw7RXc3Vxa7Njkea6SCw2cVBAO9xwRdWrnfVeIAM/s1600/ws3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="446" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgeQM7fB2MgAB2nrdyHjdc6Ihuz3voLBLWHj_wK6vcPfIKxytDU3up6SaSsykuPJ6I9EKvMesdZL-UuSyzBkoxMgDJkxK6P-eOAjsQPw7RXc3Vxa7Njkea6SCw2cVBAO9xwRdWrnfVeIAM/s640/ws3.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">You probably get it by now, right? For the filter syntax please refer to the <a href="http://www.wireshark.org/docs/wsug_html_chunked/ChWorkBuildDisplayFilterSection.html" target="_blank">Wireshark user's guide</a>.</span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<h3>
<span style="font-family: Trebuchet MS, sans-serif;">IO Graph and statistics</span></h3>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">Another nice feature for long term capturing is the IO graph, available through the menu Statistics -> IO Graph.</span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">After capturing for a while and moving the sensor node around a bit, the graph looked like:</span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVmTFtFJtBMfdwOu1r0w_r5CSeQHmar9Lx7Vm54lZBqFizoRTo6UIOVnCWTQQDGcIwm34yjW_dZImmrExHewE4pPQmfkz5-KEgNcx7Y9WU5sVhd1RYXao2vxr2yKxIT1tmFKEuduZx9Pw/s1600/iochart.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="451" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVmTFtFJtBMfdwOu1r0w_r5CSeQHmar9Lx7Vm54lZBqFizoRTo6UIOVnCWTQQDGcIwm34yjW_dZImmrExHewE4pPQmfkz5-KEgNcx7Y9WU5sVhd1RYXao2vxr2yKxIT1tmFKEuduZx9Pw/s1600/iochart.png" width="640" /></a></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">The black line shows the number of packets per 10 sec. over a timespan of a little over 700 seconds. When the sensor node started, the number of packets peaked at approx. 200 packets. It then settled at around 40, to increase again after 450 sec.</span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">I enabled 'Graph 2' with the previously explored CRC invalid expression, which is drawn as red bars in the graph. Apparently the location where I moved the sensor node after 450 sec. lead to a clear increase in CRC errors!</span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">Wireshark has many, many more possibilities to analyze your network traffic. I suggest to play around for a while and <a href="http://www.wireshark.org/docs/wsug_html_chunked/index.html" target="_blank">explore the user manual</a>.</span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<h3>
<span style="font-family: Trebuchet MS, sans-serif;">MySensors dissector</span></h3>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">Along with the nrf24 dissector I also wrote two dissectors for the <a href="http://www.mysensors.org/" target="_blank">MySensors</a> protocol. The stable version 1.3 will be dissected by mysensors1.dll, the beta 1.4 by mysensors2.dll. As said before, only have one of the mysensors dissectors active in the plugins directory, as Wireshark might otherwise mixup protocol versions 1 & 2 in a single capture. Below is a screenshot of a MySensors 1.4b communication capture, between nodes 0 (gateway) and 124 (</span><span style="font-family: 'Trebuchet MS', sans-serif;">sensor):</span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXtPWwPtbHxVHeTDCiI99Nx0Pr3GXN1b-aoyqWKGEcQvoav-nr_EskuTy5_khNoaq59omgIHPDALd7hk3T7q4-a-FdHjV87M3ZNluQJJ64vaxxfHZWznd31Av8uzfnqhyphenhypheniU1OytxIqVBQ/s1600/ms.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="442" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXtPWwPtbHxVHeTDCiI99Nx0Pr3GXN1b-aoyqWKGEcQvoav-nr_EskuTy5_khNoaq59omgIHPDALd7hk3T7q4-a-FdHjV87M3ZNluQJJ64vaxxfHZWznd31Av8uzfnqhyphenhypheniU1OytxIqVBQ/s1600/ms.png" width="640" /></a></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">In the selected packet an acknowledge of a temperature value is sent by the gateway to the sensor node. Note that both <i>Source </i>and <i>Destination </i>node addresses are now set for the packets of the mysensors <i>Protocol</i>.</span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">For version 1 (1.3) the following filters are supported:</span></div>
<div>
<ul>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">mysensors.crc - CRC value</span></li>
<li><span style="font-family: Trebuchet MS, sans-serif;">mysensors.crcvalid - CRC Valid flag</span></li>
<li><span style="font-family: Trebuchet MS, sans-serif;">mysensors.version - Version (always 1)</span></li>
<li><span style="font-family: Trebuchet MS, sans-serif;">mysensors.binary - Binary flag</span></li>
<li><span style="font-family: Trebuchet MS, sans-serif;">mysensors.sender - Sender node address</span></li>
<li><span style="font-family: Trebuchet MS, sans-serif;">mysensors.dest - Destination node address</span></li>
<li><span style="font-family: Trebuchet MS, sans-serif;">mysensors.last - Last node address</span></li>
<li><span style="font-family: Trebuchet MS, sans-serif;">mysensors.childid - ChildID for sensor value</span></li>
<li><span style="font-family: Trebuchet MS, sans-serif;">mysensors.msgtype - Message type</span></li>
<li><span style="font-family: Trebuchet MS, sans-serif;">mysensors.subtype - Sub type</span></li>
</ul>
</div>
<div>
<br /></div>
<div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">For version 2 (1.4) the following filters are supported:</span></div>
</div>
<div>
<ul>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">mysensors.paylen - Length of payload, in bytes</span></li>
<li><span style="font-family: Trebuchet MS, sans-serif;">mysensors.version - Version (always 2)</span></li>
<li><span style="font-family: Trebuchet MS, sans-serif;">mysensors.datatype - Data type</span></li>
<li><span style="font-family: Trebuchet MS, sans-serif;">mysensors.cmdtype - Command type</span></li>
<li><span style="font-family: Trebuchet MS, sans-serif;">mysensors.ack - Ack flag</span></li>
<li><span style="font-family: Trebuchet MS, sans-serif;">mysensors.sender - Sender node address</span></li>
<li><span style="font-family: Trebuchet MS, sans-serif;">mysensors.last - Last node address</span></li>
<li><span style="font-family: Trebuchet MS, sans-serif;">mysensors.dest - Destination node address</span></li>
<li><span style="font-family: Trebuchet MS, sans-serif;">mysensors.type - Type</span></li>
<li><span style="font-family: Trebuchet MS, sans-serif;">mysensors.sensor - Sensor</span></li>
</ul>
<span style="font-family: Trebuchet MS, sans-serif;">Capturing all messages to the gateway (dest == 0) for sensor 3 (ChildId 3) results in the following display:</span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiAa4U9HNJpY8_nRNjjMO0jLk089DqrDbfkY2EHKkCld0P0ztWc2T0k5LFdaWzxdBvOLf_nlK2RxL99xldI6HBoWKB0aM5CLzUtHgu7QQsN7JmwiJAXIGVD4mcs91MS2QzhgaWkq9oL8rY/s1600/ms2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="430" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiAa4U9HNJpY8_nRNjjMO0jLk089DqrDbfkY2EHKkCld0P0ztWc2T0k5LFdaWzxdBvOLf_nlK2RxL99xldI6HBoWKB0aM5CLzUtHgu7QQsN7JmwiJAXIGVD4mcs91MS2QzhgaWkq9oL8rY/s1600/ms2.png" width="640" /></a></div>
<div>
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
<h3>
<span style="font-family: 'Trebuchet MS', sans-serif;">Wrapup</span></h3>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">In the past days I've presented a wireless packet sniffer for nRF24L01+ radios. It has very powerful features, thanks to the integration of Wireshark, but also has some limitations anyone who uses it should be aware of.</span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">Currently the dissectors cannot be configured, so packets are always assumed to be in Enhanced Shockburst format, with 1 byte node address and 2 byte CRC value.</span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">Always remember that the nRF24 sniffer uses a regular radio to capture that packets on air. Sometimes it detects CRC errors, while another node will receive the packet correctly, and vice versa.</span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
Yveauxhttp://www.blogger.com/profile/16599434883652140617noreply@blogger.com31tag:blogger.com,1999:blog-1578010460921274916.post-68533695818078005352014-07-27T16:49:00.001+02:002015-05-23T11:01:48.277+02:00nRF24L01+ sniffer - part 2<h3>
<span style="font-family: Trebuchet MS, sans-serif;">Hardware</span></h3>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">The requirement to use cheap commodity hardware resulted in the use of a standard <a href="http://arduino.cc/en/Main/ArduinoBoardUno" target="_blank">Arduino Uno R3</a> and a single <a href="http://www.ebay.com/itm/Arduino-NRF24L01-2-4GHz-Antenna-Wireless-Transceiver-Module-Microcontroll-/310670158878?pt=LH_DefaultDomain_0&hash=item4855626c1e" target="_blank">nRF24L01+ module</a>. Some male-female Dupont cables connect the radio to the Arduino. Other Arduino's based on AtMega328 should also work, as long as they have a serial interface to the PC and 3.3V power supply for the radio (the nRF24 I/O pins are 5V tolerant).</span><br />
<span style="font-family: Trebuchet MS, sans-serif;">Be careful as multiple variants exist of the nRF24L01+ modules, and they don't all use the same layout for the pin header!</span></div>
<div>
<br />
<span style="font-family: Trebuchet MS, sans-serif;"></span>
<span style="font-family: Trebuchet MS, sans-serif;">Connect the two as follows:</span><br />
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: right; text-align: right;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2XWs3dr7yuUtVg2FYVu-sc-2o4e0Z4KTUyK5qjVctNnK0h62ZqsMrV4kspizAfIydSYc-5TeyIMLrmFWPM9vagjlAbxx1kNUKojhe8rCwH4FsDFliV2mNZOzWNQkWe_knR1izxf2bN9w/s1600/nRF24L01.png" imageanchor="1" style="clear: right; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img border="0" height="106" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2XWs3dr7yuUtVg2FYVu-sc-2o4e0Z4KTUyK5qjVctNnK0h62ZqsMrV4kspizAfIydSYc-5TeyIMLrmFWPM9vagjlAbxx1kNUKojhe8rCwH4FsDFliV2mNZOzWNQkWe_knR1izxf2bN9w/s1600/nRF24L01.png" width="200" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: Trebuchet MS, sans-serif;">nRF24L01+ module pinout</span></td></tr>
</tbody></table>
<span style="font-family: Trebuchet MS, sans-serif;"></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"></span>
<br />
<table style="table-layout: fixed; width: 305px;"><colgroup><col style="width: 87px;"></col><col style="width: 79px;"></col><col style="width: 26px;"></col><col style="width: 113px;"></col></colgroup><tbody>
<tr><th><span style="font-family: Trebuchet MS, sans-serif;">Function</span></th><th><span style="font-family: Trebuchet MS, sans-serif;">Arduino Uno pin</span></th><th></th><th><span style="font-family: Trebuchet MS, sans-serif;">nRF24L01+</span><br />
<span style="font-family: Trebuchet MS, sans-serif;">pin</span></th></tr>
<tr><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">GND</span></div>
</td><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">GND</span></div>
</td><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">-</span></div>
</td><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">1</span></div>
</td></tr>
<tr><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">3.3V</span></div>
</td><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">3.3V</span></div>
</td><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">-</span></div>
</td><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">2</span></div>
</td></tr>
<tr><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">CE</span></div>
</td><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">9</span></div>
</td><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">-</span></div>
</td><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">3</span></div>
</td></tr>
<tr><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">CSN/CS</span></div>
</td><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">10</span></div>
</td><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">-</span></div>
</td><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">4</span></div>
</td></tr>
<tr><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">SCK</span></div>
</td><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">13</span></div>
</td><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">-</span></div>
</td><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">5</span></div>
</td></tr>
<tr><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">MOSI</span></div>
</td><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">11</span></div>
</td><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">-</span></div>
</td><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">6</span></div>
</td></tr>
<tr><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">MISO</span></div>
</td><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">12</span></div>
</td><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">-</span></div>
</td><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">7</span></div>
</td></tr>
<tr><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">IRQ</span></div>
</td><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">2</span></div>
</td><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">-</span></div>
</td><td><div style="text-align: center;">
<span style="font-family: Trebuchet MS, sans-serif;">8</span></div>
</td></tr>
</tbody></table>
<span style="font-family: Trebuchet MS, sans-serif;"></span></div>
<div>
<div style="text-align: center;">
<div style="text-align: left;">
<span style="font-family: Trebuchet MS, sans-serif;"></span><br />
<span style="font-family: Trebuchet MS, sans-serif;"></span></div>
</div>
</div>
<div>
<div style="text-align: left;">
<span style="font-family: Trebuchet MS, sans-serif;">Some applications don't connect the IRQ line, but the sniffer requires it to quickly respond to received packets.</span></div>
<div style="text-align: left;">
<span style="font-family: Trebuchet MS, sans-serif;">This is what my sniffer looks like:</span></div>
<div style="text-align: left;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhE4mGRZrRwjApy8n97nc3p0gkmH9lWnii-jZmh1o0e8tIvHY6lF9d5Do6Pwp_6YKudrWTGQ3rbJXYO-INoUtB-UScjzqnKbIBOIL08jgdwEGptDHF3x238Xlc-QixrUnJwadEW6h7REHY/s1600/2014-07-26+21.25.40.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhE4mGRZrRwjApy8n97nc3p0gkmH9lWnii-jZmh1o0e8tIvHY6lF9d5Do6Pwp_6YKudrWTGQ3rbJXYO-INoUtB-UScjzqnKbIBOIL08jgdwEGptDHF3x238Xlc-QixrUnJwadEW6h7REHY/s1600/2014-07-26+21.25.40.jpg" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: Trebuchet MS, sans-serif;">nRF24 sniffer hardware: Arduino Uno, prototype shield, some Dupont cables and nRF24L01+ module</span></td></tr>
</tbody></table>
<div style="text-align: left;">
<span style="font-family: Trebuchet MS, sans-serif;">I didn't have any male-female Dupont cables at hand, so I put a prototype shield inbetween to turn the female headers into male.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<br />
<h3>
<span style="font-family: Trebuchet MS, sans-serif;">Software</span></h3>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">The required software is split in the following parts:</span></div>
<div>
<ul>
<li><span style="font-family: Trebuchet MS, sans-serif;">Sketch running on the Arduino: configures the nRF24 radio and reads any messages received using SPI. It determines the actual payload size for each message and adds a microsecond-resolution timestamp. The messages are buffered in the Atmega328 and sent to the host over a serial connection. It keeps track of the number of lost messages, when the buffer is full.</span></li>
<li><span style="font-family: Trebuchet MS, sans-serif;">Console application 'Nrf24Sniff.exe' (currently only Windows) which sends configuration data to the Arduino sketch and reads captured packets from the sketch, using a serial connection. The packets received are forwarded in <a href="http://wiki.wireshark.org/Development/LibpcapFileFormat" target="_blank">libpcap-format</a> to a named pipe. Wireshark will be instructed to capture from this named pipe (too bad it cannot capture directly from a serial connection).</span></li>
<li><span style="font-family: Trebuchet MS, sans-serif;"><a href="http://www.wireshark.org/" target="_blank">Wireshark</a> to visualize the captured packets, filter them and gather statistics.</span></li>
<li><span style="font-family: Trebuchet MS, sans-serif;">Wireshark will be extended with one or more plugins (called <i>dissectors, </i>currently only precompiled for Windows) which recognize the nRF24 packet format and take it apart. Protocols which use the nRF24 as transport layer (e.g. MySensors) require a separate dissector.</span></li>
</ul>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<h3>
<span style="font-family: Trebuchet MS, sans-serif;">Installation</span></h3>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">As you can see in the description above, the console application and Wireshark dissectors are currently only available for Windows (anyone who volunteers to port them to Linux and/or Mac, please do so and let me know).</span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">In the description below I assume you've already downloaded and installed:</span></div>
<div>
<ul>
<li><span style="font-family: Trebuchet MS, sans-serif;"><a href="http://www.wireshark.org/download.html" target="_blank">Wireshark</a> - I used 1.10.8, either 32- or 64-bits</span></li>
<li><span style="font-family: Trebuchet MS, sans-serif;"><a href="http://arduino.cc/en/Main/Software" target="_blank">Arduino IDE</a> - I used 1.5.6-r2, but I guess any 1.5.x version will do</span></li>
</ul>
</div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">First download and extract the software I developed as a <a href="https://github.com/Yveaux/NRF24_Sniffer/archive/master.zip" target="_blank">single zip-file</a> from my <a href="https://github.com/Yveaux" target="_blank">GitHub repository</a>.</span></div>
<span style="font-family: Trebuchet MS, sans-serif;"><i><br /></i></span>
<span style="font-family: Trebuchet MS, sans-serif;"><i>Arduino sniffer sketch</i></span><br />
<div>
<span style="font-family: Trebuchet MS, sans-serif;">Either move the contents from the 'Arduino' directory to your Arduino users' directory (c:\users\<yourname>\Documents\Arduino) or copy it elsewhere and instruct the Arduino IDE to use that directory by pointing Preferences -> Sketchbook location to it and restart. I'm a bit reluctant when it comes to copying libraries to your regular users' Arduino directory as it might conflict with any libraries already present. Beware that I changed some small thinks in the RF24 library that's included.</span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">Start the Arduino IDE, load the NRF24_sniff sketch, connect the hardware setup as described above, select the correct board & comport and download the compiled sketch.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div>
</div>
<div>
<i><span style="font-family: Trebuchet MS, sans-serif;">Nrf24Sniff.exe</span></i></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">The Windows console application which transfers captured data from a serial interface to a named pipe can be found in the 'SerialToPipe/bin/Win32' directory. Just copy this executable somewhere convenient.</span></div>
<div>
<br /></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><i>Wireshark dissector(s)</i></span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">Choose the directory matching your 32- or 64-bits install from 'Wireshark/bin/Win32' or </span><span style="font-family: 'Trebuchet MS', sans-serif;">'Wireshark/bin/Win64' and copy the nrf24.dll to the Wireshark plugins directory, e.g. '</span><span style="font-family: Trebuchet MS, sans-serif;">c:\Program Files\Wireshark\plugins\1.10.8\</span><span style="font-family: 'Trebuchet MS', sans-serif;">'.</span></div>
<div>
<span style="font-family: 'Trebuchet MS', sans-serif;">Those using the MySensors library can also copy either mysensors1.dll (version 1.3 of the library) or mysensors2.dll (version 1.4beta), depending on the library version you're working with. Better not copy both of them as these are <i><a href="https://code.wireshark.org/review/gitweb?p=wireshark.git;a=blob_plain;f=doc/README.heuristic" target="_blank">heuristic</a></i> dissectors which have problems detecting the protocol version reliably.</span></div>
<div>
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
<h3>
<span style="font-family: Trebuchet MS, sans-serif;">Running</span></h3>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">Connect the hardware running the sniffer sketch to your PC (either using an RS232 connection or a serial-to-USB bridge as present on the Arduino Uno). Note the comport assigned by Windows (the same port as in the Arduino IDE). Assure the Arduino IDE's Serial Monitor is not running as it will block access to the serial port.</span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><b>Nrf24sniff.exe</b> can be started from a cmd-window. It supports a number of commandline parameters which control its behaviour (display them using '</span><span style="font-family: 'Trebuchet MS', sans-serif;">Nrf24Sniff.exe -h')</span><span style="font-family: 'Trebuchet MS', sans-serif;">:</span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTbroS7xB0hNLOClIiFUokNVRBSaC3Xoiogu_02B48IhlMbuvtvC3mt-p_ti-FsWeJlIOALnO1aAozXOHrwLIYqJu_-mxbOIB_LRq1UW4ajkVY3qL6pqBvNOIknqAoUFIs9GU0OfKFAAs/s1600/nrf24sniff-h.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTbroS7xB0hNLOClIiFUokNVRBSaC3Xoiogu_02B48IhlMbuvtvC3mt-p_ti-FsWeJlIOALnO1aAozXOHrwLIYqJu_-mxbOIB_LRq1UW4ajkVY3qL6pqBvNOIknqAoUFIs9GU0OfKFAAs/s1600/nrf24sniff-h.png" /></a></div>
<div>
<br /></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">For example, when monitoring MySensors 1.4beta traffic (at non-default 1Mb/s), using the Arduino Uno sniffer connected to com17, I run the tool as follows:</span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Courier New, Courier, monospace;">Nrf24Sniff.exe -P17 -c76 -r0 -l5 -p4 -a0xA8A8E1FC00 -C2</span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">The address length is set to 5 bytes (-l5), of which 4 bytes are used as base address (-p4) (Please refer to <a href="http://yveaux.blogspot.nl/2014/07/nrf24l01-sniffer-part-1.html" target="_blank">part 1</a> of this series for a description of addressing schemes). Passing only the comport would have been sufficient in this case, as the rest of the parameters are all set to defaults.</span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">Now run it:</span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwMWyKOQSREBFI6-_pbp3j0nw2iF7kTufjtFd2EIHHeu5Lv2AhDWdDtcn5CRu20CDG2ud337xdpJC9TdvT4CTRxIOWXiUYa2eXyAZC5y40Z0G-fG-tStF0ZRpH_g8V01e_Mze-5b8-CJE/s1600/nrf24sniff-connpipe.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwMWyKOQSREBFI6-_pbp3j0nw2iF7kTufjtFd2EIHHeu5Lv2AhDWdDtcn5CRu20CDG2ud337xdpJC9TdvT4CTRxIOWXiUYa2eXyAZC5y40Z0G-fG-tStF0ZRpH_g8V01e_Mze-5b8-CJE/s1600/nrf24sniff-connpipe.png" /></a></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">Keep it running and open another console window to start Wireshark:</span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhcaKUuAxCGgNA9gjhbnRdrFUnBmrfkuFVm8WUwj2yUNXHgg6phFYX5RGUzsaScdriwbIQHbIQm5-bP5k7qnVO6LmC34wLAtFqFoLnfZH03jFOy8DZ4OSWjUP4LdZsf4wOjO8JzFZfvuzg/s1600/nrf24sniff-startws.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhcaKUuAxCGgNA9gjhbnRdrFUnBmrfkuFVm8WUwj2yUNXHgg6phFYX5RGUzsaScdriwbIQHbIQm5-bP5k7qnVO6LmC34wLAtFqFoLnfZH03jFOy8DZ4OSWjUP4LdZsf4wOjO8JzFZfvuzg/s1600/nrf24sniff-startws.png" /></a></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">This instructs Wireshark to start capturing from interface (-i) \\.\pipe\wireshark (that's the named pipe Nrf24Sniff.exe will be writing to) and to start capturing immediately (-k). More commandline options for Wireshark can be found <a href="http://www.wireshark.org/docs/man-pages/wireshark.html" target="_blank">here</a>.</span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">After Wireshark starts capturing, the Nrf24Sniff console window will display a 'Wait for sniffer to restart' message for a few seconds (at most):</span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTzoQbrhfkq5LjS4sALncHb2z3frlm-VPI2uYmINZc51uqqmjd9jHvRjNKFueuFzR_b35iQqRDfNgCNpyXbWWF8AT_bVZsVYvLH61cBCWhH_0kGRF8SbTCmwTH63j8g1hJRU4wbCN-8ec/s1600/nrf24sniff-config.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTzoQbrhfkq5LjS4sALncHb2z3frlm-VPI2uYmINZc51uqqmjd9jHvRjNKFueuFzR_b35iQqRDfNgCNpyXbWWF8AT_bVZsVYvLH61cBCWhH_0kGRF8SbTCmwTH63j8g1hJRU4wbCN-8ec/s1600/nrf24sniff-config.png" /></a></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">If it hangs here, restart the sniffer hardware manually by pressing the reset button on the Arduino (I'm working on that...).</span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">As Wireshark has no clue how to interpret the data coming through our named pipe, we have to tell it which dissector to use.</span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">Switch over to Wireshark and select Edit -> Preferences.</span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">In the preferences window, open the <i>protocols</i> tree, scroll down and select <i>DLT_USER</i>.</span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">Press the edit button for the 'Encapsulations table' and press <i>New. </i>Enter the data as in the screenshot below:</span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj92Z3skPrT7rshmob7du0YiI36jvdlP5o-TPMs6h8aBVIm0y71DUmzPxsN071Ny1QRrlDVJQgzOyqfGGXDzs0UghPiHtxCvX0GSv8Vr6RnZDtAxAMUvyMhtEmrAw1V4RYd9H3YbNcXE_4/s1600/WS-dlt_user.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj92Z3skPrT7rshmob7du0YiI36jvdlP5o-TPMs6h8aBVIm0y71DUmzPxsN071Ny1QRrlDVJQgzOyqfGGXDzs0UghPiHtxCvX0GSv8Vr6RnZDtAxAMUvyMhtEmrAw1V4RYd9H3YbNcXE_4/s1600/WS-dlt_user.png" /></a></div>
</div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">Press OK, OK, OK. Any packets on air that match the radio configuration should now be captured in Wireshark!</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVm5-C-GTJfwD6Mfz-xAkV6PLunD5HPUiyROrMg2bYZBU2anxuCDKr-szA4qaQHOV9lVpJe5LPIC3jskVHmPLKiunKIBJjgUEJI8G02EG9rp9XMnRd1brJeLQwqzc-6TUFnll5hljxibc/s1600/ws.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="450" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVm5-C-GTJfwD6Mfz-xAkV6PLunD5HPUiyROrMg2bYZBU2anxuCDKr-szA4qaQHOV9lVpJe5LPIC3jskVHmPLKiunKIBJjgUEJI8G02EG9rp9XMnRd1brJeLQwqzc-6TUFnll5hljxibc/s640/ws.png" width="640" /></a></div>
</div>
<div class="" style="clear: both; text-align: center;">
<br /></div>
<div>
<span style="font-family: 'Trebuchet MS', sans-serif;">The Nrf24Sniff console shows a count of packets captured and lost:</span></div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEioP4J0x4eg2W0QhCccSfviwmQcEaEMKmRkH7dej6EwWPhp-NXitMl2wmVLdBV4cOdko5aFp3r-Brl5lUnh73oIwIOxzjQ3dopwzQu630gv6JOrboIOh-zqGYkffyqHKJiMYAqsAZNTJR8/s1600/Nrf24-cap.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEioP4J0x4eg2W0QhCccSfviwmQcEaEMKmRkH7dej6EwWPhp-NXitMl2wmVLdBV4cOdko5aFp3r-Brl5lUnh73oIwIOxzjQ3dopwzQu630gv6JOrboIOh-zqGYkffyqHKJiMYAqsAZNTJR8/s1600/Nrf24-cap.png" /></a></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<h3>
<span style="font-family: Trebuchet MS, sans-serif;">What's next</span></h3>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">The next and last part of this series will dive into the possibilities of Wireshark and the dissectors I've implemented for nRF24 packets and the MySensors protocol.</span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span><span style="font-family: Trebuchet MS, sans-serif; font-size: x-small;"><i>Updates</i></span><br />
<span style="font-family: 'Trebuchet MS', sans-serif; font-size: x-small;">Aug 3 - statically linked Nrf24sniff.exe, so dependency on msvcr110.dll no longer exists. Should also work on WinXP now.</span></div>
</div>
</div>
Yveauxhttp://www.blogger.com/profile/16599434883652140617noreply@blogger.com41tag:blogger.com,1999:blog-1578010460921274916.post-43114306481994407412014-07-26T20:19:00.001+02:002015-05-23T11:04:07.151+02:00nRF24L01+ sniffer - part 1<span style="font-family: Trebuchet MS, sans-serif;">When working with wireless networks, or any network in general, it can be very helpfull to inspect the raw message data. Networking chips only accept messages directly addressed to them (or when broadcasteded), but most also support a so-called <i>promiscuous mode</i>. This mode allows the networking chip to capture all network traffic on air/on the wire and is used to monitor all network traffic, not just the traffic addressed to our node.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;">As a picture is worth a thousand words, a moving picture is probably worth a million words!</span><br />
<br />
<div style="text-align: center;">
<iframe allowfullscreen="" frameborder="0" height="270" src="//www.youtube.com/embed/wxjxm0LnkAk" width="480"></iframe></div>
<h3>
<span style="font-family: Trebuchet MS, sans-serif;">nRF24 sniffing</span></h3>
<span style="font-family: Trebuchet MS, sans-serif;">The wireless 2.4GHz </span><span style="font-family: Trebuchet MS, sans-serif;"><a href="http://yveaux.blogspot.nl/2014/07/mysensors.html#nRF24">Nordic Semiconductor nRF24L01+</a> </span><span style="font-family: 'Trebuchet MS', sans-serif;">chip </span><span style="font-family: Trebuchet MS, sans-serif;">(or nRF24 for short)</span><span style="font-family: 'Trebuchet MS', sans-serif;">, which I'm experimenting with for <a href="http://yveaux.blogspot.nl/2014/07/mysensors.html">wireless domotica applications</a>, does however </span><i style="font-family: 'Trebuchet MS', sans-serif;">not </i><span style="font-family: 'Trebuchet MS', sans-serif;">support promiscuous mode, which in theory makes it impossible to capture network traffic between different nodes on a network.</span><br />
<span style="font-family: 'Trebuchet MS', sans-serif;">Some time ago I stumbled upon a blogpost by </span><a href="http://travisgoodspeed.blogspot.nl/2011/02/promiscuity-is-nrf24l01s-duty.html" style="font-family: 'Trebuchet MS', sans-serif;" target="_blank">Travis Goodspeed</a><span style="font-family: 'Trebuchet MS', sans-serif;">, in which he explains how reducing the wireless network address length of an nRF24 (together with some other tricks) allows capturing traffic not directly addressed to this chip.</span><br />
<span style="font-family: 'Trebuchet MS', sans-serif;">After reading his blog and some more google'ing around I started thinking of building a 'simple' network sniffer for nRF24 traffic. I faced following requirements & challenges:</span><br />
<ul>
<li><span style="font-family: Trebuchet MS, sans-serif;">Based on commodity, cheap hardware</span></li>
<li><span style="font-family: Trebuchet MS, sans-serif;">Traffic capturing for network with known parameters (channel, baudrate, base address)</span></li>
<li><span style="font-family: Trebuchet MS, sans-serif;">Analysis using <a href="http://www.wireshark.org/" target="_blank">Wireshark</a> network protocol analyzer</span></li>
<li><span style="font-family: Trebuchet MS, sans-serif;">Possibility to analyze protocols which use the nRF24 for transport in their network</span></li>
</ul>
<div>
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
<h3>
<span style="font-family: 'Trebuchet MS', sans-serif;">Packet formats</span></h3>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">A regular packet is sent on air by the nRF24 in the following format (supposedly; it's not in the datasheet):</span><br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAr6mfiFrE2Tx1uFaI-v4T9XmDswo_vQZsW7w_37g8cbMtr79reY8_HbHcPScV9hs8v7VSkWQogf5rCPaCxERncrbWQEh33AmdnaG2VdwRPmoWLKJiXvU71sWP_NX_Fb_MSc4d4atrk0w/s1600/nRF24packet_Regular.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAr6mfiFrE2Tx1uFaI-v4T9XmDswo_vQZsW7w_37g8cbMtr79reY8_HbHcPScV9hs8v7VSkWQogf5rCPaCxERncrbWQEh33AmdnaG2VdwRPmoWLKJiXvU71sWP_NX_Fb_MSc4d4atrk0w/s1600/nRF24packet_Regular.png" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 12.8000001907349px;">Regular nRF24 packet</span></td></tr>
</tbody></table>
<span style="font-family: Trebuchet MS, sans-serif;">Every message starts with a preamble, which the radio uses to identify incoming packets. The target node address follows and can be specified as 3 to 5 bytes (according to Travis Goodspeed a length of 2 is also accepted by the radio, though defined as invalid in the datasheet). Then comes the fixed-size payload, followed by an optional CRC to check the integrity of the message after reception. </span><span style="font-family: 'Trebuchet MS', sans-serif;">The CRC is calculated over the whole message, excluding the preamble and the CRC itself. </span><span style="font-family: 'Trebuchet MS', sans-serif;">The radio must be told upfront what the length of the payload will be, as a regular packet contains no indication of the length.</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: Trebuchet MS, sans-serif;">When a message received matches the receiver address of the radio and the CRC is found valid or disabled, the radio will store the <i>payload </i>in an internal FIFO for reception by the host (microcontroller or whatever connected to the nRF24 using SPI).</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: Trebuchet MS, sans-serif;">The nRF24L01+ modules support a mode called 'Enhanced Shockburst' which has a number of advantages over regular usage (incomplete):</span></div>
<div class="separator" style="clear: both; text-align: left;">
</div>
<ul>
<li><span style="font-family: Trebuchet MS, sans-serif;">Payload lengths can be set dynamically and are part of the message</span></li>
<li><span style="font-family: Trebuchet MS, sans-serif;">The receiving node can automatically send an acknowledge to the sender to indicate that the message has been received correctly. The sender will automatically retry transmission a number of times when the acknowledge is not received within a configurable timeout (Nordic calls this "Automatic packet transaction handling")</span></li>
</ul>
<span style="font-family: 'Trebuchet MS', sans-serif;">Enhanced shockburst messages are sent over the air in the following format (from the datasheet):</span><br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiaG5laD_Jq8GDsx4pi8YqnJm4xATh7ZPJrDKDUG9gLj-J8ejTzfI-xtiKXIlUr119c4a45q4fRjx8GL5NL6N0-nvWqwnt0Sm37a6fk9E4Gbu6mk4UEJPH5wr5QavxZvlERas9rJml6XdQ/s1600/nRF24packet_EnhShockBurst.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiaG5laD_Jq8GDsx4pi8YqnJm4xATh7ZPJrDKDUG9gLj-J8ejTzfI-xtiKXIlUr119c4a45q4fRjx8GL5NL6N0-nvWqwnt0Sm37a6fk9E4Gbu6mk4UEJPH5wr5QavxZvlERas9rJml6XdQ/s1600/nRF24packet_EnhShockBurst.png" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: Trebuchet MS, sans-serif;">Enhanced Shockburst nRF24 packet</span></td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: Trebuchet MS, sans-serif;">As you can see a 9 bit packet control field has been added which stores the payload length (in bytes), a packet identifier (PID) to detect retransmissions and a flag to suppress sending acknowledge packets on a per-packet basis. The CRC is no longer optional.</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: 'Trebuchet MS', sans-serif;">As with the regular packets, a message received must match the receiver address of the radio and the CRC must be valid to have the </span><i style="font-family: 'Trebuchet MS', sans-serif;">payload </i><span style="font-family: 'Trebuchet MS', sans-serif;">stored </span><span style="font-family: 'Trebuchet MS', sans-serif;">in the internal FIFO, otherwise the message will be discarded.</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: Trebuchet MS, sans-serif;">Many (all?) wireless sensor applications based on the nRF24L01+ I've seen so far run the radio in Enhanced Shockburst mode.</span></div>
<div class="separator" style="clear: both; text-align: left;">
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div>
<h3>
<span style="font-family: Trebuchet MS, sans-serif;">Promiscuous reception</span></h3>
</div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">When building a wireless network of many nodes you choose a single RF channel which all nodes will operate on. Furthermore each node shall have a unique address within the network (unless you're only broadcasting). Each node <i>can </i>have an arbitrary address, but normally you choose a <i>base address</i> which is identical for all nodes, and a <i>node address </i>which is unique for each node<i>. </i>Combined these form <i>the</i> address:</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicDcgV-8h68MWv9IjPpYSy1vY7lrTn1AhJu8lOYRTacB6quw-6leefFXsHX3_rF0uL-G7kjYIUj9h1qhbIASPV6MNhPj1-93XmeW-GIi5EB-yTJcsKpc7hhAkx0mRRDhZC5XHZbCLn_gM/s1600/nRF24packet_Address.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicDcgV-8h68MWv9IjPpYSy1vY7lrTn1AhJu8lOYRTacB6quw-6leefFXsHX3_rF0uL-G7kjYIUj9h1qhbIASPV6MNhPj1-93XmeW-GIi5EB-yTJcsKpc7hhAkx0mRRDhZC5XHZbCLn_gM/s1600/nRF24packet_Address.png" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: 'Trebuchet MS', sans-serif; font-size: 12.8000001907349px;">Address consisting of 4 byte base address and single byte node address</span></td></tr>
</tbody></table>
<span style="font-family: 'Trebuchet MS', sans-serif;">This example addressing scheme (4+1) is used by the </span><a href="http://www.mysensors.org/" style="font-family: 'Trebuchet MS', sans-serif;" target="_blank">MySensors </a><span style="font-family: 'Trebuchet MS', sans-serif;">library and allows 255 unique nodes to be addressed (node 255 is used for broadcast addressing).</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><i><br /></i></span>
<span style="font-family: Trebuchet MS, sans-serif;"><i>Should </i>the nRF24 support promiscuous addressing, then the base address would have to be configured in the chip and it should be instructed that the node addressing consists of 1 byte. The nRF24 would then start listening for messages. All messages with matching base address and valid CRC would then be stored...</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">But the nRF24 does not support promiscuous listening. With some trickery we can however instruct it to capture all messages for a certain base address, <i>including the ones with invalid CRC's</i> !</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif;">The following configuration of the nRF24 sniffing radio is required:</span><br />
<br />
<ul>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">Set the nRF24 receiver address to just the base address</span></li>
<li><span style="font-family: Trebuchet MS, sans-serif;">Disable Enhanced Shockburst</span></li>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">Disable CRC checking</span></li>
<li><span style="font-family: Trebuchet MS, sans-serif;">Configure a fixed payload size</span></li>
</ul>
</div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">The first 3 items will cause the nRF24 to capture <i>anything </i>that matches the base address of the network we're sniffing. As Enhanced Shockburst is disabled, the radio will not determine the payload size from the message anymore and we just have to store a fixed amount of data starting from the Node address. We just fake the message received is a regular packet, while in fact it is an Enhanced Shockburst packet!</span><br />
<span style="font-family: 'Trebuchet MS', sans-serif;">CRC checking has to be disabled of course, as the nRF24 doesn't know the payload length anymore and CRC calculation would fail, rejecting all messages.</span><br />
<span style="font-family: 'Trebuchet MS', sans-serif;">The process is illustrated by the image below (again, taking the 4+1 addressing scheme as an example):</span><br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi7gt63W4jzKHlHhwQLbPHPk-SQ-69sad8pSW3eIQi71koh7n0TkGqX_R6NzjMAle7Swodcs4wp9SxamnuQ3X3XA8451yWkmCC4zfI2jjv8uc8F54pkGsrAtAYoi1gRzkuhv4bvkEskZUw/s1600/nRF24packet_SniffES_as_regular+%25281%2529.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi7gt63W4jzKHlHhwQLbPHPk-SQ-69sad8pSW3eIQi71koh7n0TkGqX_R6NzjMAle7Swodcs4wp9SxamnuQ3X3XA8451yWkmCC4zfI2jjv8uc8F54pkGsrAtAYoi1gRzkuhv4bvkEskZUw/s1600/nRF24packet_SniffES_as_regular+%25281%2529.png" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: Trebuchet MS, sans-serif;">Capture Enhanced Shockburst packet as regular packet</span></td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: center;">
</div>
<span style="font-family: 'Trebuchet MS', sans-serif;">The payload received will start with the node address the packet was transmitted to, so effectively we've created a promiscuous listening nRF24!</span><br />
<span style="font-family: 'Trebuchet MS', sans-serif;">As the nRF24 will no longer dissect the packet for us, we'll have to do it ourselves (actually let Wireshark do it for us). The original length of the payload should be </span><span style="font-family: 'Trebuchet MS', sans-serif;">extracted </span><span style="font-family: 'Trebuchet MS', sans-serif;">(the 6 bit payload length), the full address </span><span style="font-family: 'Trebuchet MS', sans-serif;">recreated </span><span style="font-family: 'Trebuchet MS', sans-serif;">and CRC calculated over the data received. When the CRC is invalid the message can be marked, which gives us a nice indication of the link quality. As the nRF24 header is not a multiple of 8 bits, all payload & CRC bytes will be bit-shifted directly adjacent to the packet control field. This is inconvenient when inspecting the raw bytes in a packet, but Wireshark will solve this nicely for us.</span><br />
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span>
<br />
<h3>
<span style="font-family: 'Trebuchet MS', sans-serif;">Limitations</span></h3>
<span style="font-family: 'Trebuchet MS', sans-serif;">There are however some limitations to this method which you should be aware of:</span><br />
<br />
<ul>
<li><span style="font-family: Trebuchet MS, sans-serif;">The maximum length of a payload is limited by the nRF24 to 32 bytes. As we 'shift' the reception of the payload towards the start of the packet and also want to include the CRC in the payload, the effective size of payloads captured will go down by a number of bytes. The amount depends on the number of bytes in the node address, the fixed packet control field and the length of the CRC.</span></li>
<li><span style="font-family: Trebuchet MS, sans-serif;">When fixed payload size of the sniffer is set to a value (much) larger than the actual payload size in the packet, then subsequent packets might be missed. When the nRF24 is still capturing the fixed size payload and a new packet arrives, this will not be detected. A good example for this are the auto-acknowledge packets which can be enabled in Enhanced Shockburst mode. After the target node receives the packet (and it will know the real size of the payload a lot faster than the sniffer will) it switches its radio from receiving to transmitting mode in only 130us. Then it sends out the acknowledge packet. Reception of 32 bytes at 1Mb/s takes 32*8us = 256us, so acknowledge of a short message will definately be missed. For acknowledge packets this isn't much of a problem as the transmitter will retry to send the identical message when no acknowledge was received and we will know it missed the acknowldge.</span></li>
<li><span style="font-family: Trebuchet MS, sans-serif;">This method works well for Enhanced Shockburst packages, as they have the payload size embedded in the message. For regular messages the length will have to be known or can be determined by testing different lengths until the CRC matches. With CRC disabled the payload size can only be guessed.</span></li>
<li><span style="font-family: Trebuchet MS, sans-serif;">The addressing scheme must use a base address in the high address byte(s), and node address in the low byte(s), as explained.</span></li>
</ul>
<div>
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span></div>
<h3>
<span style="font-family: 'Trebuchet MS', sans-serif;">What's next</span></h3>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">In the next parts of this series I will dive deeper in the hardware and software required to create the sniffer and give some nice usage examples. Furthermore a Wireshark dissector for the MySensors protocol will be presented.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: Trebuchet MS, sans-serif; font-size: x-small;"><i>Updates</i></span><br />
<span style="font-family: 'Trebuchet MS', sans-serif; font-size: x-small;">July 27 - added youtube video</span><br />
<span style="font-family: 'Trebuchet MS', sans-serif; font-size: x-small;">August 20 - updated Wireshark dissector for MySensors 1.4b to state of Aug. 18, 2014.</span></div>
</div>
Yveauxhttp://www.blogger.com/profile/16599434883652140617noreply@blogger.com20tag:blogger.com,1999:blog-1578010460921274916.post-40112335872064234702014-07-20T10:51:00.000+02:002014-07-21T19:31:10.454+02:00Changing Arduino bootloader to Optiboot<span style="font-family: Trebuchet MS, sans-serif;">All Arduino boards come with a pre-programmed boot loader. This boot loader allows you to program the Arduino from the IDE using a serial connection only. After programming the serial connection can be used as a console interface to 'talk' to the Arduino. Other ways exist to program an Arduino, but all of them require extra hardware.</span><br />
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span>
<span style="font-family: 'Trebuchet MS', sans-serif;">First a </span><b style="font-family: 'Trebuchet MS', sans-serif;">big fat warning</b><span style="font-family: 'Trebuchet MS', sans-serif;">: Be sure you are familiar with compiling source code from the command line and programming your Arduino using ISP. Failure to update the boot loader might </span><b style="font-family: 'Trebuchet MS', sans-serif;">brick</b><span style="font-family: 'Trebuchet MS', sans-serif;"> your Arduino for usage by the Arduino IDE !!!</span><br />
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span>
<br />
<h3>
<span style="font-family: Trebuchet MS, sans-serif;">Advantages of the Optiboot boot loader</span></h3>
<ul>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">Size is only 512 bytes. This leaves more room (flash) for own programs.</span></li>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">Works with watchdog enabled.</span></li>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">Serial connection speed can be increased (default 57k6). This shortens programming times!</span></li>
</ul>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<ul>
</ul>
<h3>
<span style="font-family: Trebuchet MS, sans-serif;">What you'll need</span></h3>
<div>
<ul>
<li><span style="font-family: Trebuchet MS, sans-serif;">An Arduino Pro Mini 3v3 @ 8MHz. </span><span style="font-family: 'Trebuchet MS', sans-serif;">This description is for an Arduino Pro Mini (3V3, 8Mhz), but the principle is the same for other ATmega328 based Arduino's)</span></li>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">An ISP programmer connected to the ATMega (I use Atmel's </span><a href="http://www.atmel.com/tools/jtagice3.aspx" style="font-family: 'Trebuchet MS', sans-serif;">JTAGICE3</a><span style="font-family: 'Trebuchet MS', sans-serif;">) & software to flash (for JTAGICE3 I use Atmel Studio 6.1)</span></li>
<li><span style="font-family: Trebuchet MS, sans-serif;">Arduino IDE (I used 1.5.6r2)</span></li>
</ul>
<span style="font-family: Trebuchet MS, sans-serif;">The description here assumes Windows.</span></div>
<h3>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></h3>
<h3>
<span style="font-family: Trebuchet MS, sans-serif;">Compiling Optiboot</span></h3>
<ul>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">Download Optiboot 5.0a sources: <a href="https://code.google.com/p/optiboot/downloads/detail?name=optiboot-v5.0a.zip">https://code.google.com/p/optiboot/downloads/detail?name=optiboot-v5.0a.zip</a></span></li>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">Extract to c:\Arduino_1.5.6-r2\hardware\arduino\avr\ (rename existing optiboot directory, when required)</span></li>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">Optional: Edit bootloaders\optiboot\Makefile to change the baud rate (line 562) (This is a makefile, so be sure to use tabs to indent instead of spaces!) I went from 57k6 to 76k8, because I got errors at 115k2:</span></li>
</ul>
<blockquote class="tr_bq">
<span style="font-family: Courier New, Courier, monospace;">atmega328_pro8: $(MAKE) $(CHIP) AVR_FREQ=8000000L LED_START_FLASHES=3 BAUD_RATE=76800</span></blockquote>
<ul>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">Start a cmd shell in c:\Arduino_1.5.6-r2\hardware\arduino\avr\bootloaders\optiboot</span></li>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">make clean</span></li>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">make atmega328_pro8</span></li>
</ul>
<h3>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></h3>
<h3>
<span style="font-family: Trebuchet MS, sans-serif;">Flashing Optiboot to the Arduino</span></h3>
<ul>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">Optional: Use your ISP tool to create a backup of the existing bootloader and fuses.</span></li>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">Flash optiboot_atmega328_pro_8MHz.hex using your favourite ISP</span></li>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">Set fuses to: Low = 0xFF, High = 0xDE, Extended = 0xFE</span></li>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">Close any active Arduino windows</span></li>
</ul>
<h3>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></h3>
<h3>
<span style="font-family: Trebuchet MS, sans-serif;">Add support for the new bootloader to Arduino IDE</span></h3>
<ul>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">Edit c:\Arduino_1.5.6-r2\hardware\arduino\avr\boards.txt</span></li>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">Add (based on Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ ATmega328):</span></li>
</ul>
<blockquote class="tr_bq">
<span style="font-family: Courier New, Courier, monospace;">## Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ ATmega328 - Optiboot 76k8<br />## --------------------------------------------------<br />pro.menu.cpu.8MHzatmega328ob=ATmega328 (3.3V, 8 MHz, Optiboot 76k8)<br />pro.menu.cpu.8MHzatmega328ob.upload.maximum_size=32256<br />pro.menu.cpu.8MHzatmega328ob.upload.maximum_data_size=2048<br />pro.menu.cpu.8MHzatmega328ob.upload.speed=76800<br />pro.menu.cpu.8MHzatmega328ob.bootloader.low_fuses=0xFF<br />pro.menu.cpu.8MHzatmega328ob.bootloader.high_fuses=0xDE<br />pro.menu.cpu.8MHzatmega328ob.bootloader.extended_fuses=0xFE<br />pro.menu.cpu.8MHzatmega328ob.bootloader.file=atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex<br />pro.menu.cpu.8MHzatmega328ob.build.mcu=atmega328p<br />pro.menu.cpu.8MHzatmega328ob.build.f_cpu=8000000L</span></blockquote>
<div>
<h3>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></h3>
<h3>
<span style="font-family: Trebuchet MS, sans-serif;">Testing it!</span></h3>
<ul>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">Start Arduino IDE</span></li>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">Select Board -> Arduino Pro or Pro Mini</span></li>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">Select Processor -> ATmega328 (3.3V, 8 MHz, Optiboot 76k8)</span></li>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">File -> Upload</span></li>
</ul>
</div>
Yveauxhttp://www.blogger.com/profile/16599434883652140617noreply@blogger.com3tag:blogger.com,1999:blog-1578010460921274916.post-10585902340497484422014-07-19T15:04:00.002+02:002014-07-26T08:11:27.204+02:00MySensors<span style="font-family: 'Trebuchet MS', sans-serif;">It's been a while since I started expermenting with wireless networks.</span><br />
<span style="font-family: 'Trebuchet MS', sans-serif;">It all started with an attempt to convert the regular doorbell into a connected doorbell which could trigger a sound throughout the whole house. It would be nice if this could be any sound, so why not make it play mp3's? And if it's connected, it can also measure the room temperature & humidity and....</span><br />
<span style="font-family: Trebuchet MS, sans-serif;">So I started experimenting with Zigbee modules (XBee, Zigbit) and point-to-point modules (CYRF6936, MRF24J40). The Zigbee modules I found too complex and expensive and the point-to-point modules lacked software support. </span><span style="font-family: 'Trebuchet MS', sans-serif;">I really wanted some form of mesh-networking that could communicate with home automation software and would cost me less than 10 Euro's per node.</span><br />
<h2 id="nRF24">
<span style="font-family: 'Trebuchet MS', sans-serif;">Enter the nRF24</span></h2>
<span style="font-family: Trebuchet MS, sans-serif;">In search for cheap wireless networking modules I came across the <a href="http://www.nordicsemi.com/eng/Products/2.4GHz-RF/nRF24L01P">Nordic Semiconductor's nRF24L01+</a>. This single chip transceiver operates in the 2.4GHz range at bitrates upto 2MBps, communicates to a host using SPI and has very low power consumption.</span><br />
<span style="font-family: 'Trebuchet MS', sans-serif;">Complete modules based on these chips sell for around $1 on eBay!</span><br />
<span style="font-family: 'Trebuchet MS', sans-serif;">A few weeks later some modules arrived from China. Meanwhile I did some investigation on networking stacks based on the nRF24, but I could only find an Arduino driver.</span><br />
<h2>
<span style="font-family: 'Trebuchet MS', sans-serif;">Networking stack</span></h2>
<span style="font-family: 'Trebuchet MS', sans-serif;">I decided to implement a mesh-networking stack, but progress went slowly mainly due to lack of spare time and defects in one of the first modules I received.</span><br />
<span style="font-family: 'Trebuchet MS', sans-serif;">After some time, while researching the net for nRF24 info, I stumbled upon the <a href="http://www.mysensors.org/">MySensors </a>mesh networking stack. This library provides simple mesh networking for nRF24 based sensors, and uses the <a href="http://www.arduino.cc/">Arduino</a> platform to run the stack and the specific sensor code. This was exactly what I was looking for!</span><br />
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhfM0BvMQCrOyLL15Hmru1MOsB5vI6vQ4H_wXWaSvH4e7HNo6PLgEA5WOApzDbD_PoHX8S-nU5KcCgwR6kQmKhFE3kzBo81lct8rnn6hrFnbUA3ux3IU9PJvi9U2y7XsRe27E-_XyjlFdQ/s1600/2014-07-19+16.16.17.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img alt="" border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhfM0BvMQCrOyLL15Hmru1MOsB5vI6vQ4H_wXWaSvH4e7HNo6PLgEA5WOApzDbD_PoHX8S-nU5KcCgwR6kQmKhFE3kzBo81lct8rnn6hrFnbUA3ux3IU9PJvi9U2y7XsRe27E-_XyjlFdQ/s1600/2014-07-19+16.16.17.jpg" height="240" title="Experimental MySensors setup" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Experimental MySensors setup, using Arduino Pro Mini (3V3), nRF24 and some sensors.<br />
All powered from just 2 AA batteries.</td></tr>
</tbody></table>
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span>
<br />
<h2>
<span style="font-family: 'Trebuchet MS', sans-serif;">MySensors</span></h2>
<div>
<span style="font-family: 'Trebuchet MS', sans-serif;">I still haven't rolled out sensor nodes based on the MySensors library, though. This is mainly because I'm still experimenting with reliability of connections and range of sensors. For some type of sensors (e.g. the doorbell) I want to be absolutely sure that the data gets delivered, for others (e.g. temperature measurement) an occasional delivery-miss isn't a big problem.</span></div>
<div>
<span style="font-family: 'Trebuchet MS', sans-serif;">MySensors 1.3 is marked stable and a beta release for 1.4 is currently under test. The beta uses an improved nRF24 driver and has automatic acknowledgement and retransmission turned on, which improves connection reliability.</span></div>
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span>
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span>
Yveauxhttp://www.blogger.com/profile/16599434883652140617noreply@blogger.com1