<?xml version="1.0"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title></title>
    <link>http://watr.li</link>
    <atom:link href="http://watr.li/feed.xml" rel="self" type="application/rss+xml" />
    <description></description>
    <language>en-us</language>
    <pubDate>Sun, 14 Oct 2018 19:21:13 +0000</pubDate>
    <lastBuildDate>Sun, 14 Oct 2018 19:21:13 +0000</lastBuildDate>

    
    
    <item>
      <title>It's a wrap!</title>
      <link>http://watr.li/wrapup.html</link>
      <pubDate>Mon, 23 Mar 2015 18:30:00 +0000</pubDate>
      <author></author>
      <guid>http://watr.li/wrapup</guid>
      <description>&lt;p&gt;In the last couple of weeks, we have been working hard on watr.li. Today marks the deadline for the &lt;a href=&quot;http://iot.eclipse.org/open-iot-challenge/&quot;&gt;Eclipse Open IoT Challenge 2015&lt;/a&gt;, so we’d like to take the opportunity to summarize our work and experience so far.&lt;/p&gt;

&lt;p&gt;In this wrap-up post, we do not only want to present the fruits of our labour, but also go into what we’ve learned, which mistakes we made, and which future steps we’d like to take with watr.li.&lt;/p&gt;

&lt;!-- more --&gt;

&lt;h1 id=&quot;presenting-watrli&quot;&gt;Presenting watr.li&lt;/h1&gt;

&lt;p&gt;We’ve created a short video on the problem we’re trying to solve, presenting the solution we’ve implemented both from the user- and the technical perspective. We hope you will enjoy it!&lt;/p&gt;

&lt;iframe style=&quot;margin-left: -66px;&quot; src=&quot;https://player.vimeo.com/video/122985560&quot; width=&quot;665&quot; height=&quot;372&quot; frameborder=&quot;0&quot; webkitallowfullscreen=&quot;&quot; mozallowfullscreen=&quot;&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;

&lt;h1 id=&quot;technologies-used&quot;&gt;Technologies used&lt;/h1&gt;

&lt;p&gt;For watr.li we’ve relied on homogenous hardware, Open Source technology as well as Open Standards, the most important of which we summarize in this section.&lt;/p&gt;

&lt;h2 id=&quot;open-source-software-and-open-standards&quot;&gt;Open source software and open standards&lt;/h2&gt;

&lt;dl&gt;
  &lt;dt&gt;CoAP&lt;/dt&gt;
  &lt;dd&gt;To encode our data and its context, we used&lt;br /&gt;
&lt;a href=&quot;http://watr.li/what-is-coap.html&quot;&gt;CoAP&lt;/a&gt;. On the display nodes, we have integrated &lt;a href=&quot;https://eclipse.org/californium/&quot;&gt;Eclipse Californium&lt;/a&gt; into our web server to be able to parse, handle and send CoAP requests. Our plant nodes run the RIOT port of &lt;a href=&quot;http://libcoap.sourceforge.net&quot;&gt;microcoap&lt;/a&gt;. During both CoAP development processes, we relied on the &lt;a href=&quot;https://addons.mozilla.org/en-us/firefox/addon/copper-270430/&quot;&gt;Eclipse Copper plugin&lt;/a&gt; for reference and testing.

    &lt;p&gt;If you’d like to learn more about CoAP, check out our &lt;a href=&quot;http://watr.li/what-is-coap.html&quot;&gt;non RFC-writers guide to CoAP&lt;/a&gt;. For details on our implementations, see the posts on &lt;a href=&quot;http://watr.li/play2-californium.html&quot;&gt;connecting Californium to the Play framework&lt;/a&gt; and &lt;a href=&quot;http://watr.li/microcoap-and-ff-copper.html&quot;&gt;building a small microcoap server for RIOT&lt;/a&gt;.&lt;/p&gt;
  &lt;/dd&gt;
  &lt;dt&gt;RPL&lt;/dt&gt;
  &lt;dd&gt;To connect all nodes of the Internet of plants, we &lt;br /&gt;
chose to use &lt;a href=&quot;https://tools.ietf.org/html/rfc6550&quot;&gt;RPL&lt;/a&gt; as our routing protocol. RPL was made for environments in which all traffic is directed towards one central, strong node. Our display node fulfills this role, so RPL was a great fit for watr.li’s current configuration.&lt;/dd&gt;
  &lt;dt&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/IEEE_802.15.4&quot;&gt;IEEE 802.15.4&lt;/a&gt;&lt;/dt&gt;
  &lt;dd&gt;forms the MAC and PHY layer of our plant nodes. This &lt;br /&gt;
standard was designed specifically for embedded devices: Its hardware is cheap to produce, energy efficient and features &lt;em&gt;very&lt;/em&gt; small packets– with a frame size of 128 bytes, only 81 bytes of payload are left to the upper layers. For comparison: the size of a minimal IPv6 header alone is 40 bytes.&lt;/dd&gt;
  &lt;dt&gt;6LoWPAN&lt;/dt&gt;
  &lt;dd&gt;To adapt our IPv6 packets to the the restrictions of&lt;br /&gt;
our IEEE802.15.4 transceiver, we used a &lt;a href=&quot;http://en.wikipedia.org/wiki/6LoWPAN&quot;&gt;6LoWPAN&lt;/a&gt; adaption layer.&lt;/dd&gt;
  &lt;dt&gt;RIOT&lt;/dt&gt;
  &lt;dd&gt;All plant nodes run &lt;a href=&quot;http://riot-os.org/&quot;&gt;RIOT&lt;/a&gt;, an&lt;br /&gt;
embedded Operating System designed for the Internet of Things. RIOT comes with POSIX compliance, full C language support, IEEE 802.15.4. support, a network stack that features RPL and 6LoWPAN and ports of two different CoAP implementations: microcoap and libcoap.&lt;/dd&gt;
&lt;/dl&gt;

&lt;h2 id=&quot;hardware&quot;&gt;Hardware&lt;/h2&gt;

&lt;dl&gt;
  &lt;dt&gt;Plant node&lt;/dt&gt;
  &lt;dd&gt;The plant nodes consist of an&lt;br /&gt;
&lt;a href=&quot;http://www.atmel.com/tools/ATSAMR21-XPRO.aspx&quot;&gt;Atmel SAM R21&lt;/a&gt; connected to a &lt;a href=&quot;http://www.dfrobot.com/index.php?route=product/product&amp;amp;product_id=599&quot;&gt;DFROBOT SEN0114 humidity sensor&lt;/a&gt;, with an optional USB/UART converter for debugging.&lt;/dd&gt;
  &lt;dt&gt;Display Node&lt;/dt&gt;
  &lt;dd&gt;Our display node is a&lt;br /&gt;
&lt;a href=&quot;http://www.raspberrypi.org&quot;&gt;Raspberry Pi&lt;/a&gt; equipped with a &lt;a href=&quot;http://rosand-tech.com/products/r-idge/prod.html&quot;&gt;R-IDGE 6LoWPAN USB Border Router&lt;/a&gt; which lets us receive IEEE 802.15.4 packets and transform their 6LoWPAN packets into regular IPv6 packets.&lt;/dd&gt;
&lt;/dl&gt;

&lt;h1 id=&quot;what-weve-learned&quot;&gt;What we’ve learned&lt;/h1&gt;

&lt;p&gt;Building watr.li has been a great learning experience. We’ve fell on our noses a couple of times, but emerged with a stronger knowledge about the technologies we’ve used. In the following, we will summarize the experiences we made as well as good and bad decisions (in hindsight).&lt;/p&gt;

&lt;h2 id=&quot;the-plant-node-side-of-life&quot;&gt;The plant node side of life&lt;/h2&gt;

&lt;!-- Where we fucked up, what we could've done better, what we underestimated... --&gt;
&lt;p&gt;Picking a CoAP implementation turned out to be a bit trickier than we thought: It seems that the general assumption is that IoT devices are so constrained that they cannot issue requests on their own, but must be asked for their data by other, stronger nodes. This is why the creation of a CoAP server is often more trivial than the creation of a client. &lt;code class=&quot;highlighter-rouge&quot;&gt;libcoap&lt;/code&gt;, RIOTs original CoAP implementation, does appear to support clients, but its only documentation are &amp;gt;1000 mostly uncommented lines of code. So &lt;a href=&quot;https://github.com/authmillenon&quot;&gt;Martine Lenders&lt;/a&gt; kindly added a port of microcoap to RIOT. Microcoap is more minimalistic and easier to use, but it lacks the ability to create and send requests without having previously received a request from another CoAP client. We needed this functionality to register our plant nodes at the display node, though, so why we built our &lt;a href=&quot;https://github.com/watr-li/nodes/blob/master/plant_node/coap_ext.c&quot;&gt;own microcoap extension&lt;/a&gt; to do this.&lt;/p&gt;

&lt;p&gt;Additionally, RIOT is currently going through some &lt;a href=&quot;https://github.com/RIOT-OS/RIOT/issues/2278&quot;&gt;major network stack refactoring&lt;/a&gt;, and we’ve come to learn why. Unfortunately, the current IPv6 Neighbor Discovery doesn’t always work as expected, which can lead to inconsistencies in the communication between plant node and display node, because Linux refuses to believe the plant nodes are its neighbors if it doesn’t have confirmation from the Neighbor Cache. The refactoring seems to be progressing rapidly, though, and we’re looking forward to updating our application!&lt;/p&gt;

&lt;h2 id=&quot;on-the-dashboard-side&quot;&gt;On the dashboard side&lt;/h2&gt;

&lt;p&gt;Choosing Eclipse Californium as the CoAP client/server turned out to be a good decision. While the developer-oriented documentation is not as extensive as one would wish, the example applications are numerous and the overall code architecture seems well-thought-out.&lt;/p&gt;

&lt;p&gt;Choosing the Play framework on the other hand turned out to be more trouble than it was worth. While the WebSocket integration is good and almost effortless, many simple tasks that have to be performed in a web application were comparatively time intensive. Some examples:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Integrating database access through &lt;a href=&quot;http://slick.typesafe.com/&quot;&gt;Slick&lt;/a&gt;, which is recommended by the Typesafe stack, was difficult due to missing/badly written documentation.&lt;/li&gt;
  &lt;li&gt;Generating URLs from a template does not seem to be trivially possible, thus we had to hard-code all of them.&lt;/li&gt;
  &lt;li&gt;File upload and general form submission are two separate operations, making image upload in a form complicated.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For future work on watr.li we will definitely evaluate other ways to implement the web frontend. Last but not least, no standard RPL implementation for Linux currently exists, which is why we used the implementation from &lt;a href=&quot;http://rosand-tech.com/&quot;&gt;Rosand Tech&lt;/a&gt;, who also manufacture the R-Idge 6LoWPAN router we used. Since the implementation was a little dated, we had to adjust it to the current version of the Linux kernel.&lt;/p&gt;

&lt;h1 id=&quot;future-work&quot;&gt;Future work&lt;/h1&gt;

&lt;p&gt;Now that we’ve figured out how to put together the building blocks of the Internet of Plants, we have a great platform to further experiment with. We’ve come up with ideas for future extensions and improvements for watr.li, and we’d like to share them with you.&lt;/p&gt;

&lt;h2 id=&quot;battery-life-experience&quot;&gt;Battery life experience&lt;/h2&gt;

&lt;p&gt;During the development process, our plant nodes have been powered by cable or spare battery packs made for smartphones we had lying around. Our next step will be to connect them to li-ion batteries which are smaller in size (and energy capacity) and experiment with their lifetime.&lt;/p&gt;

&lt;h2 id=&quot;custom-plant-node-cases&quot;&gt;Custom plant node cases&lt;/h2&gt;

&lt;p&gt;Up until now, our prototype plant nodes have been lying around close to their plant’s pots. This is not feasible in the long term, as it is ugly, dangerous for the electronics involved, and annoying to move and clean. Designing a case which holds the battery and the SAM R21 board safely above the soil and lets us plug the sensor firmly into the ground would be a major improvement. One way to create such a case could be with the help of a 3D printer. In case you happen to have one and have experience in creating such cases for electronics, please don’t hesitate to get in touch! ;)&lt;/p&gt;

&lt;h2 id=&quot;extended-sensing&quot;&gt;Extended sensing&lt;/h2&gt;

&lt;p&gt;Apart from water, plants also have other needs. We’re planning to extend our plant nodes’ abilities to sense a multitude of other environment variables, such as oxygen, carbon dioxide, temperature or light.&lt;/p&gt;

&lt;h2 id=&quot;plant-to-plant-coordination&quot;&gt;Plant-to-plant coordination&lt;/h2&gt;

&lt;p&gt;In our current network, plant nodes only communicate with the display node, forming a tree-like topology with the display node at its root, acting as a so-called “sink node”. This is perfectly common for many IoT environments. In fact, the &lt;a href=&quot;https://tools.ietf.org/html/rfc6550&quot;&gt;Routing Protocol for Low power and Lossy Networks (RPL)&lt;/a&gt;, which watr.li currently uses to establish connections throughout the network, is optimized for exactly this scenario.&lt;/p&gt;

&lt;p&gt;However, the IoT is not just about conversations between things and humans. Machine to machine (or rather, thing to thing) communication is a central aspect of the IoT, and we believe it should be part of the Io&lt;em&gt;P&lt;/em&gt;, too. In the future of watr.li, we want to enable plants to talk amongst each other, forming a mesh- rather than a tree topology. This could enable plants to coordinate their findings amongst each other, report new or more detailed data, and even provide instructions on how to change the IoP ecosystem. Suppose, for example, all plant nodes are equipped with a light sensor. In case of under- or overexposure, the plants could coordinate amongst themselves who should switch places, and provide their humans with the resulting instructions.&lt;/p&gt;

&lt;p&gt;Employing a true mesh network could also save energy, since not all communication has to go through the Display Node. This adaption may require us to switch routing protocols, but since RIOT offers alternatives to RPL such as AODVv2 and OLSRv2 &lt;a href=&quot;https://github.com/RIOT-OS/RIOT/pull/2294&quot;&gt;(in progress)&lt;/a&gt;, that should be feasible.&lt;/p&gt;

&lt;h2 id=&quot;plant-to-thing-coordination&quot;&gt;Plant-to-thing coordination&lt;/h2&gt;

&lt;p&gt;Since we’re ultimately talking about the Internet of &lt;em&gt;Things&lt;/em&gt;, plants should be able to talk to other kinds of things, too. Some example applications for this could be: instructing blinds to move when there’s too much or too little light, regulating room temperature or humidity, or cooperating with automatic watering systems during holiday season.&lt;/p&gt;

&lt;p&gt;However, since home wireless automation over IEEE 802.15.4 is a comparatively new field with lots of incompatible, proprietary solutions, this vision may be a bit out of scope.&lt;/p&gt;

&lt;h1 id=&quot;thats-all-for-now-folks&quot;&gt;That’s all (for now), folks!&lt;/h1&gt;

&lt;p&gt;We’ve had a lot of fun building watr.li and will continue to use and enhance it, for the good of the plants in our offices. What do you think? Which crucial feature would you like to see in watr.li? What are the things we could’ve done better, or differently?&lt;/p&gt;
</description>
    </item>
    
    
    
    <item>
      <title>Sensing the humidity of a plant's soil</title>
      <link>http://watr.li/Sensing-moisture.html</link>
      <pubDate>Mon, 23 Mar 2015 00:00:00 +0000</pubDate>
      <author></author>
      <guid>http://watr.li/Sensing-moisture</guid>
      <description>&lt;p&gt;One of the last pieces of the watr.li puzzle was to measure the humidity of a plant’s soil with one of our monitoring nodes. How we connected our humidity sensor to the SAM R21 and sampled its values is the topic of this post.&lt;/p&gt;

&lt;!-- more --&gt;

&lt;p&gt;The humidity sensor basically consists of two electrodes which should pass a current. These are tucked into the soil whose humidity we want to measure. The soil becomes more electrically conductive the more humid it is, increasing the current flow. On the sensor, a common collector circuit then translates the change in current flow to a change in voltage at its output, which is the sensor’s output pin.&lt;/p&gt;

&lt;p&gt;We sample this value using the “analog to digital converter” (ADC) on the SAM R21 board. The ADC is used in an operation mode that compares the input signal to a reference voltage and then quantizes the signal. The maximum sampled value is reached when the input has the same magnitude as the reference voltage, 3.3V for our scenario. Ignoring small voltage drops caused by the transistor circuit, the sensor should roughly reach this maximum value when submerged in water. We used the ADC with a sampling width of 12-bit, leading to a maximum value of 2^12-1 = 4095.&lt;/p&gt;

&lt;h1 id=&quot;calibrating-the-adc&quot;&gt;Calibrating the ADC&lt;/h1&gt;

&lt;p&gt;Ideally, the correlation between sampled voltage and value is as shown in the figure below, i.e. the “Gain” is 1 and the “Offset” is 0.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;images/sensing-moisture/calibration.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;In our case, however the value never dropped below a certain minimum and the maximum value of 4095 (i.e. 3.3V) was never reached, even when the sensor was submerged in water. This is a common issue with cheap ADC components, which is why they include hardware capabilites to compensate these inaccuracies. This compensation has to be calibrated, though.&lt;/p&gt;

&lt;p&gt;Unfortunately, it is currently not possible to calibrate the ADC without modifying the RIOT source tree, so that is what we will have to do. The relevant settings are stored in the &lt;code class=&quot;highlighter-rouge&quot;&gt;boards/samd21-xpro/include/periph_conf&lt;/code&gt; file. The values we will need to tweak are &lt;code class=&quot;highlighter-rouge&quot;&gt;SAMPLE_0_V_OFFSET&lt;/code&gt; (the offset) and &lt;code class=&quot;highlighter-rouge&quot;&gt;SAMPLE_REF_V&lt;/code&gt; (the gain). Do determine these values we will need to run the ADC test application, as explained in the upcoming section.&lt;/p&gt;

&lt;p&gt;Additionally, the ADC conflicts with the default STDOUT device (&lt;code class=&quot;highlighter-rouge&quot;&gt;UART_0&lt;/code&gt;) on the SAM R21 board, which is piped through the EDBG USB port. To be able to see the debug output from the RIOT application nonetheless, we have to change the output to &lt;code class=&quot;highlighter-rouge&quot;&gt;UART_1&lt;/code&gt;. Since &lt;code class=&quot;highlighter-rouge&quot;&gt;UART_1&lt;/code&gt; does not have a USB interface, we’ll needed an additional USB/UART converter, which had to be connected as illustrated below:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;images/sensing-moisture/uart.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;This switch to a nonstandard output device means RIOTs &lt;code class=&quot;highlighter-rouge&quot;&gt;make term&lt;/code&gt; doesn’t listen on the right device anymore. This is why, instead of using &lt;code class=&quot;highlighter-rouge&quot;&gt;make term&lt;/code&gt;, you’ll have to start pyterm like this:&lt;/p&gt;

&lt;div class=&quot;wide highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;path to your RIOT directory&amp;gt;/tools/pyterm/pyterm -p &quot;/dev/ttyUSB0&quot;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;running-the-test-application&quot;&gt;Running the test application&lt;/h2&gt;

&lt;p&gt;The test application can be found on GitHub. In any directory, first clone the &lt;a href=&quot;https://github.com/watr-li/RIOT&quot;&gt;Watr.li RIOT fork&lt;/a&gt; and check out the “watrli” branch and then get the adc_test node from the &lt;a href=&quot;https://github.com/watr-li/nodes&quot;&gt;Watr.li nodes repository&lt;/a&gt;:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git clone https://github.com/watr-li/RIOT.git &amp;amp;&amp;amp;
    cd RIOT &amp;amp;&amp;amp;
    git checkout watrli &amp;amp;&amp;amp;
    cd .. &amp;amp;&amp;amp;
    https://github.com/watr-li/nodes.git &amp;amp;&amp;amp;
    cd nodes/adc_test &amp;amp;&amp;amp;
    BOARD=samr21-xpro make
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;setting-up-the-offset-correction&quot;&gt;Setting up the offset correction&lt;/h2&gt;

&lt;p&gt;In this test we will identify the offset, i.e. the minimum value the ADC can return with our setup. For this, &lt;code class=&quot;highlighter-rouge&quot;&gt;SAMPLE_REF_V&lt;/code&gt; needs to be initialized with 0 and &lt;code class=&quot;highlighter-rouge&quot;&gt;ADC_0_CORRECTION_EN&lt;/code&gt; has to be disabled, i.e. set to 0 too. Connect a GND pin to the ADC pin &lt;code class=&quot;highlighter-rouge&quot;&gt;PA06&lt;/code&gt; and a the 3.3V (the reference voltage) to the &lt;code class=&quot;highlighter-rouge&quot;&gt;PA04&lt;/code&gt; pin. Now run the test. The application will print values larger than &lt;code class=&quot;highlighter-rouge&quot;&gt;0&lt;/code&gt;. We’ll call this value “offset_value”. This is the value to set for &lt;code class=&quot;highlighter-rouge&quot;&gt;SAMPLE_0_V_OFFSET&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;images/sensing-moisture/offset-calibration.png&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;setting-up-the-gain-correction&quot;&gt;Setting up the gain correction&lt;/h2&gt;

&lt;p&gt;This time we try to discover the maximum value the ADC measures when the reference voltage is supplied. For this test &lt;code class=&quot;highlighter-rouge&quot;&gt;SAMPLE_0_V_OFFSET&lt;/code&gt; needs to be set as described above and &lt;code class=&quot;highlighter-rouge&quot;&gt;SAMPLE_REF_V&lt;/code&gt; has to be set to 2048. Connect the 3.3V pin to the ADC pin &lt;code class=&quot;highlighter-rouge&quot;&gt;PA06&lt;/code&gt; and run the test and to the &lt;code class=&quot;highlighter-rouge&quot;&gt;PA04&lt;/code&gt; pin. The application should print values smaller than &lt;code class=&quot;highlighter-rouge&quot;&gt;4095&lt;/code&gt;. We’ll call this value the “measured_value”.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;images/sensing-moisture/gain-calibration.png&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;calculating-the-gain&quot;&gt;Calculating the gain&lt;/h2&gt;

&lt;p&gt;The general equation for the ADC hardware correction abilities is:&lt;/p&gt;

&lt;div class=&quot;wide highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;expected_value = (measured_value - offset_value) * gain_value
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Substituting the known values and solving the equation for gain_value we get:&lt;/p&gt;

&lt;div class=&quot;wide highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;gain_value = (expected_value) / (measured_value - offset_value)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In my case, I measured the following values:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;For the &lt;code class=&quot;highlighter-rouge&quot;&gt;expected_value&lt;/code&gt; we’ll use 4095 since that is the maximum value the ADC can return with 12-bit resolution.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;offset_value = 90&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;measured_value = 3700&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The gain value thus becomes&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;gain_value = (4095) / (3700 - 90) ≈ 1.13
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;To set the microcontroller to the correct 12-bit gain value, we will need a truncated &lt;a href=&quot;http://www.cs.uwm.edu/~cs151/Bacon/Lecture/HTML/ch03s07.html&quot;&gt;binary fixed-point&lt;/a&gt; representation (&lt;a href=&quot;http://www.exploringbinary.com/binary-converter/&quot;&gt;this site&lt;/a&gt; lets you convert back and forth between the formats):&lt;/p&gt;

&lt;p&gt;
    1.13&lt;sub&gt;10&lt;/sub&gt; = 1.0010000101000111101...&lt;sub&gt;2&lt;/sub&gt;
    &lt;br /&gt;
    1.13&lt;sub&gt;10&lt;/sub&gt; ≈ 1.00100001010&lt;sub&gt;2&lt;/sub&gt; (truncated)
&lt;/p&gt;

&lt;p&gt;We then remove the decimal point in the truncated binary representation and convert the resulting binary number back to the decimal system:&lt;/p&gt;

&lt;p&gt;
    100100001010&lt;sub&gt;2&lt;/sub&gt; = 2314&lt;sub&gt;10&lt;/sub&gt;
&lt;/p&gt;

&lt;p&gt;This resulting value is the one that we want to set the &lt;code class=&quot;highlighter-rouge&quot;&gt;SAMPLE_REF_V&lt;/code&gt; parameter in our &lt;code class=&quot;highlighter-rouge&quot;&gt;periph_conf&lt;/code&gt; to.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;SAMPLE_0_V_OFFSET = 90&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;SAMPLE_REF_V = 2314&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;final-setup&quot;&gt;Final setup&lt;/h1&gt;

&lt;p&gt;After calibrating the ADC, we can finally connect the sensor! As the sensor, we’ve used a &lt;a href=&quot;http://www.dfrobot.com/index.php?route=product/product&amp;amp;product_id=599&quot;&gt;SEN0114 Moisture Sensor&lt;/a&gt; from dfrobot, which is connected to the board as follows:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;images/sensing-moisture/sensor.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Now that everything is set up and connected, we can finally get some humidity values by running the ADC test application once more!&lt;/p&gt;

&lt;p class=&quot;alert alert-warning&quot;&gt;&lt;strong&gt;Note:&lt;/strong&gt; When using the sensor in your plant pot, you should not set the soil under continuous voltage as this might damage the plant. Also you should not measure more often than “a couple of times” in an hour.&lt;/p&gt;
</description>
    </item>
    
    
    
    <item>
      <title>Serving CoAP on RIOT</title>
      <link>http://watr.li/microcoap-and-ff-copper.html</link>
      <pubDate>Tue, 17 Mar 2015 00:00:00 +0000</pubDate>
      <author></author>
      <guid>http://watr.li/microcoap-and-ff-copper</guid>
      <description>&lt;p class=&quot;alert alert-warning&quot;&gt;Note: A previous version of this post linked to a now deprecated microcoap example&lt;br /&gt;
application for RIOT. The old version also contained instructions for using &lt;a href=&quot;https://github.com/sgso/marz&quot;&gt;marz&lt;/a&gt;, which is now deprecated as well. You can find the old version of this post &lt;a href=&quot;https://github.com/watr-li/blog/blob/5c5877391fb38cb012dc6f75e0d87cb26831176c/_posts/2015-10-02-microcoap-and-ff-copper.md&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In &lt;a href=&quot;http://watr.li/what-is-coap.html&quot;&gt;a previous post&lt;/a&gt;, we explained how the &lt;a href=&quot;http://coap.technology&quot;&gt;Constrained Application Protocol (CoAP)&lt;/a&gt; enables us to exchange data between nodes in the Internet of Plants using a request/reply cycle similar to that of HTTP.&lt;br /&gt;
To do this, we need both of our node types– plant nodes and display nodes– to be able to send, process and answer CoAP requests.&lt;/p&gt;

&lt;p&gt;This post explains how to implement a simple CoAP server on our &lt;em&gt;plant nodes&lt;/em&gt;, which run &lt;a href=&quot;http://www.riot-os.org&quot;&gt;RIOT&lt;/a&gt;, using RIOTs &lt;a href=&quot;https://github.com/1248/microcoap&quot;&gt;microcoap&lt;/a&gt; package.&lt;/p&gt;

&lt;p class=&quot;alert alert-info&quot;&gt;Since no special modifications to the code are needed to get it to run on RIOT, this guide may also be useful to you if you’re looking to run microcoap on Linux or your Arduino.&lt;/p&gt;

&lt;p&gt;We’ll also show you how to test your microcoap server with &lt;a href=&quot;https://addons.mozilla.org/de/firefox/addon/copper-270430/&quot;&gt;Copper&lt;/a&gt;.&lt;/p&gt;

&lt;!-- more --&gt;

&lt;h2 id=&quot;implementing-a-small-microcoap-server&quot;&gt;Implementing a small microcoap server&lt;/h2&gt;
&lt;p&gt;This section will walk you through the implementation of a very small microcoap server. In the end, you’ll have a server which is able to answer &lt;code class=&quot;highlighter-rouge&quot;&gt;GET&lt;/code&gt; requests to &lt;code class=&quot;highlighter-rouge&quot;&gt;/riot/board&lt;/code&gt;, and (hopefully :) ) the knowledge how to extend this server at will. This guide is based on the code of &lt;a href=&quot;https://github.com/RIOT-OS/RIOT/tree/master/examples/microcoap_server&quot;&gt;this example application&lt;/a&gt;. It might be useful to keep an eye on it as a reference.&lt;br /&gt;
Let’s go through the code file by file.&lt;/p&gt;

&lt;h3 id=&quot;the-makefile&quot;&gt;The Makefile&lt;/h3&gt;
&lt;p class=&quot;alert alert-info&quot;&gt;Note: this part is only relevant if you use RIOT.&lt;/p&gt;

&lt;p&gt;Even though &lt;a href=&quot;https://github.com/RIOT-OS/RIOT/wiki/Creating-your-first-RIOT-project&quot;&gt;the RIOT wiki&lt;/a&gt; has a more in-depth explanation of RIOT Makefiles, there is one thing that you shouldn’t overlook:&lt;br /&gt;
Each RIOT Makefile specifies the board the application should be built for using the &lt;code class=&quot;highlighter-rouge&quot;&gt;BOARD&lt;/code&gt; parameter. &lt;a href=&quot;https://github.com/RIOT-OS/RIOT/blob/master/examples/microcoap_server/Makefile&quot;&gt;In the example Makefile&lt;/a&gt;, you’ll find the following line:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;BOARD ?= native
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This means that your application will be built as a &lt;em&gt;native&lt;/em&gt; applications. the application and the RIOT instance it is running on will run inside a thread on your Linux OS, which is great for testing and debugging. Once you’re ready to flash your code to your actual board, substitute &lt;code class=&quot;highlighter-rouge&quot;&gt;native&lt;/code&gt; with the name of your board (in our case &lt;code class=&quot;highlighter-rouge&quot;&gt;samr21-xpro&lt;/code&gt;) and &lt;a href=&quot;http://watr.li/samr21-dev-setup-ubuntu.html&quot;&gt;flash it&lt;/a&gt;.&lt;/p&gt;

&lt;p class=&quot;alert alert-info&quot;&gt;Please note that microcoap currently doesn’t have a nice API to create requests on its own (i.e. without being triggered by a client). It can be done, though, but that’s for another blog post.&lt;/p&gt;

&lt;h3 id=&quot;endpointsc&quot;&gt;endpoints.c&lt;/h3&gt;

&lt;p&gt;As explained in our &lt;a href=&quot;/what-is-coap.html&quot;&gt;previous post&lt;/a&gt;, a CoAP server answers requests which are directed at the &lt;em&gt;resource&lt;/em&gt; of a certain &lt;em&gt;endpoint&lt;/em&gt; (namely, the IP address of our server). Our server will thus have to define the resources which can be requested, and how to handle these requests.&lt;/p&gt;

&lt;p&gt;Probably a bit confusingly named, microcoap handles this with the help of an array of type &lt;code class=&quot;highlighter-rouge&quot;&gt;endpoints&lt;/code&gt;.&lt;br /&gt;
This array should &lt;em&gt;not&lt;/em&gt; contain information about any endpoints (i.e. IP and port pairs), but information about your resources.&lt;br /&gt;
You will have to create a &lt;code class=&quot;highlighter-rouge&quot;&gt;const coap_endpoint_t endpoints[]&lt;/code&gt; and fill it to match your desired endpoints and how they should be handled. Let’s look at this step by step.&lt;/p&gt;

&lt;p&gt;In &lt;code class=&quot;highlighter-rouge&quot;&gt;microcoap_server/coap.c&lt;/code&gt;, you will find that the example application has created an array of &lt;code class=&quot;highlighter-rouge&quot;&gt;coap_endpoint_t&lt;/code&gt; called &lt;code class=&quot;highlighter-rouge&quot;&gt;endpoints&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-c highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;coap_endpoint_t&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;endpoints&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;COAP_METHOD_GET&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;handle_get_well_known_core&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
      &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path_well_known_core&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;ct=40&quot;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;COAP_METHOD_GET&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;handle_get_riot_board&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
      &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path_riot_board&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;    &lt;span class=&quot;s&quot;&gt;&quot;ct=0&quot;&lt;/span&gt;  &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
    &lt;span class=&quot;cm&quot;&gt;/* marks the end of the endpoints array: */&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;coap_method_t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;NULL&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;For simplicity’s sake, we’ll only be looking at the second entry from now on.&lt;/p&gt;

&lt;p&gt;Now, if we look at the &lt;code class=&quot;highlighter-rouge&quot;&gt;coap.h&lt;/code&gt; file of &lt;a href=&quot;https://github.com/1248/microcoap/blob/master/coap.h#L138&quot;&gt;the microcoap code&lt;/a&gt;, we can see that a &lt;code class=&quot;highlighter-rouge&quot;&gt;coap_endpoint_t&lt;/code&gt; is defined as follows:&lt;/p&gt;

&lt;div class=&quot;language-c wide highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;typedef&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;coap_method_t&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;              &lt;span class=&quot;cm&quot;&gt;/* (i.e. POST, PUT or GET) */&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;coap_endpoint_func&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;handler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;         &lt;span class=&quot;cm&quot;&gt;/* callback function which
                                         * handles this type of
                                         * endpoint (and calls
                                         * coap_make_response()
                                         * at some point) */&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;coap_endpoint_path_t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;cm&quot;&gt;/* path towards a resource
                                         * (i.e. foo/bar/) */&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;core_attr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;             &lt;span class=&quot;cm&quot;&gt;/* the 'ct' attribute,
                                         * as defined in RFC7252,
                                         * section 7.2.1.:
                                         * &quot;The Content-Format code
                                         * &quot;ct&quot; attribute provides
                                         * a hint about the
                                         * Content-Formats this
                                         * resource returns.&quot;
                                         * (Section 12.3. lists
                                         * possible ct values.) */&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;coap_endpoint_t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This helps us understand the entries of our &lt;code class=&quot;highlighter-rouge&quot;&gt;endpoints[]&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;COAP_METHOD_GET&lt;/code&gt; specifies that this entry describes how to handle a &lt;code class=&quot;highlighter-rouge&quot;&gt;GET&lt;/code&gt; request.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;handle_get_response&lt;/code&gt; is the function which should be called in case a suitable request has been received.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;&amp;amp;path&lt;/code&gt; is a pointer towards the path that specifies the resource which is handled by this entry. &lt;code class=&quot;highlighter-rouge&quot;&gt;path&lt;/code&gt; is defined as&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-c wide highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;coap_endpoint_path_t&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;path_riot_board&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;riot&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;board&quot;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;a few lines up, so we know that this entry handles a path which contains two segments, namely &lt;code class=&quot;highlighter-rouge&quot;&gt;/riot/board&lt;/code&gt;.&lt;/p&gt;

&lt;p class=&quot;alert alert-warning&quot;&gt;microcoap supports a maximum segment number of two out of the box. If you need more, you’ll have to adjust &lt;code class=&quot;highlighter-rouge&quot;&gt;MAX_SEGMENTS&lt;/code&gt; in &lt;code class=&quot;highlighter-rouge&quot;&gt;coap.h&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;&quot;ct=0&quot;&lt;/code&gt; Specifies the Content-Format, which is a hint on how to interpret the payload of the packet (if any). In this case, the content format is 0, which stands for &lt;code class=&quot;highlighter-rouge&quot;&gt;text/plain&lt;/code&gt;&lt;br /&gt;
 A list of possible Content-Format types can be found in &lt;a href=&quot;https://tools.ietf.org/html/rfc7252#section-12.3&quot;&gt;section 12.3 of the CoAP RFC&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If our CoAP server receives a request which matches this definition, i.e. a &lt;code class=&quot;highlighter-rouge&quot;&gt;GET&lt;/code&gt; request to &lt;code class=&quot;highlighter-rouge&quot;&gt;/riot/board/&lt;/code&gt; with the Content-Format set to &lt;code class=&quot;highlighter-rouge&quot;&gt;0=text/plain&lt;/code&gt;, the &lt;code class=&quot;highlighter-rouge&quot;&gt;handle_get_riot_board()&lt;/code&gt; function will be called, which handles the processing of this request and the creation of a response, if necessary. Let’s look at this function in detail:&lt;/p&gt;

&lt;div class=&quot;language-c wide highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;handle_get_riot_board&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;coap_rw_buffer_t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;scratch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;coap_packet_t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;inpkt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;coap_packet_t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;outpkt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;kt&quot;&gt;uint8_t&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;id_hi&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;uint8_t&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;id_lo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;riot_name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RIOT_BOARD&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;len&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;strlen&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;RIOT_BOARD&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;memcpy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;riot_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;coap_make_response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;scratch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;outpkt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                             &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;uint8_t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                              &lt;span class=&quot;n&quot;&gt;id_hi&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;id_lo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;inpkt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tok&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                              &lt;span class=&quot;n&quot;&gt;COAP_RSPCODE_CONTENT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                              &lt;span class=&quot;n&quot;&gt;COAP_CONTENTTYPE_TEXT_PLAIN&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Whenever a callback function that is defined in an &lt;code class=&quot;highlighter-rouge&quot;&gt;coap_endpoint_t&lt;/code&gt; is called, it is provided with parameters. Let’s look at the ones that may be important to you.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;const coap_packet_t *inpkt&lt;/code&gt; Is a pointer to the packet which caused this callback to be called. This way, your callback function can examine its content and determine how it should react.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;coap_packet_t *outpkt&lt;/code&gt; Is a pointer to the buffer into which a response packet can be written.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;uint8_t id_hi&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;uint8_t id_lo&lt;/code&gt; Are, when put together, the CoAP Message ID. These Message IDs are used to detect duplicate packets or to match Acknowledgement packets to the requests that triggered them.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Because &lt;code class=&quot;highlighter-rouge&quot;&gt;handle_get_riot_board()&lt;/code&gt; handles a &lt;code class=&quot;highlighter-rouge&quot;&gt;GET&lt;/code&gt; request, we want this function to answer with a response value. So we’re copying the current BOARD name into &lt;code class=&quot;highlighter-rouge&quot;&gt;response[]&lt;/code&gt;.&lt;br /&gt;
Then, we use &lt;code class=&quot;highlighter-rouge&quot;&gt;coap_make_response()&lt;/code&gt; to build our packet:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The struct that the &lt;code class=&quot;highlighter-rouge&quot;&gt;outpkt&lt;/code&gt; pointer points to is filled with fresh data.&lt;/li&gt;
  &lt;li&gt;The data behind &lt;code class=&quot;highlighter-rouge&quot;&gt;response&lt;/code&gt; is incorporated into &lt;code class=&quot;highlighter-rouge&quot;&gt;outpkt&lt;/code&gt; as payload.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;id_hi&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;id_lo&lt;/code&gt; are echoed back to help our client match the response to its request.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;COAP_RSPCODE_CONTENT&lt;/code&gt; sets the message response code to &lt;code class=&quot;highlighter-rouge&quot;&gt;2.05 Content&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;COAP_CONTENTTYPE_TEXT_PLAIN&lt;/code&gt; sets the media type to &lt;code class=&quot;highlighter-rouge&quot;&gt;text/plain&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When this is done, &lt;code class=&quot;highlighter-rouge&quot;&gt;handle_get_riot_board()&lt;/code&gt; returns the response code that &lt;code class=&quot;highlighter-rouge&quot;&gt;coap_make_response()&lt;/code&gt; gave us, so that &lt;code class=&quot;highlighter-rouge&quot;&gt;main.c&lt;/code&gt; knows if our endeavors were successful.&lt;/p&gt;

&lt;p&gt;As you can see, our response payload in this example is very simple. In a real application, however, this might be where you’ll read out sensor data which has been requested.&lt;/p&gt;

&lt;p class=&quot;alert alert-warning&quot;&gt;Note that microcoap will recognize the endpoints array by its name. This will &lt;strong&gt;not&lt;/strong&gt; work if your array is called anything but &lt;code class=&quot;highlighter-rouge&quot;&gt;endpoints&lt;/code&gt;!&lt;/p&gt;

&lt;h3 id=&quot;microcoap_connc&quot;&gt;microcoap_conn.c&lt;/h3&gt;
&lt;p class=&quot;alert alert-info&quot;&gt;Now, let’s see how we can use our newly-defined endpoints to handle requests.&lt;br /&gt;
For an in-depth explanation of the structure of a RIOT application, please &lt;a href=&quot;https://github.com/RIOT-OS/RIOT/wiki/Creating-your-first-RIOT-project&quot;&gt;see this RIOT wiki page&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You’ll see that &lt;code class=&quot;highlighter-rouge&quot;&gt;microcoap_server_loop()&lt;/code&gt; starts with calls to &lt;code class=&quot;highlighter-rouge&quot;&gt;conn_udp_create()&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;conn_udp_recvfrom()&lt;/code&gt;. This is RIOT-specific code to set up and receive from a UDP connection and can be substituted with regular POSIX socket code, if that’s what you need.&lt;/p&gt;

&lt;p&gt;The interesting part starts at line 60:&lt;/p&gt;

&lt;div class=&quot;language-c highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cm&quot;&gt;/* parse UDP packet to CoAP */&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rc&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;coap_parse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pkt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;_udp_buf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)))&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;DEBUG&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Bad packet rc=%d&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;checks whether the packet we received is actually a valid CoAP packet.&lt;/p&gt;

&lt;div class=&quot;language-c highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;coap_packet_t&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rsppkt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;DEBUG&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;content:&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;coap_dumpPacket&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pkt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;cm&quot;&gt;/* handle CoAP request */&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;coap_handle_req&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;scratch_buf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pkt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rsppkt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;After the packet passes this test, it is passed to &lt;code class=&quot;highlighter-rouge&quot;&gt;coap_handle_req()&lt;/code&gt;. If the method and path of the request match one of the method-path combinations we specified in &lt;code class=&quot;highlighter-rouge&quot;&gt;endpoints[]&lt;/code&gt; earlier on, the &lt;code class=&quot;highlighter-rouge&quot;&gt;coap_endpoint_func handler&lt;/code&gt; provided along with them (in our case, this is &lt;code class=&quot;highlighter-rouge&quot;&gt;handle_get_riot_board&lt;/code&gt;) will be called automagically. The resulting response packet is written into &lt;code class=&quot;highlighter-rouge&quot;&gt;rsppkt&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-c highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cm&quot;&gt;/* build reply */&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;size_t&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rsplen&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;sizeof&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_udp_buf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rc&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;coap_build&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_udp_buf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rsplen&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rsppkt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;DEBUG&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;coap_build failed rc=%d&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now, the response packet &lt;code class=&quot;highlighter-rouge&quot;&gt;rsppkt&lt;/code&gt; we just built is serialized and written to &lt;code class=&quot;highlighter-rouge&quot;&gt;buf&lt;/code&gt; so that we can send it. Note that we also pass a &lt;em&gt;pointer&lt;/em&gt; to &lt;code class=&quot;highlighter-rouge&quot;&gt;rsplen&lt;/code&gt;: This doesn’t just tell &lt;code class=&quot;highlighter-rouge&quot;&gt;coap_build()&lt;/code&gt; the size of our buffer. When &lt;code class=&quot;highlighter-rouge&quot;&gt;coap_build()&lt;/code&gt; is done, it will have written the actual CoAP packet size to &lt;code class=&quot;highlighter-rouge&quot;&gt;rsplen&lt;/code&gt;. This way, we can avoid sending bogus data which fills the rest of &lt;code class=&quot;highlighter-rouge&quot;&gt;buf&lt;/code&gt; by providing our send function with &lt;code class=&quot;highlighter-rouge&quot;&gt;rsplen&lt;/code&gt; as the buffer size indicator:&lt;/p&gt;

&lt;div class=&quot;language-c wide highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;DEBUG&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Sending packet: &quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;coap_dump&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_udp_buf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rsplen&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;DEBUG&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;DEBUG&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;content:&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;coap_dumpPacket&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rsppkt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;cm&quot;&gt;/* send reply via UDP */&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;rc&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;conn_udp_sendto&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_udp_buf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rsplen&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;raddr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;raddr_len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                         &lt;span class=&quot;n&quot;&gt;AF_INET6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;COAP_SERVER_PORT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rport&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rc&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;DEBUG&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Error sending CoAP reply via udp; %u&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And that’s it! We’ve now successfully received, processed and answered a CoAP request.&lt;/p&gt;

&lt;h2 id=&quot;testing-your-microcoap-server&quot;&gt;Testing your microcoap server&lt;/h2&gt;
&lt;p&gt;Now that our microcoap server is up and running, we’ll want to feed it requests and see if it behaves as expected. This section will guide you through the setup of a simple environment which lets you do this. (Despite the somewhat misleading terminology, this section is &lt;em&gt;not&lt;/em&gt; about thorough, automated tests.)&lt;/p&gt;

&lt;h3 id=&quot;using-copper-as-a-test-client&quot;&gt;Using Copper as a test client&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;https://addons.mozilla.org/de/firefox/addon/copper-270430/&quot;&gt;Copper&lt;/a&gt;, is a Firefox plugin that turns your browser into a powerful CoAP client.&lt;/p&gt;

&lt;h3 id=&quot;radvd-making-riot-available-to-copper&quot;&gt;radvd: making RIOT available to Copper&lt;/h3&gt;
&lt;!--
TODO: remarks about missing zone indices etc.. you only need this if you use copper (or anything else that doesnt understand them ^^)
--&gt;

&lt;p&gt;If your microcoap application is running on RIOT native, there are some extra hoops to jump through before you can test it with Copper (in case you don’t use RIOT, skip this subsection).&lt;/p&gt;

&lt;p&gt;Make sure you’ve installed the Router Advertisement Daemon (&lt;code class=&quot;highlighter-rouge&quot;&gt;radvd&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;Build the application again using &lt;code class=&quot;highlighter-rouge&quot;&gt;make&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Enter the following into your &lt;code class=&quot;highlighter-rouge&quot;&gt;/etc/radvd.conf&lt;/code&gt; (if it doesn’t exist yet, create one):&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;interface tap0
{
    AdvSendAdvert on;

    MinRtrAdvInterval 3;
    MaxRtrAdvInterval 10;

    AdvDefaultPreference low;

    prefix 2001:db8:1:0::/64
    {
        AdvOnLink on;
        AdvAutonomous on;
        AdvRouterAddr off;
    };
};
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;(you can use &lt;code class=&quot;highlighter-rouge&quot;&gt;radvd -c&lt;/code&gt; to check for syntax errors)&lt;/p&gt;

&lt;p&gt;and run&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo radvd
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Then, run the RIOT binary as usual:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;make term
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Note that the output listing all configured interfaces contains a globally scoped&lt;br /&gt;
address, which you can now use to reach the RIOT instance via Copper.&lt;/p&gt;

&lt;p&gt;After you’ve installed the Copper plugin in your Firefox browser and successfully set up &lt;code class=&quot;highlighter-rouge&quot;&gt;radvd&lt;/code&gt;, start the microcoap application:&lt;/p&gt;

&lt;div class=&quot;wide highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ make term

RIOT native interrupts/signals initialized.
LED_GREEN_OFF
LED_RED_ON
RIOT native board initialized.
RIOT native hardware initialization complete.

main(): This is RIOT! (Version: 2016.03-devel-145-g7da0d-ubuntu)
RIOT microcoap example application
Configured network interfaces:
Iface  5   HWaddr: 62:fc:3c:5e:40:df
           MTU:1500  HL:64  RTR  RTR_ADV
           Source address length: 6
           Link type: wired
           inet6 addr: ff02::1/128  scope: local [multicast]
           inet6 addr: fe80::60fc:3cff:fe5e:40df/64  scope: local
           inet6 addr: ff02::1:ff5e:40df/128  scope: local [multicast]
           inet6 addr: ff02::2/128  scope: local [multicast]
           inet6 addr: 2001:db8:1:0:e42a:1aff:feca:10ec/64  scope: global

Waiting for incoming UDP packet...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Note the address marked as “scope: &lt;strong&gt;global&lt;/strong&gt;”. This is the address you’ll use to communicate with your microcoap server using Copper.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;If the above doesn’t work,&lt;/strong&gt; try manually adding a Global address to the tap0 interface:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo service radvd start
sudo ip address add 2001:db8:1::a/64 dev tap0
make term
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;using-copper&quot;&gt;Using Copper&lt;/h3&gt;

&lt;p&gt;Now, you can enter&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;coap://[2001:db8:1:0:e42a:1aff:feca:10ec]/riot/board
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;into your Firefox address bar, where you should replace &lt;code class=&quot;highlighter-rouge&quot;&gt;2001:db8:1:0:e42a:1aff:feca:10ec&lt;/code&gt; with your server’s IPv6 address (for RIOT, tis is the “scope: global” address). If you use IPv4, remove the &lt;code class=&quot;highlighter-rouge&quot;&gt;[]&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Your browser window should look similar to this:&lt;/p&gt;

&lt;!--TODO update image --&gt;
&lt;p&gt;&lt;img src=&quot;../images/microcoap/copper_before.png&quot; alt=&quot;Copper start window&quot; /&gt;&lt;/p&gt;

&lt;!-- TODO update path, get results etc --&gt;

&lt;p&gt;Now you can click the big green &lt;code class=&quot;highlighter-rouge&quot;&gt;GET&lt;/code&gt; button. This will send a GET request to the resource &lt;code class=&quot;highlighter-rouge&quot;&gt;foo/bar/&lt;/code&gt; of our microcoap server. Our server should reply with a &lt;code class=&quot;highlighter-rouge&quot;&gt;2.05 Content&lt;/code&gt; message containing the payload &lt;code class=&quot;highlighter-rouge&quot;&gt;native&lt;/code&gt;, which Copper should display in the big grey box, similar to the “1337” in this screenshot:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;../images/microcoap/copper_after.png&quot; alt=&quot;Copper start window&quot; /&gt;&lt;/p&gt;

&lt;p&gt;When all of this works, you’re ready to go. Extend &lt;code class=&quot;highlighter-rouge&quot;&gt;endpoints[]&lt;/code&gt; with your own methods and paths, create response payloads that actually make sense and build awesome stuff with your new CoAP server. Happy hacking!&lt;/p&gt;
</description>
    </item>
    
    
    
    <item>
      <title>Californium meets the Play Framework</title>
      <link>http://watr.li/play2-californium.html</link>
      <pubDate>Tue, 24 Feb 2015 00:00:00 +0000</pubDate>
      <author></author>
      <guid>http://watr.li/play2-californium</guid>
      <description>&lt;p&gt;On our Raspberry Pi web interface we want to display the data from all our plant nodes in “realtime”. In this post we will be introducing our technology stack that will be running on the Raspberry Pi and explain step by step how all the pieces fit and can be made to work together.&lt;/p&gt;

&lt;!-- more --&gt;

&lt;p&gt;&lt;img src=&quot;images/play2-californium/architecture.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The graphic shows an abstract overview of our setup. On the bottom left we have one of our plant nodes which communicates with the &lt;a href=&quot;https://www.eclipse.org/californium/&quot;&gt;Eclipse Californium&lt;/a&gt; Server via the CoAP protocol, both of which have been introduced &lt;a href=&quot;/what-is-coap.html&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To develop the web interface we have chosen the &lt;a href=&quot;https://playframework.com/&quot;&gt;Play framework&lt;/a&gt; because it runs inside the JVM and thus integrates well with Californium. The communication between the Californium Server and the web application is established through an &lt;a href=&quot;http://akka.io/&quot;&gt;Akka&lt;/a&gt; Actor, which is the conventional solution for asynchronous communication within Play. Lastly, the user’s browser communicates with the Play application server using HTTP as well as the WebSocket protocol for “realtime” updates. Communication between actors is highlighted in red. No protocol is mentioned because no serialization of the messages is necessary, since the subsystems operate inside the same Java Virtual Machine, thus making it possible to simply pass Java objects around.&lt;/p&gt;

&lt;h1 id=&quot;creating-a-play-application&quot;&gt;Creating a Play application&lt;/h1&gt;

&lt;p&gt;In order to create a new Play application, Java has to be installed on your system. Please follow the guide on &lt;a href=&quot;https://playframework.com/documentation/2.3.x/Installing&quot;&gt;playframework.com&lt;/a&gt; on how to install the Play framework itself. After the installation you’re ready to create a new Play app. Since this article does not intend to be an introduction to the Play framework, only the necessary steps are shown here. For more details check out the framework’s &lt;a href=&quot;https://playframework.com/documentation/2.3.x/Home&quot;&gt;getting started guide&lt;/a&gt;.&lt;/p&gt;

&lt;p class=&quot;alert alert-info&quot;&gt;&lt;strong&gt;Note:&lt;/strong&gt; While Play offers the option for development in Scala, this blogpost relies entirely on an implementation written in Java, in the the hope that a Java implementation reaches a wider audience. Most parts should be easily interchangeable with Scala code, however.&lt;/p&gt;

&lt;p&gt;To create a new Play application based on the Java template, run the following in your console after installing Play:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;activator new play-californium play-java
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This will create a new directory &lt;code class=&quot;highlighter-rouge&quot;&gt;play-californium&lt;/code&gt; in the current directory, to which we can switch and execute &lt;code class=&quot;highlighter-rouge&quot;&gt;./activator run&lt;/code&gt;. This will start a webserver at port 9000, so navigating to &lt;code class=&quot;highlighter-rouge&quot;&gt;http://localhost:9000&lt;/code&gt; should display the Play welcome message.&lt;/p&gt;

&lt;p class=&quot;alert alert-info&quot;&gt;&lt;strong&gt;Note:&lt;/strong&gt; Play automatically detects changes in the project directory after each request to the webserver, so it is not necessary to restart it after source code changes.&lt;/p&gt;

&lt;h1 id=&quot;adding-eclipse-californium&quot;&gt;Adding Eclipse Californium&lt;/h1&gt;

&lt;p&gt;Now that we have a very basic Play application set up we want to add Californium as a dependency. To do this, we include the following line in the &lt;code class=&quot;highlighter-rouge&quot;&gt;build.sbt&lt;/code&gt; file within the project’s root directory:&lt;/p&gt;

&lt;div class=&quot;language-groovy highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;libraryDependencies&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;org.eclipse.californium&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;californium-core&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;1.0.0-M3&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p class=&quot;alert alert-warning&quot;&gt;&lt;strong&gt;Note:&lt;/strong&gt; The above statement has to be surrounded by newlines or an error will be thrown. This is a convention of the Scala Build Tool (SBT) which is used by Play.&lt;/p&gt;

&lt;p&gt;After adding said line and re-running &lt;code class=&quot;highlighter-rouge&quot;&gt;./activator&lt;/code&gt;, the dependency should now be included in the project. If 1.0.0-M3 should not be the &lt;a href=&quot;https://oss.sonatype.org/#nexus-search;gav~org.eclipse.californium~californium-core~~~&quot;&gt;current release&lt;/a&gt; of &lt;code class=&quot;highlighter-rouge&quot;&gt;californium-core&lt;/code&gt; then you will have to update the last segment of the above dependency to match the current version designation.&lt;/p&gt;

&lt;h1 id=&quot;starting-a-californium-server&quot;&gt;Starting a Californium Server&lt;/h1&gt;

&lt;p&gt;Background jobs in Play are executed through so-called “Actors”, which are lightweight concurrent entities which process messages asynchronously (&lt;a href=&quot;http://doc.akka.io/docs/akka/snapshot/general/actor-systems.html#actor-systems&quot;&gt;docs.akka.io&lt;/a&gt; provides a much more detailed explanation). We will use such an actor to handle creation and graceful shutdown of our Californium CoAP server. Additionally it will handle communication between the CoAP server and the rest of the Play application.&lt;/p&gt;

&lt;h2 id=&quot;the-californium-server-actor&quot;&gt;The Californium Server Actor&lt;/h2&gt;

&lt;p&gt;Actors in Play (which uses the Akka framework) have a single abstract method &lt;code class=&quot;highlighter-rouge&quot;&gt;void receive(Object message)&lt;/code&gt; that needs to be implemented and is invoked whenever the actor receives a message. The following code is shortened for better readability of the article. Please refer to &lt;a href=&quot;https://github.com/watr-li/play-californium/blob/master/app/actors/CaliforniumServerActor.java&quot;&gt;GitHub&lt;/a&gt; for the full source:&lt;/p&gt;

&lt;div class=&quot;language-java wide highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;package&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;actors&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;[...]&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;CaliforniumServerActor&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;UntypedActor&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;LoggingAdapter&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;log&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Logging&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getLogger&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getContext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;system&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(),&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;CaliforniumServer&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;server&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;[...]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;There are several types of actors, but we will be working with the simplest, the &lt;code class=&quot;highlighter-rouge&quot;&gt;UntypedActor&lt;/code&gt;. The &lt;code class=&quot;highlighter-rouge&quot;&gt;server&lt;/code&gt; variable will hold a reference to the instantiated Californium server, which is initialized in the constructor. The implementation of said server is presented in the next section.&lt;/p&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;CaliforniumServerActor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;super&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;server&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;CaliforniumServer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;initialize&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getSelf&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;());&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Here we pass a reference to the actor, obtained by calling &lt;code class=&quot;highlighter-rouge&quot;&gt;getSelf&lt;/code&gt; and of type &lt;code class=&quot;highlighter-rouge&quot;&gt;ActorRef&lt;/code&gt;, as a parameter to the Californium initialization routine. We do this so that the Californium server will be able to send messages to the Californium actor and thus to the Play application.&lt;/p&gt;

&lt;p&gt;Now that the server is initialized, only the &lt;code class=&quot;highlighter-rouge&quot;&gt;onReceive&lt;/code&gt; method remains to be implemented. This method defines which types of messages an actor can react to. The message is passed as an &lt;code class=&quot;highlighter-rouge&quot;&gt;Object&lt;/code&gt; parameter, so it is possible to simply send strings as messages to the actor. It is preferable to send Java objects though, since these can be extended with additional data attributes when necessary. For example, for our server actor we will implement two messages, &lt;code class=&quot;highlighter-rouge&quot;&gt;CoapMessageReceived&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;ShutdownActor&lt;/code&gt;. These messages are simple Java objects which store data to be transmitted in the message. The implementation for our two messages looks like this:&lt;/p&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// app/actors/messages/CoapMessageReceived.java&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;package&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;actors&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;messages&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;CoapMessageReceived&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;CoapMessageReceived&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;message&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;getMessage&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// app/actors/messages/ShutdownActor.java&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;package&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;actors&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;messages&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;ShutdownActor&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In our &lt;code class=&quot;highlighter-rouge&quot;&gt;onReceive&lt;/code&gt; method we can now check which type of message we have received using &lt;code class=&quot;highlighter-rouge&quot;&gt;instanceof&lt;/code&gt;. If the received message contains actual data we can then cast it to the correct type and call the defined getter methods, like so:&lt;/p&gt;

&lt;div class=&quot;language-java wide highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;onReceive&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Object&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;throws&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Exception&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;message&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;instanceof&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;CoapMessageReceived&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;CoapMessageReceived&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;msg&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;CoapMessageReceived&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Received a message via CoAP: {}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;msg&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getMessage&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;());&lt;/span&gt;

  &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;message&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;instanceof&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ShutdownActor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Graceful shutdown&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;server&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;stop&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;getSelf&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;tell&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;akka&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;actor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;PoisonPill&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getInstance&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;getSelf&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;());&lt;/span&gt;

  &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Unhandled message: {}&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;unhandled&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;One thing to note is the &lt;code class=&quot;highlighter-rouge&quot;&gt;ShutdownActor&lt;/code&gt; case. In it, we first call &lt;code class=&quot;highlighter-rouge&quot;&gt;server.stop()&lt;/code&gt; to shutdown the Californium server. In the following line we send a &lt;code class=&quot;highlighter-rouge&quot;&gt;PoisonPill&lt;/code&gt; message to the current actor. This is a message provided by the Akka actor framework which instructs the actor to process all messages remaining in its inbox and then shut itself down.&lt;/p&gt;

&lt;h2 id=&quot;starting-the-actor&quot;&gt;Starting the actor&lt;/h2&gt;

&lt;p&gt;Now that we’ve created our actor we need to initialize it when the Play application starts. This is done by defining a &lt;a href=&quot;https://www.playframework.com/documentation/2.3.x/ScalaGlobal&quot;&gt;Global object&lt;/a&gt; which handles global settings and startup routines in Play. For that, we create a &lt;code class=&quot;highlighter-rouge&quot;&gt;Global.java&lt;/code&gt; inside the &lt;code class=&quot;highlighter-rouge&quot;&gt;app/global/&lt;/code&gt; directory (which we have to create), adding the following content:&lt;/p&gt;

&lt;div class=&quot;language-java wide highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;package&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;global&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;[...]&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Global&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;GlobalSettings&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ActorRef&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;californiumActor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;onStart&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Application&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;californiumActor&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Akka&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;system&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;actorOf&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;Props&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;CaliforniumServerActor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;onStop&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Application&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;californiumActor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;tell&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ShutdownActor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(),&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ActorRef&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;getCaliforniumActor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;californiumActor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In the &lt;code class=&quot;highlighter-rouge&quot;&gt;onStart&lt;/code&gt; method we create an instance of our Californium Server Actor and store the reference for later access. In &lt;code class=&quot;highlighter-rouge&quot;&gt;onStop&lt;/code&gt; we send it a &lt;code class=&quot;highlighter-rouge&quot;&gt;ShutdownActor&lt;/code&gt; message to gracefully shutdown the Californium server as well as itself. For a more in-depth explanation of how the Play integration of Akka works please refer to the &lt;a href=&quot;https://www.playframework.com/documentation/2.3.x/JavaAkka&quot;&gt;Play documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Normally Play expects the Global object to reside inside the &lt;code class=&quot;highlighter-rouge&quot;&gt;app/&lt;/code&gt; directory. Unfortuntately Java does not allow access to classes in the root namespace from other packages, which we will need later in order to obtain a reference to the server actor through the &lt;code class=&quot;highlighter-rouge&quot;&gt;getCaliforniumActor&lt;/code&gt; getter. To work around this limitation we have to put the Global object in the &lt;code class=&quot;highlighter-rouge&quot;&gt;global&lt;/code&gt; package (any name works though) and tell Play where to find it. We do this by adding the following line to the &lt;code class=&quot;highlighter-rouge&quot;&gt;conf/application.conf&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;application.global=global.Global
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;example-californium-server&quot;&gt;Example Californium Server&lt;/h1&gt;

&lt;p&gt;For this guide we have slightly modified the official &lt;a href=&quot;https://github.com/eclipse/californium/blob/master/cf-helloworld-server/src/main/java/org/eclipse/californium/examples/HelloWorldServer.java&quot;&gt;Californium Hello World Server&lt;/a&gt;. The following section highlights our modifications. For the full class please refer to &lt;a href=&quot;https://github.com/watr-li/play-californium/blob/master/app/californium/CaliforniumServer.java&quot;&gt;GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Just as in the Hello World example, our server class inherits from &lt;code class=&quot;highlighter-rouge&quot;&gt;CoapServer&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-java highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// app/californium/CaliforniumServer.java&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;CaliforniumServer&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;CoapServer&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;ActorRef&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;serverActor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;[...]&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Instead of a static &lt;code class=&quot;highlighter-rouge&quot;&gt;main(String[] args)&lt;/code&gt; method we use a static method that initializes the server, passing a reference to our server actor from the previous section, and returning the resulting instance:&lt;/p&gt;

&lt;div class=&quot;language-java wide highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;CaliforniumServer&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;initialize&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ActorRef&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;serverActor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;CaliforniumServer&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;server&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;server&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;CaliforniumServer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;serverActor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;server&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;start&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;();&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;catch&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SocketException&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Failed to initialize server: &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getMessage&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;());&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;server&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Then comes the constructor which registers our example CoAP resource and stores the reference to the server actor so that we can later send messages to it:&lt;/p&gt;

&lt;div class=&quot;language-java wide highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;CaliforniumServer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ActorRef&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;serverActor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;throws&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SocketException&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;serverActor&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;serverActor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;HelloWorldResource&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;());&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Lastly we define said resource as an inner class of the &lt;code class=&quot;highlighter-rouge&quot;&gt;CaliforniumServer&lt;/code&gt;. The constructor of the &lt;code class=&quot;highlighter-rouge&quot;&gt;CoapResource&lt;/code&gt; takes the resource name as a parameter, which in this case is &lt;code class=&quot;highlighter-rouge&quot;&gt;helloWorld&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In order to send messages to the resource we still need to define a handler for one of the CoAP methods (GET, POST, PUT and DELETE). We don’t use GET (as the Californium HelloWorld example does) because &lt;a href=&quot;/what-is-coap.html&quot;&gt;it cannot have a payload&lt;/a&gt;.&lt;/p&gt;

&lt;div class=&quot;language-java wide highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;HelloWorldResource&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;CoapResource&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;

  &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;HelloWorldResource&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;super&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;helloWorld&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;getAttributes&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;setTitle&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Hello-World Resource&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;handlePUT&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;CoapExchange&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;exchange&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;serverActor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;tell&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;CoapMessageReceived&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;exchange&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;getRequestText&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;()),&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;exchange&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;respond&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ResponseCode&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;CHANGED&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In the &lt;code class=&quot;highlighter-rouge&quot;&gt;handlePUT&lt;/code&gt; method we notify the server actor that a message has been received through a &lt;code class=&quot;highlighter-rouge&quot;&gt;CoapMessageReceived&lt;/code&gt; instance containing the message’s paylod. The second parameter of &lt;code class=&quot;highlighter-rouge&quot;&gt;tell&lt;/code&gt; is the sending actor. Since we’re not in an actor context and do not need to receive a response from the actor, we can simply pass null. Lastly we respond with the &lt;code class=&quot;highlighter-rouge&quot;&gt;CHANGED&lt;/code&gt; response code which indicates that the request was successful but did not result in the creation of a new resource.&lt;/p&gt;

&lt;h1 id=&quot;testing-locally&quot;&gt;Testing locally&lt;/h1&gt;

&lt;p&gt;Now let’s test what we’ve built. In the Play project’s root directory, launch &lt;code class=&quot;highlighter-rouge&quot;&gt;./activator run&lt;/code&gt; (if it isn’t still running) and navigate to &lt;code class=&quot;highlighter-rouge&quot;&gt;http://localhost:9000&lt;/code&gt;. This will initialize the Californium server and the actors, thus allowing us to receive CoAP messages.&lt;/p&gt;

&lt;p&gt;To test that functionality we’ll be using &lt;a href=&quot;https://addons.mozilla.org/en-US/firefox/addon/copper-270430/&quot;&gt;Eclipse Copper&lt;/a&gt;, a Firefox plugin that adds &lt;code class=&quot;highlighter-rouge&quot;&gt;coap://&lt;/code&gt; URI support. After installing Copper and the server, we should be able to navigate to &lt;code class=&quot;highlighter-rouge&quot;&gt;coap://localhost:5683/&lt;/code&gt; and see the following screen:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;images/play2-californium/copper-screenshot.png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;We can see that Copper used the CoAP resouce discovery mechanism to list all the available resources that our server provides, which is just &lt;code class=&quot;highlighter-rouge&quot;&gt;helloWorld&lt;/code&gt;. We can can proceed by clicking on that resource, entering something in the “Outgoing” textfield in the center of the screen and then click on the PUT icon at the top (we use the PUT method because that is how we have defined our resource handler). The expected result is that whatever you’ve entered into the “Outgoing” field now pops up in the console where you’ve started the Play application:&lt;/p&gt;

&lt;div class=&quot;wide lol highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;[INFO] [02/20/2015 17:12:08] [...] Received CoAP message: 'Success!'
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;deploying-the-application-to-the-raspberry-pi&quot;&gt;Deploying the application to the Raspberry Pi&lt;/h1&gt;

&lt;p&gt;The last step we’ll have to take is to get our application deployed to Raspberry. This is relatively simple if you’ve set it up according to our previous post, “&lt;a href=&quot;/setting-up-a-border-router.html&quot;&gt;&lt;/a&gt;”, because Java comes pre-installed on recent releases of Raspbian.&lt;/p&gt;

&lt;p&gt;To prepare our deployment we run &lt;code class=&quot;highlighter-rouge&quot;&gt;./activator stage&lt;/code&gt;. This will bundle the application inside the &lt;code class=&quot;highlighter-rouge&quot;&gt;target/universal/stage&lt;/code&gt; directory relative to the project’s root. All we have to do then is rsync said directory to the Raspberry and run the application by changing into the &lt;code class=&quot;highlighter-rouge&quot;&gt;stage&lt;/code&gt; directory on the Raspberry and running:&lt;/p&gt;

&lt;div class=&quot;language-bash wide highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;JAVA_OPTS&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;-Xmx64M -Xms16M -XX:PermSize=24M -XX:MaxPermSize=64M&quot;&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    ./bin/play-californium
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p class=&quot;alert alert-warning&quot;&gt;&lt;strong&gt;Note:&lt;/strong&gt; If you’re deploying to a device that has e.g. Java 7 installed, but you built the application with Java 8, running it on the target will fail. To circumvent this, add the following to your &lt;code class=&quot;highlighter-rouge&quot;&gt;build.sbt&lt;/code&gt; if necessary: &lt;code class=&quot;highlighter-rouge&quot;&gt;javacOptions ++= Seq(&quot;-source&quot;, &quot;1.7&quot;, &quot;-target&quot;, &quot;1.7&quot;)&lt;/code&gt;. This sets the Java compiler’s target version to Java 7.&lt;/p&gt;

&lt;p&gt;This starts the Play application, which might take quite a while to spin up since the Raspberry isn’t the fastest of devices. The &lt;code class=&quot;highlighter-rouge&quot;&gt;JAVA_OPTS&lt;/code&gt; that we’re passing limits the amount of memory the JVM uses. If Play has started successfully, it will display the following messags:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;[info] play - Listening for HTTP on /0.0.0.0:9000
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;After that you should be able to test the Californium Server inside Play just as you’ve done locally, by entering the IP of your Raspberry into Firefox with the &lt;code class=&quot;highlighter-rouge&quot;&gt;coap://&lt;/code&gt; protocol prefix.&lt;/p&gt;

&lt;p&gt;An upcoming post will explain how to forward the CoAP messages to the user’s browser through WebSockets and how to process CoAP messages and update a web interface in “realtime” based on the received data.&lt;/p&gt;

</description>
    </item>
    
    
    
    <item>
      <title>Sending <i>small</i> packets</title>
      <link>http://watr.li/what-is-coap.html</link>
      <pubDate>Wed, 18 Feb 2015 00:00:00 +0000</pubDate>
      <author></author>
      <guid>http://watr.li/what-is-coap</guid>
      <description>&lt;p&gt;In order to transfer data in the Internet of Plants, nodes need to know the type of interaction and its exact target: Did my neighbor just ask me for a specific information, or did they send unsolicited information? If so, which resource is this query or information about? Et cetera et cetera.&lt;/p&gt;

&lt;p&gt;We could have defined our own way of communicating this information. We could have specified a suitable JSON-based interface of some sort or put the data into protocol buffers and prayed that they wouldn’t exceed the 81 bytes of payload the teeny-tiny &lt;a href=&quot;http://en.wikipedia.org/wiki/Maximum_transmission_unit&quot;&gt;MTU&lt;/a&gt; of IEEE 802.15.4 leaves us. We probably would have entered a world of pain.&lt;/p&gt;

&lt;p&gt;Luckily, there is a better way of doing this: the &lt;a href=&quot;http://coap.technology&quot;&gt;Constrained Application Protocol (CoAP)&lt;/a&gt;. It operates on the Application Layer and was designed to be a lightweight complement to HTTP. Because of this coupling, CoAP requests can be translated to HTTP requests and a subset of HTTP requests can be translated to CoAP. This is great for nodes that act as border routers (like our &lt;em&gt;display node&lt;/em&gt;) and translate between IoT environments and the “big” internet.&lt;/p&gt;

&lt;!-- more --&gt;

&lt;h1 id=&quot;endpoints-and-resources&quot;&gt;Endpoints and Resources&lt;/h1&gt;

&lt;p&gt;All entities participating in the CoAP protocol are called “endpoints”. For our use case, these participants are the client and the server.&lt;/p&gt;

&lt;p class=&quot;alert alert-info&quot;&gt;&lt;strong&gt;Note:&lt;/strong&gt; Other participants include intermediaries such as proxies which are not discussed here.&lt;/p&gt;

&lt;p&gt;Each endpoint is uniquely identified by a the triplet &lt;code class=&quot;highlighter-rouge&quot;&gt;(IP, Port, Transport Layer Security)&lt;/code&gt;, the latter two being optional, defaulting to &lt;code class=&quot;highlighter-rouge&quot;&gt;5683&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;None&lt;/code&gt; respectively. Every type of information a CoAP endpoint has to offer is called a &lt;em&gt;resource&lt;/em&gt;. These resources are identified by a Unique Resource Identifier (URI), which resembles (but is completely unrelated to) a filesystem path. With endpoint information included, a CoAP URI might look something like this:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;coap://[fe80::c2ff:febc:139c]:1234/foo/bar
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The IPv6 address and port identify the endpoint that provides the &lt;code class=&quot;highlighter-rouge&quot;&gt;foo&lt;/code&gt; resource. &lt;code class=&quot;highlighter-rouge&quot;&gt;bar&lt;/code&gt; is a sub-resource of &lt;code class=&quot;highlighter-rouge&quot;&gt;foo&lt;/code&gt;.&lt;/p&gt;

&lt;p class=&quot;alert alert-info&quot;&gt;&lt;strong&gt;Note:&lt;/strong&gt; Literal IPv6 address in a URI have to be enclosed in &lt;code class=&quot;highlighter-rouge&quot;&gt;[...]&lt;/code&gt; according to &lt;a href=&quot;https://tools.ietf.org/html/rfc2732&quot;&gt;RFC 2732&lt;/a&gt;.&lt;/p&gt;

&lt;h1 id=&quot;request-methods&quot;&gt;Request methods&lt;/h1&gt;

&lt;p&gt;When interacting with a CoAP resource, one of four “request methods” must be specified. The request method identifies the intent with which a resource is being accessed and each method has some inherent properties:&lt;/p&gt;

&lt;p class=&quot;alert alert-info&quot;&gt;&lt;strong&gt;Note:&lt;/strong&gt; A CoAP request is idempotent if you can invoke a request multiple times with the same effect. A request is safe if it does not change any state on the server.&lt;/p&gt;

&lt;table class=&quot;table table-condensed wide&quot;&gt;
    &lt;thead&gt;
        &lt;tr&gt;
            &lt;th&gt;Method&lt;/th&gt;
            &lt;th&gt;Semantics&lt;/th&gt;
            &lt;th&gt;Safe&lt;/th&gt;
            &lt;th&gt;Idempotent&lt;/th&gt;
            &lt;th&gt;Payload&lt;/th&gt;
            &lt;th&gt;Return&amp;nbsp;Codes&lt;/th&gt;
        &lt;/tr&gt;
    &lt;/thead&gt;
    &lt;tbody&gt;
        &lt;tr&gt;
            &lt;td&gt;GET&lt;/td&gt;
            &lt;td&gt;&lt;small&gt;Retrieve the current state of a resource identified by the accessed URI.&lt;/small&gt;&lt;/td&gt;
            &lt;td class=&quot;text-center&quot;&gt;✓&lt;/td&gt;
            &lt;td class=&quot;text-center&quot;&gt;✓&lt;/td&gt;
            &lt;td class=&quot;text-center&quot;&gt;𝗫&lt;/td&gt;
            &lt;td&gt;&lt;small&gt;2.03&amp;nbsp;Valid, 2.05&amp;nbsp;Content&lt;/small&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;POST&lt;/td&gt;
            &lt;td&gt;&lt;small&gt;A generic indicator for the recipient that the enclosed message should be pro&amp;shy;cessed, usually resulting in the creation of a new re&amp;shy;source or the update of the target resource.&lt;/small&gt;&lt;/td&gt;
            &lt;td class=&quot;text-center&quot;&gt;𝗫&lt;/td&gt;
            &lt;td class=&quot;text-center&quot;&gt;𝗫&lt;/td&gt;
            &lt;td class=&quot;text-center&quot;&gt;✓&lt;/td&gt;
            &lt;td&gt;&lt;small&gt;2.01&amp;nbsp;Created, 2.02&amp;nbsp;Deleted, 2.04&amp;nbsp;Changed&lt;/small&gt;&lt;/td&gt;
            
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;PUT&lt;/td&gt;
            &lt;td&gt;&lt;small&gt;Indicates that the target resource should be created or updated.&lt;/small&gt;&lt;/td&gt;
            &lt;td class=&quot;text-center&quot;&gt;𝗫&lt;/td&gt;
            &lt;td class=&quot;text-center&quot;&gt;✓&lt;/td&gt;
            &lt;td class=&quot;text-center&quot;&gt;✓&lt;/td&gt;
            &lt;td&gt;&lt;small&gt;2.01&amp;nbsp;Created, 2.04&amp;nbsp;Changed&lt;/small&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
            &lt;td&gt;DELETE&lt;/td&gt;
            &lt;td&gt;&lt;small&gt;Requests that the target resource should be deleted.&lt;/small&gt;&lt;/td&gt;

            &lt;td class=&quot;text-center&quot;&gt;𝗫&lt;/td&gt;
            &lt;td class=&quot;text-center&quot;&gt;✓&lt;/td&gt;
            &lt;td class=&quot;text-center&quot;&gt;𝗫&lt;/td&gt;
            &lt;td&gt;&lt;small&gt;2.02&amp;nbsp;Deleted&lt;/small&gt;&lt;/td&gt;
            
        &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;

&lt;hr /&gt;

&lt;h1 id=&quot;example&quot;&gt;Example&lt;/h1&gt;

&lt;p&gt;Let’s say we have a CoAP client C and a CoAP server S. Suppose node C wanted to know about the humidity status of the plant node S is watching over. S has the IP &lt;code class=&quot;highlighter-rouge&quot;&gt;fe80::42&lt;/code&gt; and runs a CoAP server which is listening on port &lt;code class=&quot;highlighter-rouge&quot;&gt;1234&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;To retrieve the desired information, C may send the following request (request parameters are specified in &lt;code class=&quot;highlighter-rouge&quot;&gt;Parameter: Value&lt;/code&gt; format in this example):&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;GET coap://[fe80::42]:1234/plant/humidity
Accept: 0
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The &lt;code class=&quot;highlighter-rouge&quot;&gt;Accept&lt;/code&gt; option indicates the desired response format. The value &lt;code class=&quot;highlighter-rouge&quot;&gt;0&lt;/code&gt; stands for &lt;code class=&quot;highlighter-rouge&quot;&gt;text/plain&lt;/code&gt; within the CoAP Content-Formats Registry (&lt;a href=&quot;https://tools.ietf.org/html/rfc7252#section-12.3&quot;&gt;see RFC7252 12.3.&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;S then answers with a &lt;code class=&quot;highlighter-rouge&quot;&gt;2.05 Content&lt;/code&gt; response, which is similar to HTTP’s &lt;code class=&quot;highlighter-rouge&quot;&gt;200 OK&lt;/code&gt;, and the requested value the response’s payload.&lt;/p&gt;

&lt;!-- add picture --&gt;

&lt;h1 id=&quot;implementations&quot;&gt;Implementations&lt;/h1&gt;

&lt;p&gt;Some implementations of the CoAP protocol can be found at  &lt;a href=&quot;http://coap.technology/impls.html&quot;&gt;coap.technology&lt;/a&gt;. For watr.li, we chose to use Californium to handle all things CoAP on our Display nodes, since it provides a nicely architected high-level abstraction over the CoAP protocol, which is exactly what we desired for our relatively powerful display node running a Raspberry Pi (in comparison to the SAM R21 based plant nodes). Since Californium runs inside of the JVM it also integrates nicely with the &lt;a href=&quot;https://www.playframework.com/&quot;&gt;Play framework&lt;/a&gt; which we chose to implement our web interface.&lt;/p&gt;

&lt;p&gt;On our plant nodes, we had the choice between &lt;a href=&quot;https://github.com/1248/microcoap&quot;&gt;microcoap&lt;/a&gt; and &lt;a href=&quot;http://libcoap.sourceforge.net&quot;&gt;libcoap&lt;/a&gt;, as RIOT features both as an &lt;a href=&quot;https://github.com/RIOT-OS/RIOT/tree/master/pkg&quot;&gt;external package&lt;/a&gt;. libcoap is a more monolithic effort which not only sets the CoAP headers and payload in place, but also takes care of dispatching them. microcoap, on the other hand, gives the user a blob of data which they can then dispatch however they see fit. This decreases complexity and removes the need for additional socket-handling threads. This is why we chose to use microcoap on our plant nodes.&lt;/p&gt;

&lt;p&gt;In our next series of posts, we will explain how to create, send and answer CoAP requests with both microcoap and Californium, so keep an eye out for updates!&lt;/p&gt;

&lt;p class=&quot;attribution&quot;&gt;Header image by Flickr user &lt;a href=&quot;https://www.flickr.com/photos/alt-n-anela/6189556902&quot;&gt;ДьюФрейм&lt;/a&gt;. Released under &lt;a href=&quot;https://creativecommons.org/licenses/by-nd/2.0/&quot;&gt;CC BY-ND 2.0&lt;/a&gt;.&lt;/p&gt;

</description>
    </item>
    
    
    
    <item>
      <title>Setting up the Border Router</title>
      <link>http://watr.li/setting-up-a-border-router.html</link>
      <pubDate>Fri, 13 Feb 2015 00:00:00 +0000</pubDate>
      <author></author>
      <guid>http://watr.li/setting-up-a-border-router</guid>
      <description>&lt;p&gt;Providing our office flowers with intelligent equipment to measure humidity and giving them the ability to form a network over IEEE 802.15.4 is all well and good. Unfortunately, this only creates a network amongst office flowers, which is separated from the internet.&lt;/p&gt;

&lt;p&gt;To provide a connection between this network and the Internet, thus enabling Humans™ to know that they should water the plants, we need to setup a border router to evolve the &lt;em&gt;network of plants&lt;/em&gt; to the &lt;em&gt;Internet of Plants&lt;/em&gt;. This post explains how to prepare the border router components, for which we have chosen the Rasperry Pi with 6LoWPAN capabilities provided by the R-Idge USB router.&lt;/p&gt;

&lt;!-- more --&gt;

&lt;h1 id=&quot;installing-raspbian-on-the-raspberry-pi&quot;&gt;Installing Raspbian on the Raspberry Pi&lt;/h1&gt;

&lt;p&gt;First we need to download a recent version of &lt;a href=&quot;http://www.raspbian.org/&quot;&gt;Raspbian&lt;/a&gt;, a Linux distribution specifically made for the Raspberry Pi. This image will be flashed onto an SD Card to serve as the operating system. For this post we used &lt;strong&gt;Rasbian Debian Wheezy, version December 2014&lt;/strong&gt;, which can be downloaded &lt;a href=&quot;http://www.raspberrypi.org/downloads&quot;&gt;here&lt;/a&gt;. After the download finishes we follow the &lt;a href=&quot;http://elinux.org/RPi_Easy_SD_Card_Setup&quot;&gt;comprehensive guide&lt;/a&gt; on how to flash the image to the SD Card published by &lt;a href=&quot;http://elinux.org/RPi_Easy_SD_Card_Setup&quot;&gt;elinux.org&lt;/a&gt;, which covers Windows, OS X and Linux users.&lt;/p&gt;

&lt;p&gt;Now we insert the freshly flashed SD Card into our RasPi, connect a monitor, plug in a keyboard and connect the RasPi to with the Internet using a &lt;em&gt;good old&lt;/em&gt; ethernet cable.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;images/raspi/raspi-config2.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;When booting the Raspberry Pi, you will be presented with an initial configuration screen for basic setup of the operating system similar to the above. This screen includes the “Expand Filesystem” option which gives you read-write access to the entire SD card from within Raspbian. This one should be definitely selected. For a more detailed explanation on all options please check out &lt;a href=&quot;http://elinux.org/RPi_raspi-config&quot;&gt;elinux.org&lt;/a&gt;. After finishing the setup procedure, restarting and logging in, we are finally presented with (or similar):&lt;/p&gt;

&lt;div class=&quot;wide highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Linux raspberrypi 3.12.35+ #730 PREEMPT Fri Dec 19 18:31:24 GMT 2014 armv6l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Mon Jan 26 10:13:52 2015
pi@raspberrypi ~ $
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p class=&quot;alert alert-info&quot;&gt;&lt;strong&gt;Note:&lt;/strong&gt; if you’ve chosen the graphical user interface, open a terminal (i.e. click the “black monitor” icon) to proceed. Of course this only works if you plugged in a mouse or similar. If not, you can hit &lt;code class=&quot;highlighter-rouge&quot;&gt;CTRL+ESC&lt;/code&gt; to navigate through the Menu and choose &lt;code class=&quot;highlighter-rouge&quot;&gt;Accessoirees &amp;gt; Terminal&lt;/code&gt; with the arrow keys and hit enter, which also opens a new terminal window.&lt;/p&gt;

&lt;p&gt;To finish the initial installation, we do an update of Raspbian to get the most recent versions of the installed packages. To do this, we run in a terminal:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;apt-get update &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;apt-get upgrade &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;apt-get dist-upgrade
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p class=&quot;alert alert-danger&quot;&gt;&lt;strong&gt;Warning:&lt;/strong&gt; Running a &lt;code class=&quot;highlighter-rouge&quot;&gt;dist-upgrade&lt;/code&gt; is a potentially destructive operation, so it is &lt;strong&gt;NOT&lt;/strong&gt; recommended if you don’t have a dedicated installation of Raspian for this excercise.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The first line fetches all information for packages and available updates.&lt;/li&gt;
  &lt;li&gt;The second line updates the currently installed packages.&lt;/li&gt;
  &lt;li&gt;The third line installs new and updated packages, including kernel updates.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now we have an up-to-date foundation of Raspbian to start setting up a border router!&lt;/p&gt;

&lt;h1 id=&quot;preparing-the-internet-of-plants&quot;&gt;Preparing the Internet of Plants&lt;/h1&gt;

&lt;p&gt;After the initial installation of Raspbian we need to configure it further to enable the Raspberry Pi to act as a border router. The first thing to be done is to enable IPv6. In the initial configuration of Raspbian only IPv4 handling is activated. We can check this by entering &lt;code class=&quot;highlighter-rouge&quot;&gt;lsmod | grep ipv6&lt;/code&gt; in a terminal. When IPv6 support is not activated, this command returns with no output. To load the IPv6 kernel module we enter &lt;code class=&quot;highlighter-rouge&quot;&gt;sudo modprobe ipv6&lt;/code&gt;, which should return with no output if the loading succeeded. Entering &lt;code class=&quot;highlighter-rouge&quot;&gt;lsmod | grep ipv6&lt;/code&gt; again will present us with:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;ipv6                  316254  20
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;indicating that the module is loaded. To load the module automatically at boot time we enter&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;:bash:
echo ipv6 | sudo tee -a /etc/modules
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;which appends &lt;code class=&quot;highlighter-rouge&quot;&gt;ipv6&lt;/code&gt; as last line to &lt;code class=&quot;highlighter-rouge&quot;&gt;/etc/modules&lt;/code&gt;. The next time we boot, the &lt;code class=&quot;highlighter-rouge&quot;&gt;ipv6&lt;/code&gt; module will be loaded automatically.&lt;/p&gt;

&lt;h1 id=&quot;operating-the-r-idge-usb-router&quot;&gt;Operating the R-Idge USB router&lt;/h1&gt;

&lt;p&gt;To provide connectivity to other IEEE 802.15.4 devices we use the &lt;a href=&quot;http://rosand-tech.com/products/r-idge/prod.html&quot;&gt;R-Idge&lt;/a&gt; 6LoWPAN USB router. After the USB stick is plugged in, it should create a new available network interface called &lt;code class=&quot;highlighter-rouge&quot;&gt;usb0&lt;/code&gt;. We can check this entering &lt;code class=&quot;highlighter-rouge&quot;&gt;ifconfig usb0&lt;/code&gt; which will provide us with information on the interface:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;usb0      Link encap:Ethernet  HWaddr 02:12:4b:e4:0a:83
inet6 addr: fe80::12:4bff:fee4:a83/64 Scope:Link
UP BROADCAST RUNNING MULTICAST  MTU:1280  Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:13 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B)  TX bytes:2018 (1.9 KiB)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Note: if you are presented with (or similar):&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;pi@raspberrypi ~ $ ifconfig usb0
usb0: error fetching interface information: Device not found
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;the interface has probably received a different name from the operating system. You can list all available and active interfaces by entering &lt;code class=&quot;highlighter-rouge&quot;&gt;ifconfig&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;To verify if any of shown network interface is our R-Idge USB router, we enter &lt;code class=&quot;highlighter-rouge&quot;&gt;dmesg -T | tail | grep RNDIS&lt;/code&gt;.&lt;br /&gt;
We will be presented with the following output:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;[Mon Jan 26 12:39:27 2015] rndis_host 1-1.3.4:1.0 usb0: register 'rndis_host' at usb-bcm2708_usb-1.3.4, RNDIS device, 02:12:4b:e4:0a:83
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;We can then compare the shown hardware address (at the far end of the shown line) with the &lt;code class=&quot;highlighter-rouge&quot;&gt;HWaddr&lt;/code&gt; presented in the first line of the entered &lt;code class=&quot;highlighter-rouge&quot;&gt;ifconfig&lt;/code&gt; command. If the addresses match everything is fine and we can move on to configure our R-Idge 6LoWPAN USB router.&lt;/p&gt;

&lt;h2 id=&quot;configuring-the-r-idge-6lowpan-router&quot;&gt;Configuring the R-Idge 6LoWPAN router&lt;/h2&gt;

&lt;p&gt;To configure the router, we need to use the provided &lt;em&gt;Configuration program&lt;/em&gt; from &lt;a href=&quot;http://rosand-tech.com/products/r-idge/doc.html&quot;&gt;Rosand Technologies&lt;/a&gt;. Unfortunately the provided binary/installation packages are not compiled for being used on the Raspbian, so we need to build them from source. For the build we need to install the tools required to build the source by entering&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo apt-get install bison flex wget
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;After &lt;code class=&quot;highlighter-rouge&quot;&gt;bison&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;flex&lt;/code&gt; are installed we can proceed to build the configuration program:&lt;/p&gt;

&lt;div class=&quot;language-bash wide highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;wget http://rosand-tech.com/downloads/cfgtool-1.00.tar.gz &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;tar&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-xvzf&lt;/span&gt; cfgtool-1.00.tar.gz &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;cd &lt;/span&gt;cfgtool-1.00 &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    ./configure &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    make
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;After the build finishes, we create a new directory for the compiled binary (&lt;code class=&quot;highlighter-rouge&quot;&gt;mkdir ../cfgtool-bin&lt;/code&gt;), and copy the relevant files there by entering&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;cp cfgtool ../cfgtool-bin/ &amp;amp;&amp;amp;
    cp cftool.conf ../cfgtool-bin/
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now we change the directory to &lt;code class=&quot;highlighter-rouge&quot;&gt;cd ../cfgtool-bin&lt;/code&gt; and configure our R-Idge USB router. To have a look in the current setup of the R-Idge USB router, we enter&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;./cfgtool &lt;span class=&quot;nt&quot;&gt;-p&lt;/span&gt; ridge &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
          &lt;span class=&quot;nt&quot;&gt;-c&lt;/span&gt; serial &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
          &lt;span class=&quot;nt&quot;&gt;-C&lt;/span&gt; ./cfgtool.conf &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
          &lt;span class=&quot;nt&quot;&gt;-U&lt;/span&gt; channel:r: &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
          &lt;span class=&quot;nt&quot;&gt;-U&lt;/span&gt; power:r: &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
          &lt;span class=&quot;nt&quot;&gt;-U&lt;/span&gt; panid:r: &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
          &lt;span class=&quot;nt&quot;&gt;-U&lt;/span&gt; prefix:r:
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This will present us with the following (or similar):&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;channel = 21
power = 21
panid = 0x3e9
prefix = 3
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The most interesting values here are the &lt;code class=&quot;highlighter-rouge&quot;&gt;channel&lt;/code&gt; and the &lt;code class=&quot;highlighter-rouge&quot;&gt;panid&lt;/code&gt;. These values must both be the same for all  communication participants, i.e. the R-Idge router and any node in the network. To change these values we set the according parameters to write (exchange &lt;code class=&quot;highlighter-rouge&quot;&gt;:r:&lt;/code&gt; with &lt;code class=&quot;highlighter-rouge&quot;&gt;:w:&lt;/code&gt; in the command above) and provide an appropriate value, e.g we set channel to 22 and the panid to 0x123:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;./cfgtool &lt;span class=&quot;nt&quot;&gt;-p&lt;/span&gt; ridge &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
          &lt;span class=&quot;nt&quot;&gt;-c&lt;/span&gt; serial &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
          &lt;span class=&quot;nt&quot;&gt;-C&lt;/span&gt; ./cfgtool.conf &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
          &lt;span class=&quot;nt&quot;&gt;-U&lt;/span&gt; channel:w:22: &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
          &lt;span class=&quot;nt&quot;&gt;-U&lt;/span&gt; panid:w:0x123:
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Which should result in the following output:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;cfgtool: 1 bytes of channel written
cfgtool: verifying channel memory:
cfgtool: reading on-chip channel data:
cfgtool: verifying ...
cfgtool: 1 bytes of channel verified
cfgtool: 2 bytes of panid written
cfgtool: verifying panid memory:
cfgtool: reading on-chip panid data:
cfgtool: verifying ...
cfgtool: 2 bytes of panid verified
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Reading the configuration again (as done above) reveals that the new values are set:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;channel = 22
power = 21
panid = 0x123
prefix = 3
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p class=&quot;alert alert-info&quot;&gt;&lt;strong&gt;Note:&lt;/strong&gt; These values are examples. You need to make sure that whatever you set in the configuration tool for the R-Idge router matches the parameters that you set in your RIOT application and/or other hardware which might want to communicate with the border router.&lt;/p&gt;

&lt;h1 id=&quot;next-steps&quot;&gt;Next steps&lt;/h1&gt;

&lt;p&gt;This concludes the basic setup of the R-Idge router on the Raspberry Pi. Now that we have both the &lt;a href=&quot;/samr21-dev-setup-ubuntu.html&quot;&gt;SAM R21&lt;/a&gt; and the Rasperry Pi set up, the next step is to establish communication between both devices, which will be the topic of an upcoming post. So stay tuned :smile:&lt;/p&gt;
</description>
    </item>
    
    
    
    <item>
      <title>The Atmel SAM R21</title>
      <link>http://watr.li/samr21-dev-setup-ubuntu.html</link>
      <pubDate>Mon, 09 Feb 2015 00:00:00 +0000</pubDate>
      <author></author>
      <guid>http://watr.li/samr21-dev-setup-ubuntu</guid>
      <description>&lt;p&gt;For the internet of plants, we have decided to use the &lt;a href=&quot;http://www.atmel.com/tools/ATSAMR21-XPRO.aspx&quot;&gt;Atmel SAM R21&lt;/a&gt;, a Cortex M0 based platform with an on-board IEEE 802.15.4 wireless module, to monitor our green friends. This post explains the general process of setting up a development environment for RIOT applications on Ubuntu 14.10, taking into account the peculiarities of the SAM R21 board.&lt;/p&gt;

&lt;!-- more --&gt;

&lt;h1 id=&quot;package-requirements&quot;&gt;Package requirements&lt;/h1&gt;

&lt;p&gt;The following packages are needed to build the necessary tools and the RIOT application:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;General: git, pkg-config, autoconf, libtool, unzip&lt;/li&gt;
  &lt;li&gt;OpenOCD: libudev-dev, libusb-1.0-0-dev&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;They can be installed through apt by running&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo apt-get install git pkg-config autoconf \
    libudev-dev libusb-1.0-0-dev libtool unzip \
    valgrind
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In addition it is recommendable to update Ubuntu to the latest version after installing, by invoking&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo apt-get update &amp;amp;&amp;amp;
    sudo apt-get dist-upgrade
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p class=&quot;alert alert-danger&quot;&gt;&lt;strong&gt;Warning:&lt;/strong&gt; Running a &lt;code class=&quot;highlighter-rouge&quot;&gt;dist-upgrade&lt;/code&gt; is a potentially destructive operation, so it is &lt;strong&gt;NOT&lt;/strong&gt; recommended if you don’t have a dedicated installation of Ubuntu 14.10 for this excercise.&lt;/p&gt;

&lt;h1 id=&quot;building-openocd&quot;&gt;Building OpenOCD&lt;/h1&gt;

&lt;p&gt;The Open On-Chip-Debugger (OpenOCD) is used by the RIOT build system for flashing the application onto the board and to debug it. The current release (v0.8.0) of &lt;a href=&quot;http://openocd.sourceforge.net/&quot;&gt;OpenOCD&lt;/a&gt;, however, does not contain configuration files for the SAM R21 board, so it has to be built from source. OpenOCD also requires hidapi, which is not available as a package on Ubuntu 14.10. The following script will clone, build and install hidapi if all goes well:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;TMP&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;$(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;mktemp&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;rm&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-r&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$TMP&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;mkdir&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-p&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$TMP&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;cd&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$TMP&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    git clone http://github.com/signal11/hidapi.git &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;cd &lt;/span&gt;hidapi &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    ./bootstrap &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    ./configure &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    make &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;make &lt;span class=&quot;nb&quot;&gt;install&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;sudo ln&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-s&lt;/span&gt; /usr/local/lib/libhidapi-hidraw.so.0 &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
        /usr/lib/libhidapi-hidraw.so.0
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now that all requirements are installed, OpenOCD can be built:&lt;/p&gt;

&lt;div class=&quot;language-bash wide highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;TMP&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;$(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;mktemp&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;rm&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-r&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$TMP&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;mkdir&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-p&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$TMP&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;cd&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$TMP&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    git clone https://github.com/watr-li/OpenOCD.git openocd &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;cd &lt;/span&gt;openocd &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    ./bootstrap &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    ./configure &lt;span class=&quot;nt&quot;&gt;--enable-maintainer-mode&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
                &lt;span class=&quot;nt&quot;&gt;--enable-cmsis-dap&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
                &lt;span class=&quot;nt&quot;&gt;--enable-hidapi-libusb&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    make &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;make &lt;span class=&quot;nb&quot;&gt;install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;installing-the-toolchain&quot;&gt;Installing the toolchain&lt;/h1&gt;

&lt;p&gt;The 64-bit version of the “&lt;a href=&quot;https://launchpad.net/gcc-arm-embedded&quot;&gt;GNU Tools for ARM Embedded Processors&lt;/a&gt;” toolchain (as recommended in &lt;a href=&quot;https://github.com/RIOT-OS/RIOT/wiki/Board:-Samr21-xpro&quot;&gt;the RIOT wiki&lt;/a&gt;) can be installed via apt using the following script.&lt;/p&gt;

&lt;div class=&quot;wide highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo apt-get remove binutils-arm-none-eabi gcc-arm-none-eabi &amp;amp;&amp;amp;
    sudo add-apt-repository ppa:terry.guo/gcc-arm-embedded &amp;amp;&amp;amp;
    sudo apt-get update &amp;amp;&amp;amp;
    sudo apt-get install gcc-arm-none-eabi=4.9.3.2015q1-0utopic14
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p class=&quot;alert alert-info&quot;&gt;&lt;strong&gt;Note:&lt;/strong&gt; A warning could be displayed that there are conflicting package names with the Debian apt repositories. That warning is already taken into consideration here and you can safely proceed by pressing enter.&lt;/p&gt;

&lt;h1 id=&quot;building-a-riot-example-application&quot;&gt;Building a RIOT example application&lt;/h1&gt;

&lt;p&gt;Now that all the requirements are set up, a RIOT-based application can be built. Cloning RIOT (via &lt;a href=&quot;https://github.com/RIOT-OS/RIOT&quot;&gt;github.com/RIOT&lt;/a&gt;), switching to the directory of the example hello world application and building it is performed by the following script:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git clone https://github.com/RIOT-OS/RIOT.git &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;cd &lt;/span&gt;RIOT/examples/hello-world &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;BOARD&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;samr21-xpro &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    make
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The only non-standard line here is the definition of the &lt;code class=&quot;highlighter-rouge&quot;&gt;BOARD&lt;/code&gt; environment variable which tells the RIOT build system which hardware we are targeting.&lt;/p&gt;

&lt;h1 id=&quot;preparations-for-flashing&quot;&gt;Preparations for flashing&lt;/h1&gt;

&lt;p&gt;In order to be able to flash the application onto the board without root privileges, a couple of additional customizations are necessary. First we need to add our user do the &lt;code class=&quot;highlighter-rouge&quot;&gt;dialout&lt;/code&gt; group by running the following command:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo usermod --append --groups dialout &amp;lt;our username&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This is required in order to capture the output from the board’s serial console, which is mounted as &lt;code class=&quot;highlighter-rouge&quot;&gt;/dev/ttyACM[0-9]+&lt;/code&gt; and belongs to the &lt;code class=&quot;highlighter-rouge&quot;&gt;dialout&lt;/code&gt; group by default.&lt;/p&gt;

&lt;p class=&quot;alert alert-warning&quot;&gt;&lt;strong&gt;Note:&lt;/strong&gt; You need to re-login after adding the user to the group.&lt;/p&gt;

&lt;p&gt;Secondly we need to instruct udev, the device manager, to allow access to the kernel devices created by the hidapi. We do this by creating a new file &lt;code class=&quot;highlighter-rouge&quot;&gt;99-hidraw-permissions.rules&lt;/code&gt; in the &lt;code class=&quot;highlighter-rouge&quot;&gt;/etc/udev/rules.d&lt;/code&gt; directory with the following content:&lt;/p&gt;

&lt;div class=&quot;wide highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;KERNEL==&quot;hidraw*&quot;, SUBSYSTEM==&quot;hidraw&quot;, MODE=&quot;0664&quot;, GROUP=&quot;plugdev&quot;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p class=&quot;alert alert-warning&quot;&gt;&lt;strong&gt;Note:&lt;/strong&gt; After adding the &lt;code class=&quot;highlighter-rouge&quot;&gt;udev&lt;/code&gt; permission you have to re-connect the board for the changes to take effect.&lt;/p&gt;

&lt;h1 id=&quot;flashing-and-running-the-application&quot;&gt;Flashing and running the application&lt;/h1&gt;

&lt;p&gt;The next step is to get the application onto the board, run it and see the output it produces. The RIOT build system is already configured to do all of this for the SAMR board, under the assumption that OpenOCD is installed. For this we need two separate terminals: one where the command to flash the board is invoked and the other where the output from the board is displayed.&lt;/p&gt;

&lt;h3 id=&quot;setting-up-the-output-terminal&quot;&gt;Setting up the output terminal&lt;/h3&gt;

&lt;p&gt;In this terminal we start a &lt;a href=&quot;http://pyterm.sourceforge.net/&quot;&gt;pyterm&lt;/a&gt; instance, a serial port terminal emulator written in Python, listening to the output of the board:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;BOARD&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;samr21-xpro &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    make term
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This should result in the following being printed, after which pyterm waits for output from the board:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;INFO # Connect to serial port /dev/ttyACM0
Welcome to pyterm!
Type '/exit' to exit.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;running-the-flash-command&quot;&gt;Running the flash command&lt;/h3&gt;

&lt;p&gt;Now we can switch to the other terminal window in which we will invoke the commands to flash the application onto the board:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;BOARD&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;samr21-xpro &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    make flash
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p class=&quot;alert alert-warning&quot;&gt;The CMSIS-DAP interface for flashing and debugging &lt;a href=&quot;http://sourceforge.net/p/openocd/mailman/message/32496519/&quot;&gt;is quite slow&lt;/a&gt; (should be around 2KiB/s). So when flashing, you might need to wait a little longer. You can also apply an &lt;a href=&quot;http://openocd.zylin.com/#/c/2356/&quot;&gt;OpenOCD patch&lt;/a&gt; that increases flashing speed by 50-100%.&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;make flash&lt;/code&gt; flashes and subsequently resets the board, causing the application to run. For our hello world example it should result in the following output being shown in the terminal window in which &lt;code class=&quot;highlighter-rouge&quot;&gt;make term&lt;/code&gt; was executed:&lt;/p&gt;

&lt;div class=&quot;wide highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;INFO # kernel_init(): This is RIOT! (Version: 2014.12-285-gfe295)
INFO # kernel_init(): jumping into first task...
INFO # Hello World!
INFO # You are running RIOT on a(n) samr21-xpro board.
INFO # This board features a(n) samd21 MCU.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;bonus-riot-native-mode&quot;&gt;Bonus: RIOT native mode&lt;/h1&gt;

&lt;p&gt;In addition to running the application directly on the target hardware, RIOT also features a target called &lt;code class=&quot;highlighter-rouge&quot;&gt;native&lt;/code&gt;, which runs the application inside the host operating system. This is especially useful when flashing the devices is comparatively slow, as is the case for the SAM R21 board.&lt;/p&gt;

&lt;p&gt;If you want to use native mode, the only thing required is a 32-bit version of libc installed on the system:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo apt-get install libc6-dev-i386
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;After installing this dependency you can then return to the directory of the example hello world application and invoke&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;BOARD&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;native &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    make &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    make term
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;For native mode, the build system creates a 32-bit binary in the &lt;code class=&quot;highlighter-rouge&quot;&gt;bin/native&lt;/code&gt; directory. The only thing &lt;code class=&quot;highlighter-rouge&quot;&gt;make term&lt;/code&gt; then has to do is running that binary. You should see the same output as when running the application on the board, except for the board’s name and the MCU.&lt;/p&gt;

&lt;h1 id=&quot;thats-all-folks&quot;&gt;That’s all, folks!&lt;/h1&gt;

&lt;p&gt;Now that the development environment for RIOT has been set up and applications can be flashed onto the board, you’re ready to develop your first RIOT-based IoT application!&lt;/p&gt;

&lt;p&gt;For more information about RIOT on the SAM R21, please visit the &lt;a href=&quot;https://github.com/RIOT-OS/RIOT/wiki/Board:-Samr21-xpro&quot;&gt;wiki page&lt;/a&gt; for the board in the RIOT repository. If you have any questions on the setup procedure or if anything is not working quite right, please leave a comment!&lt;/p&gt;

&lt;p&gt;This article is based on &lt;a href=&quot;http://karibe.co.ke/2013/08/setting-up-linux-opensource-build-and-debug-tools-for-freescale-freedom-board-frdm-kl25z/&quot;&gt;a great post by David Karibe&lt;/a&gt; on setting up an open-source development toolchain for the Freescale FRDM-KL25Z board.&lt;/p&gt;
</description>
    </item>
    
    
    
    <item>
      <title>Starting a RIOT in the Internet of Plants</title>
      <link>http://watr.li/riot.html</link>
      <pubDate>Thu, 05 Feb 2015 00:00:00 +0000</pubDate>
      <author></author>
      <guid>http://watr.li/riot</guid>
      <description>&lt;p&gt;Battery powered embedded devices such as our plant nodes lack the hardware resources to support common operating systems such as Linux or Windows. In addition, they have very different requirements: our plant nodes do not need a snappy graphical user interface or have to be able to host hundreds of applications simultaenously. What they do need is an operating system that is energy and memory efficient and features low-power wireless connectivity based on open standards.&lt;/p&gt;

&lt;p&gt;Operating Systems such as &lt;a href=&quot;http://www.contiki-os.org/&quot;&gt;Contiki&lt;/a&gt;, &lt;a href=&quot;http://tinyos.net/&quot;&gt;TinyOS&lt;/a&gt; or &lt;a href=&quot;http://riot-os.org/&quot;&gt;RIOT&lt;/a&gt; are designed to operate in the challenging environment of interconnected embedded devices, differing mainly in kernel architecture and the programming models that are employed for application development. This article explains our motivation for choosing RIOT over its alternatives.&lt;/p&gt;

&lt;!-- more --&gt;

&lt;h2 id=&quot;why-we-chose-riot&quot;&gt;Why we chose RIOT.&lt;/h2&gt;

&lt;p&gt;RIOT is an actively maintained Open Source project with a growing, friendly community. It features a network stack based on open standards, namely &lt;a href=&quot;https://tools.ietf.org/html/rfc6282&quot;&gt;6LoWPAN&lt;/a&gt; and IEEE 802.15.4. The latter offers an energy-efficient physical and MAC layer while the former adapts conventional IPv6 to IEEE 802.15.4’s constraints in terms of packet size through fragmentation and header compression (among other techniques). And since RIOT is a microkernel OS, we can specifically include only the features we need, shaving valuable bytes off of our memory footprint.&lt;/p&gt;

&lt;p&gt;Event-based operating systems such as Contiki or TinyOS have adopted a programming model that differs from conventional C applications and only support a subset of the C language (Contiki) or provide a C dialect (TinyOS) for application development. RIOT, in contrast, offers a “traditional” threading and scheduling scheme, POSIX-compliance as well as C and (currently partial) C++ language support. This means that if you’re familiar with standard C, you won’t have to adapt to new coding paradigms to write applications for RIOT and can dive right in. It also makes it possible to port existing code, which was originally written for “traditional”, commodity operating systems, to RIOT with just a few patches, allowing for &lt;a href=&quot;https://github.com/RIOT-OS/RIOT/tree/master/pkg&quot;&gt;the inclusion of existing external libraries&lt;/a&gt; (provided there are no license clashes).&lt;/p&gt;

&lt;p&gt;RIOT’s “native mode” makes it possible to run RIOT applications on a POSIX-compliant operating system such as Linux or OS X for testing and debugging. It is even possible to run multiple instances of RIOT applications on the same host, with communication between them enabled through virtual network devices (i.e. tun/tap). This enables a much faster feedback loop when developing and testing applications, but can prove tricky if constraints of the target hardware are not taken into account when developing primarily in native mode.&lt;/p&gt;

&lt;p&gt;Summing up, RIOT has so far proven to be a great foundation for the development of our plant nodes and we hope to be able to contribute to RIOT’s progress with our efforts on watr.li. Since development on RIOT is an ongoing effort, some development aspects are still a little rough around the edges. A lot of work is still ahead of us, but we are confident that the growing number of &lt;a href=&quot;https://github.com/RIOT-OS/RIOT/graphs/contributors&quot;&gt;awesome contributors&lt;/a&gt; will continue making RIOT a successful open-source option for IoT operating systems.&lt;/p&gt;

&lt;p&gt;Last but not least it is worth mentioning that Snappy Ubuntu Core &lt;a href=&quot;http://www.ubuntu.com/things&quot;&gt;is collaborating with RIOT&lt;/a&gt;, which will come in handy when delivering RIOT-based applications to more homogeneous networks which include nodes with increased computing power and energy resources, for which Snappy may prove to be a better fit.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;In the interest of full disclosure: All four watr.li contributors use RIOT on a more or less regular basis, either at work and/or for university projects. We are all active RIOT contributors.&lt;/em&gt;&lt;/p&gt;
</description>
    </item>
    
    
    
    <item>
      <title>Workshop Prepration</title>
      <link>http://watr.li/workshop.html</link>
      <pubDate>Thu, 29 Jan 2015 00:00:00 +0000</pubDate>
      <author></author>
      <guid>http://watr.li/workshop-preparation</guid>
      <description>&lt;p&gt;For the workshop we will assume that you are familiar with the basics of the following:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Using a linux terminal&lt;/li&gt;
  &lt;li&gt;The C programming language&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;However, first and foremost, we’re here to learn and help each other. You don’t have to know everything in order to be able to participate. If you’re unsure about anything, or feel that you’d like some help, please do not hesitate to ask the RIOT team. We know that it may be a lot to grasp at once, and we’re happy to answer all questions, no matter how trivial they may seem.&lt;/p&gt;

&lt;h1 id=&quot;development-environment&quot;&gt;Development environment&lt;/h1&gt;

&lt;p&gt;RIOT requires you to install and compile some dependencies. We’ve prepared a VMware Virtual Machine which is all set up and ready to go. We will distribute said virtual machine via USB sticks at the beginning of the workshop. To use it, you will need to have VMware installed on your system. Trials are available at &lt;a href=&quot;https://my.vmware.com/web/vmware/downloads&quot;&gt;vmware.com&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In case you prefer to set everyting up yourself, you can follow &lt;a href=&quot;http://watr.li/samr21-dev-setup-ubuntu.html&quot;&gt;this guide&lt;/a&gt; up until (but not including) the section “Building a RIOT example application”.&lt;/p&gt;

&lt;p&gt;RIOT does have experimental Windows support. If you’d prefer to use Windows as your host system, you can consult &lt;a href=&quot;https://github.com/RIOT-OS/RIOT/wiki/Build-RIOT-on-Windows-OS&quot;&gt;this guide&lt;/a&gt;, but it doesn’t cover how to flash an application. However, a word of warning: you probably know much more about your Windows machine than we do, and we might not be able to help you in case you run into trouble.&lt;/p&gt;

&lt;p&gt;We are looking forward to seeing you at the workshop! If there are any preliminary questions about the workshop, feel free to ping us &lt;a href=&quot;http://twitter.com/watr_li&quot;&gt;on Twitter&lt;/a&gt; or drop us an email to &lt;a href=&quot;mailto:xoxo@watr.li&quot;&gt;xoxo@watr.li&lt;/a&gt;.&lt;/p&gt;
</description>
    </item>
    
    
    
    <item>
      <title>Workshop Guide</title>
      <link>http://watr.li/workshop-guide.html</link>
      <pubDate>Thu, 29 Jan 2015 00:00:00 +0000</pubDate>
      <author></author>
      <guid>http://watr.li/workshop-guide</guid>
      <description>&lt;h1 id=&quot;grenoble-riot-workshop-guide&quot;&gt;Grenoble RIOT Workshop Guide&lt;/h1&gt;

&lt;p&gt;For the workshop we will assume that you are familiar with the basics of the following:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Using a linux terminal&lt;/li&gt;
  &lt;li&gt;The C programming language&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;However, first and foremost, we’re here to learn and help each other. You don’t have to know everything in order to be able to participate. If you’re unsure about anything, or feel that you’d like some help, please do not hesitate to ask the RIOT team. We know that it may be a lot to grasp at once, and we’re happy to answer all questions, no matter how trivial they may seem.&lt;/p&gt;

&lt;h1 id=&quot;development-environment&quot;&gt;Development environment&lt;/h1&gt;

&lt;p&gt;RIOT requires you to install and compile some dependencies. We’ve prepared a VMware Virtual Machine which is all set up and ready to go. We will distribute said virtual machine via USB sticks at the beginning of the workshop. To use it, you will need to have VMware installed on your system. Trials are available at &lt;a href=&quot;https://my.vmware.com/web/vmware/downloads&quot;&gt;vmware.com&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In case you prefer to set everyting up yourself, you can follow &lt;a href=&quot;http://watr.li/samr21-dev-setup-ubuntu.html&quot;&gt;this guide&lt;/a&gt; up until (but not including) the section “Building a RIOT example application”.&lt;/p&gt;

&lt;p&gt;RIOT does have experimental Windows support. If you’d prefer to use Windows as your host system, you can consult &lt;a href=&quot;https://github.com/RIOT-OS/RIOT/wiki/Build-RIOT-on-Windows-OS&quot;&gt;this guide&lt;/a&gt;, but it doesn’t cover how to flash an application. However, a word of warning: you probably know much more about your Windows machine than we do, and we might not be able to help you in case you run into trouble.&lt;/p&gt;

&lt;h2 id=&quot;tip-ssh--sshfs-for-your-vm&quot;&gt;Tip: SSH &amp;amp; sshfs for your VM&lt;/h2&gt;

&lt;p&gt;While our VM has a GUI, this can be annoyingly slow. Alternatively, you can use sshfs to mount your VM’s home directory as if it were a regular directory on your host system:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sshfs riot@ip.of.your.vm:/home/riot some_directory/
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;(get your VM’s IP by launching the Terminal application and entering &lt;code class=&quot;highlighter-rouge&quot;&gt;ifconfig eth0&lt;/code&gt;)&lt;/p&gt;

&lt;p&gt;You can then ssh onto your VM and run all make, flash etc commands from your host system’s terminal:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;ssh riot@ip.of.your.vm:/home/riot
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;getting-started-with-riot&quot;&gt;Getting started with RIOT&lt;/h1&gt;

&lt;p&gt;Now that you’re well-prepared, let’s get you started! The goal of this section is to show you how to build and flash a RIOT application.&lt;/p&gt;

&lt;h2 id=&quot;building-a-riot-app&quot;&gt;Building a RIOT app&lt;/h2&gt;

&lt;p&gt;Checking out the RIOT repository work like follows. We’ve used a fork of the main RIOT repository to work around a memory issue on the SAM R21 that has not yet been merged to the RIOT master.&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git clone https://github.com/watr-li/RIOT.git &amp;amp;&amp;amp;
    cd RIOT &amp;amp;&amp;amp;
    git checkout workshop &amp;amp;&amp;amp;
    cd ..
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now that we have checked out the RIOT repository, we can fetch some example applications:&lt;/p&gt;

&lt;div class=&quot;wide highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git clone https://github.com/watr-li/applications.git &amp;amp;&amp;amp;
cd applications &amp;amp;&amp;amp;
git checkout master
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now we’re inside the &lt;code class=&quot;highlighter-rouge&quot;&gt;applications/&lt;/code&gt; folder and we can try to build our first application, the &lt;code class=&quot;highlighter-rouge&quot;&gt;chat&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;cd chat &amp;amp;&amp;amp;
    make all
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;running-it-in-native-mode&quot;&gt;Running it in native mode&lt;/h2&gt;

&lt;p&gt;You can run and test an application on your own computer with the &lt;code class=&quot;highlighter-rouge&quot;&gt;native&lt;/code&gt; mode. The network is emulated through tun/tap devices which are connected through a tapbridge. This bridge has to be created beforehand:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;RIOT/cpu/native/tapsetup.sh create
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now you can start your RIOT application in native mode:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;make term
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In a new terminal, start another RIOT, this time listening on &lt;code class=&quot;highlighter-rouge&quot;&gt;tap1&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;PORT=tap1 make term
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;(Note that &lt;code class=&quot;highlighter-rouge&quot;&gt;make term&lt;/code&gt; only works if you’ve previously built your application. For non-native mode it will try to open up a serial connection to the hardware.)&lt;/p&gt;

&lt;p&gt;Type help to see all commands available in the RIOT shell.&lt;br /&gt;
Use the &lt;code class=&quot;highlighter-rouge&quot;&gt;say&lt;/code&gt; command in one RIOT shell to send a string to the other RIOT instance. If it arrives, you’re ready to go!&lt;/p&gt;

&lt;h2 id=&quot;flashing-it-to-the-samr21&quot;&gt;Flashing it to the SAMR21&lt;/h2&gt;

&lt;p&gt;Attach your SAM R21 board via microUSB. You’ll need two terminals for this: one for flashing and one to view the debug output.&lt;/p&gt;

&lt;h4 id=&quot;setting-up-the-output-terminal&quot;&gt;Setting up the output terminal&lt;/h4&gt;

&lt;p&gt;In this terminal we start a &lt;a href=&quot;http://pyterm.sourceforge.net/&quot;&gt;pyterm&lt;/a&gt; instance, a serial port terminal emulator written in Python, listening to the output of the board:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;BOARD&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;samr21-xpro &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    make term
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This should result in the following being printed, after which pyterm waits for output from the board:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;INFO # Connect to serial port /dev/ttyACM0
Welcome to pyterm!
Type '/exit' to exit.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;running-the-flash-command&quot;&gt;Running the flash command&lt;/h4&gt;

&lt;p&gt;Now we can switch to the other terminal window in which we will invoke the commands to flash the application onto the board:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;BOARD&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;samr21-xpro &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;
    make flash
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p class=&quot;alert alert-warning&quot;&gt;The CMSIS-DAP interface for flashing and debugging &lt;a href=&quot;http://sourceforge.net/p/openocd/mailman/message/32496519/&quot;&gt;is quite slow&lt;/a&gt; (should be around 3-5KiB/s). So when flashing, you might need to wait a little longer. You can also apply an &lt;a href=&quot;http://openocd.zylin.com/#/c/2356/&quot;&gt;OpenOCD patch&lt;/a&gt; that increases flashing speed by 50-100%.&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;make flash&lt;/code&gt; flashes and subsequently resets the board, causing the application to run. For our hello world example it should result in the same output you’ve already seen in the native version of the application.&lt;/p&gt;

&lt;p&gt;You can play around with the application, send messages to the other workshop participants over UDP and see if their messages arrive on your board!&lt;/p&gt;

&lt;h2 id=&quot;adding-your-own-code&quot;&gt;Adding your own code&lt;/h2&gt;

&lt;p&gt;Now that you’re familiar with RIOT, it’s time to add your own code. At the end of this tutorial, you’ll have built a distributed chat application which lets you communicate with the other workshop participants. All chat messages will be sent over CoAP, and the resource the CoAP messages are targeting determines the chat channel you’re in.&lt;/p&gt;

&lt;h3 id=&quot;nick-add-your-own-shell-command&quot;&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;nick&lt;/code&gt;: add your own shell command&lt;/h3&gt;

&lt;p class=&quot;alert alert-info&quot;&gt;&lt;strong&gt;Goal:&lt;/strong&gt; Create a shell command &lt;code class=&quot;highlighter-rouge&quot;&gt;nick &amp;lt;nickname&amp;gt;&lt;/code&gt; which lets you set your nickname.&lt;/p&gt;

&lt;p&gt;RIOT has a shell implementation which can be extended with your own commands. To do this, you’ll have to extend the &lt;code class=&quot;highlighter-rouge&quot;&gt;shell_commands[]&lt;/code&gt; array with your own &lt;code class=&quot;highlighter-rouge&quot;&gt;shell_command_t&lt;/code&gt;, which is defined as follows:&lt;/p&gt;

&lt;div class=&quot;language-c wide highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cm&quot;&gt;/**
 * @brief           A single command in the list of the supported commands.
 * @details         The list of commands is NULL terminated,
 *                  i.e. the last element must be ``{ NULL, NULL, NULL }``.
 */&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;typedef&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;shell_command_t&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;cm&quot;&gt;/**&amp;lt; Name of the function */&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;desc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;cm&quot;&gt;/**&amp;lt; Description to print in the &quot;help&quot; command. */&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;shell_command_handler_t&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;handler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;cm&quot;&gt;/**&amp;lt; The callback function. */&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;shell_command_t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;For your first step towards chatting with RIOT, write a function that lets you set your nickname. Then, add a &lt;code class=&quot;highlighter-rouge&quot;&gt;shell_command_t&lt;/code&gt; which lets you call this function from your RIOT shell with the command &lt;code class=&quot;highlighter-rouge&quot;&gt;nick &amp;lt;nickname&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Re-build your application with &lt;code class=&quot;highlighter-rouge&quot;&gt;make&lt;/code&gt; (in native mode) and try your new shell command by executing the binary with:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;make term
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;say-send-chat-messages&quot;&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;say&lt;/code&gt;: send chat messages&lt;/h3&gt;

&lt;p class=&quot;alert alert-info&quot;&gt;&lt;strong&gt;Goal:&lt;/strong&gt; Create a shell command &lt;code class=&quot;highlighter-rouge&quot;&gt;say &amp;lt;message&amp;gt;&lt;/code&gt; which sends a chat message. The message should be in the payload of a CoAP PUT request directed at the resource &lt;code class=&quot;highlighter-rouge&quot;&gt;chat/default/&lt;/code&gt;. The message should be prepended with your nick.&lt;/p&gt;

&lt;p&gt;Now that you can set your nick name, let’s send some chat messages!&lt;br /&gt;
Again, we’ll need to add a &lt;code class=&quot;highlighter-rouge&quot;&gt;say &amp;lt;message&amp;gt;&lt;/code&gt; command to the shell.&lt;br /&gt;
Each message should be wrapped into a CoAP PUT request. CoAP requests are– just like HTTP requests– directed at a &lt;em&gt;resource&lt;/em&gt;. The default resource for our messages is &lt;code class=&quot;highlighter-rouge&quot;&gt;chat/default/&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In microcoap, resources are represented by the following struct:&lt;/p&gt;

&lt;div class=&quot;language-c highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;typedef&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;elems&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;MAX_SEGMENTS&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;coap_endpoint_path_t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Each element of &lt;code class=&quot;highlighter-rouge&quot;&gt;coap_endpoint_path_t.elems&lt;/code&gt; should be one segment of the path, like so:&lt;/p&gt;

&lt;div class=&quot;wide highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;coap_endpoint_path_t chat_path = {2, {&quot;chat&quot;, &quot;default&quot;}};
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The payload of the PUT request is our chat message. In order to make it identifiable, make sure to prepend it with your nickname, like so:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&quot;my_nick: hello&quot;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Once you’ve created your payload, you can use &lt;code class=&quot;highlighter-rouge&quot;&gt;int coap_ext_build_PUT(uint8_t *buf, size_t *buflen, char *payload, coap_endpoint_path_t *path)&lt;/code&gt; to build your put request. Now, you can use &lt;code class=&quot;highlighter-rouge&quot;&gt;chat_udp_send()&lt;/code&gt; to send the content of &lt;code class=&quot;highlighter-rouge&quot;&gt;buf&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;(For the sake of simplicity, all messages are sent to the link-local all nodes multicast address by &lt;code class=&quot;highlighter-rouge&quot;&gt;chat_udp_send()&lt;/code&gt;)&lt;/p&gt;

&lt;p class=&quot;alert alert-info&quot;&gt;If you want to send messages wich contain spaces, the shell will recognize each word as a single argument, so you can have different values for &lt;code class=&quot;highlighter-rouge&quot;&gt;argc&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;argv&lt;/code&gt;. Bonus points for concatenating them!&lt;/p&gt;

&lt;h3 id=&quot;receive-messages&quot;&gt;Receive messages&lt;/h3&gt;

&lt;p&gt;The base application contains a &lt;code class=&quot;highlighter-rouge&quot;&gt;chat_udp_server_loop()&lt;/code&gt; which receives plain UDP mssages. However, our chat messages aren’t plain text anymore, they’re CoAP packets now. So instead of just printing the contents of &lt;code class=&quot;highlighter-rouge&quot;&gt;buffer_main&lt;/code&gt;, you’ll need to handle these packets properly. We’ll be doing this with microcoap too.&lt;/p&gt;

&lt;p class=&quot;alert alert-info&quot;&gt;For a more detailed explanation of microcoap servers, please visit &lt;a href=&quot;http://watr.li/microcoap-and-ff-copper.html&quot;&gt;this page.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;First, you’ll need to specify an endpoint which specifies for which combinations of request method and resource path a certain callback function should be called. Endpoints are defined as follows:&lt;/p&gt;

&lt;div class=&quot;language-c highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;typedef&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;coap_method_t&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;coap_endpoint_func&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;handler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;coap_endpoint_path_t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;core_attr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;coap_endpoint_t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;All endpoints need to be stored in an array which &lt;strong&gt;must&lt;/strong&gt; be called &lt;code class=&quot;highlighter-rouge&quot;&gt;endpoints&lt;/code&gt; and end with a NULL’ed script. It should look something like this:&lt;/p&gt;

&lt;div class=&quot;language-c wide highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;coap_endpoint_t&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;endpoints&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;COAP_METHOD_GET&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;handle_get_response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;ct=0&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
	&lt;span class=&quot;p&quot;&gt;{(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;coap_method_t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;cm&quot;&gt;/* marks the end of
    	                                  * the endpoints array */&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;But keep in mind that we’re expecting to handle a &lt;code class=&quot;highlighter-rouge&quot;&gt;PUT&lt;/code&gt; request! ;)&lt;br /&gt;
Now you can implement the callback function handling the CoAP packet (which is called &lt;code class=&quot;highlighter-rouge&quot;&gt;handle_get_response&lt;/code&gt; in the above).&lt;br /&gt;
After doing that, you’ll need to teach &lt;code class=&quot;highlighter-rouge&quot;&gt;chat_udp_server_loop&lt;/code&gt; how to understand CoAP messages:&lt;/p&gt;

&lt;div class=&quot;language-c highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rc&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;coap_parse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pkt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;buf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)))&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Bad packet rc=%d&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;checks whether the packet we received is actually a valid CoAP packet.&lt;/p&gt;

&lt;div class=&quot;language-c highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;size_t&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rsplen&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;sizeof&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;buf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;coap_packet_t&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rsppkt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;content:&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;coap_dumpPacket&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pkt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;coap_handle_req&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;scratch_buf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pkt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rsppkt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;After the packet passes this test, it is passed to &lt;code class=&quot;highlighter-rouge&quot;&gt;coap_handle_req()&lt;/code&gt;. If the method and path of the request match one of the method-path combinations we specified in &lt;code class=&quot;highlighter-rouge&quot;&gt;endpoints[]&lt;/code&gt; earlier on, the &lt;code class=&quot;highlighter-rouge&quot;&gt;coap_endpoint_func handler&lt;/code&gt; provided along with them will be called automagically.&lt;/p&gt;

&lt;p&gt;And that’s it! We’ve now successfully received and processed a CoAP request.&lt;/p&gt;

&lt;h3 id=&quot;join-change-channels&quot;&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;join&lt;/code&gt;: change channels&lt;/h3&gt;

&lt;p class=&quot;alert alert-info&quot;&gt;&lt;strong&gt;Goal:&lt;/strong&gt; Create &lt;code class=&quot;highlighter-rouge&quot;&gt;join &amp;lt;channel name&amp;gt;&lt;/code&gt; command that changes the second segment of our resource path. Send chat messages to resources other than &lt;code class=&quot;highlighter-rouge&quot;&gt;chat/default&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Many chat applications have topic-specific channels. Our chat application can do this too: Up until now, we’ve all been sending our messages to &lt;code class=&quot;highlighter-rouge&quot;&gt;chat/default/&lt;/code&gt;. But when we change the resource to, say, &lt;code class=&quot;highlighter-rouge&quot;&gt;chat/IoT/&lt;/code&gt;, we can create a new channel on the fly (to discuss all things IoT, for example).&lt;/p&gt;

&lt;!--- TODO: write *one* handler that outputs chat messages and a shell command that adds a new entry to endpoints[] that calls this handler for your new endpoint--&gt;

&lt;!--
## Tips

### If the board crashes, it will not tell you.
--&gt;

</description>
    </item>
    
    
    
    <item>
      <title>The Internet of Plants: turning your collective black thumb green</title>
      <link>http://watr.li/about/</link>
      <pubDate>Fri, 16 Jan 2015 17:05:58 +0000</pubDate>
      <author></author>
      <guid>http://watr.li/introduction</guid>
      <description>&lt;p&gt;Keeping plants alive in an office without regular hours is hard: Either everybody thinks their colleagues have already watered the plants or multiple people water the same plant, resulting in either drought or overhydration. This can be solved with technology: If each plants’ humidity status is displayed publicly, co-workers can take matters into their own hands without fear of interfering with an absent colleagues’ plant-watering scheme.&lt;/p&gt;

&lt;p&gt;This blog documents our journey towards the realization of such a system, dubbed the Internet of Plants (IoP).&lt;/p&gt;

&lt;!-- more --&gt;

&lt;h2 id=&quot;how-does-it-work-exactly&quot;&gt;How does it work, exactly?&lt;/h2&gt;
&lt;p&gt;To the end user, the IoP consists of two different entities: one sensor node per plant, which is plugged into its flower pot, and a web interface, which is maintained by the so-called display node. The IoP is self-configuring. That means the user won’t have to re-flash their nodes when they change plants, or register each new plant with the IoP. Whenever a new plant is detected in the IoP, the web interface will show a new, blank spot for this plant. Now, the humidity needs and a picture of the plant can be added by the user, and that’s it.&lt;br /&gt;
A plant has three statuses: happy, okay or thirsty. Whenenver a member of the IoP feels thirsty, it will send a tweet and/or E-Mail. After it has been watered, it will tweet and/or E-Mail again to prevent overhydration. Additionally, the status of all plants can be checked through the web interface. This way, users can see that they should water an “okay” plant before a long weekend even though it did not cry for help yet.&lt;/p&gt;

&lt;h2 id=&quot;protocol-stack&quot;&gt;Protocol stack&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://coap.technology&quot;&gt;CoAP&lt;/a&gt; (&lt;a href=&quot;http://libcoap.sourceforge.net&quot;&gt;libcoap&lt;/a&gt; and &lt;a href=&quot;https://eclipse.org/californium/&quot;&gt;Californium&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://tools.ietf.org/html/rfc6550&quot;&gt;RPL&lt;/a&gt;/&lt;a href=&quot;http://tools.ietf.org/html/draft-ietf-manet-aodvv2-06&quot;&gt;AODVv2&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/6LoWPAN&quot;&gt;6LowPAN&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/IEEE_802.15.4&quot;&gt;IEEE 802.15.4&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;hard--and-software&quot;&gt;Hard- and Software&lt;/h2&gt;

&lt;h3 id=&quot;plant-nodes&quot;&gt;Plant nodes&lt;/h3&gt;
&lt;p&gt;For the plant nodes, we chose to use the &lt;a href=&quot;http://www.atmel.com/tools/ATSAMR21-XPRO.aspx&quot;&gt;Atmel SAM R21&lt;/a&gt; boards equipped with a &lt;a href=&quot;http://www.dfrobot.com/index.php?route=product/product&amp;amp;product_id=599&quot;&gt;DFROBOT SEN0114 humidity sensor&lt;/a&gt; because it is robust against oxidation caused by moist soil and said to be suitable for plant-monitoring.&lt;br /&gt;
All plant nodes run &lt;a href=&quot;http://riot-os.org/&quot;&gt;RIOT&lt;/a&gt;, an embedded Operating System designed for the Internet of Things, featuring a network stack running 6LoWPAN over IEEE 802.15.4. Plant nodes will have an application which registers them with the IoP, reads their humidity sensor and reports back to the display node using CoAP.&lt;br /&gt;
The SAM R21 board is somewhat costly, so it might not be ideal for others that don’t happen to have some lying around. However, the beauty of RIOT is that the base code can be re-used: As long as there is a RIOT port for the board you want to use, all it takes is one changed line in the Makefile to deploy the IoP code on it.&lt;/p&gt;

&lt;h3 id=&quot;display-node&quot;&gt;Display node&lt;/h3&gt;
&lt;p&gt;The display node is a &lt;a href=&quot;http://www.raspberrypi.org&quot;&gt;Raspberry Pi&lt;/a&gt;. It manages all plants, collects their humidity statuses and posts changes to the web interface. To accomplish this, it serves as a web server and runs Californuim. All CoAP messages received through Californium are handled and passed to the server if need be.&lt;br /&gt;
The display node also functions as the border router, connecting our Internet of Plants to the “big” internet. To do this, it is equipped with both an Ethernet connection to the internet and a &lt;a href=&quot;http://rosand-tech.com/products/r-idge/prod.html&quot;&gt;R-IDGE 6LoWPAN USB Router&lt;/a&gt; for communication with the plant nodes.&lt;/p&gt;

&lt;h2 id=&quot;code&quot;&gt;Code&lt;/h2&gt;
&lt;p&gt;All of our code can be found &lt;a href=&quot;https://github.com/watr-li&quot;&gt;on github&lt;/a&gt;.&lt;/p&gt;
</description>
    </item>
    
    
    
    <item>
      <title>Impressum</title>
      <link>http://watr.li/impressum/</link>
      <pubDate>Thu, 01 Jan 2015 00:00:00 +0000</pubDate>
      <author></author>
      <guid>http://watr.li/impressum</guid>
      <description>&lt;p&gt;If you’re wondering what this is: German law requires you to provide all of the following information as the owner of a Website. It’s the future!&lt;/p&gt;

&lt;h3 id=&quot;impressum&quot;&gt;Impressum&lt;/h3&gt;
&lt;h4&gt;Angaben gemäß § 5 TMG:&lt;/h4&gt;

&lt;p&gt;Lucas Jenß&lt;br /&gt;
Am Genesungsheim 2&lt;br /&gt;
21527 Kollow, Kurheim&lt;/p&gt;

&lt;h4&gt;Kontakt&lt;/h4&gt;
&lt;p&gt;E-Mail: public [at] x3ro [dot] de&lt;/p&gt;

&lt;h4&gt;Verantwortlich für den Inhalt nach § 55 Abs. 2 RStV:&lt;/h4&gt;

&lt;p&gt;Lucas Jenß&lt;br /&gt;
Am Genesungsheim 2&lt;br /&gt;
21527 Kollow, Kurheim&lt;/p&gt;

&lt;h3&gt;Haftungsausschluss (Disclaimer)&lt;/h3&gt;
&lt;h4&gt;Haftung für Inhalte&lt;/h4&gt;

&lt;p&gt;Als Diensteanbieter sind wir gemäß § 7 Abs.1 TMG für eigene Inhalte auf diesen Seiten nach den allgemeinen Gesetzen verantwortlich. Nach §§ 8 bis 10 TMG sind wir als Diensteanbieter jedoch nicht verpflichtet, übermittelte oder gespeicherte fremde Informationen zu überwachen oder nach Umständen zu forschen, die auf eine rechtswidrige Tätigkeit hinweisen.&lt;/p&gt;

&lt;p&gt;Verpflichtungen zur Entfernung oder Sperrung der Nutzung von Informationen nach den allgemeinen Gesetzen bleiben hiervon unberührt. Eine diesbezügliche Haftung ist jedoch erst ab dem Zeitpunkt der Kenntnis einer konkreten Rechtsverletzung möglich. Bei Bekanntwerden von entsprechenden Rechtsverletzungen werden wir diese Inhalte umgehend entfernen.&lt;/p&gt;

&lt;h4&gt;Haftung für Links&lt;/h4&gt;
&lt;p&gt;Unser Angebot enthält Links zu externen Webseiten Dritter, auf deren Inhalte wir keinen Einfluss haben. Deshalb können wir für diese fremden Inhalte auch keine Gewähr übernehmen. Für die Inhalte der verlinkten Seiten ist stets der jeweilige Anbieter oder Betreiber der Seiten verantwortlich. Die verlinkten Seiten wurden zum Zeitpunkt der Verlinkung auf mögliche Rechtsverstöße überprüft. Rechtswidrige Inhalte waren zum Zeitpunkt der Verlinkung nicht erkennbar.&lt;/p&gt;

&lt;p&gt;Eine permanente inhaltliche Kontrolle der verlinkten Seiten ist jedoch ohne konkrete Anhaltspunkte einer Rechtsverletzung nicht zumutbar. Bei Bekanntwerden von Rechtsverletzungen werden wir derartige Links umgehend entfernen.&lt;/p&gt;

&lt;h4&gt;Urheberrecht&lt;/h4&gt;
&lt;p&gt;Die durch die Seitenbetreiber erstellten Inhalte und Werke auf diesen Seiten unterliegen dem deutschen Urheberrecht. Die Vervielfältigung, Bearbeitung, Verbreitung und jede Art der Verwertung außerhalb der Grenzen des Urheberrechtes bedürfen der schriftlichen Zustimmung des jeweiligen Autors bzw. Erstellers. Downloads und Kopien dieser Seite sind nur für den privaten, nicht kommerziellen Gebrauch gestattet.&lt;/p&gt;

&lt;p&gt;Soweit die Inhalte auf dieser Seite nicht vom Betreiber erstellt wurden, werden die Urheberrechte Dritter beachtet. Insbesondere werden Inhalte Dritter als solche gekennzeichnet. Sollten Sie trotzdem auf eine Urheberrechtsverletzung aufmerksam werden, bitten wir um einen entsprechenden Hinweis. Bei Bekanntwerden von Rechtsverletzungen werden wir derartige Inhalte umgehend entfernen.&lt;/p&gt;

&lt;h3 id=&quot;datenschutz&quot;&gt;Datenschutz&lt;/h3&gt;
&lt;p&gt;Die Betreiber dieser Seiten nehmen den Schutz Ihrer persönlichen Daten sehr ernst. Wir behandeln Ihre personenbezogenen Daten vertraulich und entsprechend der gesetzlichen Datenschutzvorschriften sowie dieser Datenschutzerklärung.&lt;/p&gt;
&lt;p&gt;Die Nutzung unserer Webseite ist in der Regel ohne Angabe personenbezogener Daten möglich. Soweit auf unseren Seiten personenbezogene Daten (beispielsweise Name, Anschrift oder E-Mail-Adressen) erhoben werden, erfolgt dies, soweit möglich, stets auf freiwilliger Basis. Diese Daten werden ohne Ihre ausdrückliche Zustimmung nicht an Dritte weitergegeben.&lt;/p&gt;
&lt;p&gt;Wir weisen darauf hin, dass die Datenübertragung im Internet (z.B. bei der Kommunikation per E-Mail) Sicherheitslücken aufweisen kann. Ein lückenloser Schutz der Daten vor dem Zugriff durch Dritte ist nicht möglich.&lt;/p&gt;

&lt;h4&gt;Server-Log-Files&lt;/h4&gt;
&lt;p&gt;Der Provider der Seiten erhebt und speichert automatisch Informationen in so genannten Server-Log Files, die Ihr Browser automatisch an uns übermittelt. Dies sind:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Browsertyp/ Browserversion&lt;/li&gt;
&lt;li&gt;verwendetes Betriebssystem&lt;/li&gt;
&lt;li&gt;Referrer URL&lt;/li&gt;
&lt;li&gt;Hostname des zugreifenden Rechners&lt;/li&gt;
&lt;li&gt;Uhrzeit der Serveranfrage&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Diese Daten sind nicht bestimmten Personen zuordenbar. Eine Zusammenführung dieser Daten mit anderen Datenquellen wird nicht vorgenommen. Wir behalten uns vor, diese Daten nachträglich zu prüfen, wenn uns konkrete Anhaltspunkte für eine rechtswidrige Nutzung bekannt werden.&lt;/p&gt;

&lt;h4&gt;Einbindung von Diensten und Inhalten Dritter&lt;/h4&gt;
&lt;p&gt;Es kann vorkommen, dass innerhalb dieses Onlineangebotes Inhalte Dritter, wie zum Beispiel Videos von YouTube, Kartenmaterial von Google-Maps, RSS-Feeds oder Grafiken von anderen Webseiten eingebunden werden. Dies setzt immer voraus, dass die Anbieter dieser Inhalte (nachfolgend bezeichnet als &quot;Dritt-Anbieter&quot;) die IP-Adresse der Nutzer wahr nehmen. Denn ohne die IP-Adresse, könnten sie die Inhalte nicht an den Browser des jeweiligen Nutzers senden. Die IP-Adresse ist damit für die Darstellung dieser Inhalte erforderlich. Wir bemühen uns nur solche Inhalte zu verwenden, deren jeweilige Anbieter die IP-Adresse lediglich zur Auslieferung der Inhalte verwenden. Jedoch  haben wir keinen Einfluss darauf, falls die Dritt-Anbieter die IP-Adresse z.B. für statistische Zwecke speichern. Soweit dies uns bekannt ist, klären wir die Nutzer darüber auf.&lt;/p&gt;

&lt;h4&gt;Auskunft, Löschung, Sperrung&lt;/h4&gt;
&lt;p&gt;Sie haben jederzeit das Recht auf unentgeltliche Auskunft über Ihre gespeicherten personenbezogenen Daten, deren Herkunft und Empfänger und den Zweck der Datenverarbeitung sowie ein Recht auf Berichtigung, Sperrung oder Löschung dieser Daten. Hierzu sowie zu weiteren Fragen zum Thema personenbezogene Daten können Sie sich jederzeit an die oben genannte E-Mail Adresse wenden.&lt;/p&gt;
</description>
    </item>
    
    

  </channel> 
</rss>