<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Seeking Clarity</title>
    <link>http://dayooliyide.com/</link>
    <description>Recent content on Seeking Clarity</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-gb</language>
    <copyright>All rights reserved - 2016</copyright>
    <lastBuildDate>Tue, 05 Jul 2016 15:09:52 +0100</lastBuildDate>
    <atom:link href="http://dayooliyide.com/index.xml" rel="self" type="application/rss+xml" />
    
    <item>
      <title>Consuming Kafka&#39;s internal consumer offsets topic</title>
      <link>http://dayooliyide.com/post/kafka-consumer-offsets-topic/</link>
      <pubDate>Tue, 05 Jul 2016 15:09:52 +0100</pubDate>
      
      <guid>http://dayooliyide.com/post/kafka-consumer-offsets-topic/</guid>
      <description>

&lt;p&gt;Since version 0.8.2, kafka has had the ability to store consumer offsets in an
internal compacted topic called &lt;code&gt;__consumer_offsets&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If you are interested in viewing the consumer offsets stored on the
&lt;code&gt;__consumer_offsets&lt;/code&gt;, you should do the following.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a small config with the &lt;code&gt;exclude.internal.topics&lt;/code&gt; property set to false&lt;/li&gt;
&lt;li&gt;Use the OffsetsMessageFormatter class as the formatter

&lt;ul&gt;
&lt;li&gt;For Kafka 0.8.2.x, it is &lt;code&gt;kafka.server.OffsetManager\$OffsetsMessageFormatter&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;For Kafka 0.9.x.x and 0.10.0.0, it is &lt;code&gt;kafka.coordinator.GroupMetadataManager\$OffsetsMessageFormatter&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/li&gt;
&lt;li&gt;If you want to consume all consumer offsets from the beginning as opposed to just the
latest, you&amp;rsquo;ll need to add &lt;code&gt;--from-beginning&lt;/code&gt; flag to the &lt;code&gt;kafka-console-consumer.sh&lt;/code&gt; script&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For Kafka 0.8.2.x&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;bash&#34;&gt;#Create consumer config
echo &#34;exclude.internal.topics=false&#34; &gt; /tmp/consumer.config
#Only consume the latest consumer offsets
./kafka-console-consumer.sh --consumer.config /tmp/consumer.config \
--formatter &#34;kafka.server.OffsetManager\$OffsetsMessageFormatter&#34; \
--zookeeper localhost:2181 --topic __consumer_offsets

&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;For Kafka 0.9.x.x and 0.10.0.0&lt;/p&gt;

&lt;pre&gt;&lt;code class=&#34;bash&#34;&gt;#Create consumer config
echo &#34;exclude.internal.topics=false&#34; &gt; /tmp/consumer.config
#Only consume the latest consumer offsets
./kafka-console-consumer.sh --consumer.config /tmp/consumer.config \
--formatter &#34;kafka.coordinator.GroupMetadataManager\$OffsetsMessageFormatter&#34; \
--zookeeper localhost:2181 --topic __consumer_offsets

&lt;/code&gt;&lt;/pre&gt;

&lt;h3 id=&#34;notes:789d2f6f6c01457940bf459622e3cb03&#34;&gt;Notes&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;From version 0.8.2, the old consumers will by default commit their offsets to zookeeper.
This can be changed to storing on the &lt;code&gt;__consumer_offsets&lt;/code&gt; topic by setting the consumer config
property &lt;code&gt;offsets.storage=kafka&lt;/code&gt;.
The new consumers commit their offsets to the &lt;code&gt;__consumer_offsets&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;For Kafka 0.9.x.x and above, you might notice that you&amp;rsquo;ve consumed more messages, from
&lt;code&gt;__consumer_offsets&lt;/code&gt; topic, than were displayed. This is because the formatter has been changed to only work on Offset messages&lt;/li&gt;
&lt;/ul&gt;
</description>
    </item>
    
    <item>
      <title>Using Clojure with Arduino - Part1</title>
      <link>http://dayooliyide.com/post/clojure-arduino-part1/</link>
      <pubDate>Thu, 16 Jun 2016 12:08:52 +0100</pubDate>
      
      <guid>http://dayooliyide.com/post/clojure-arduino-part1/</guid>
      <description>

&lt;p&gt;This is the first part of a series of posts, where I explore and create various Arduino projects using
Clojure as the main programming language.&lt;/p&gt;

&lt;p&gt;This post will guide you through being able to connect to an Arduino board (uno), using
Clojure to sends commands to to it and finally using the Arduino&amp;rsquo;s LED as a morse code
transmitter.&lt;/p&gt;

&lt;h2 id=&#34;requirements:63f754f3e8a08c9d0f1e05cdc34c3d1b&#34;&gt;Requirements&lt;/h2&gt;

&lt;h3 id=&#34;hardware:63f754f3e8a08c9d0f1e05cdc34c3d1b&#34;&gt;Hardware&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://www.amazon.co.uk/dp/B00PHY3HH2&#34;&gt;Arduino Uno&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;USB cable (male to female)&lt;/li&gt;
&lt;li&gt;Your computer&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&#34;software:63f754f3e8a08c9d0f1e05cdc34c3d1b&#34;&gt;Software&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://www.arduino.cc/en/Main/Software&#34;&gt;Arduino IDE&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html&#34;&gt;Java 8&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;http://leiningen.org&#34;&gt;Leiningen&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&#34;background-knowledge:63f754f3e8a08c9d0f1e05cdc34c3d1b&#34;&gt;Background Knowledge&lt;/h2&gt;

&lt;p&gt;After installing &lt;a href=&#34;https://www.arduino.cc/en/Guide/HomePage&#34;&gt;Arduino IDE&lt;/a&gt;, &lt;a href=&#34;http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html&#34;&gt;Java 8&lt;/a&gt; and &lt;a href=&#34;http://leiningen.org&#34;&gt;Leiningen&lt;/a&gt; on your computer, your computer should be ready.
But before we proceed there are a few important concepts that should be understood.&lt;/p&gt;

&lt;h3 id=&#34;serial-ports:63f754f3e8a08c9d0f1e05cdc34c3d1b&#34;&gt;Serial Ports&lt;/h3&gt;

&lt;p&gt;The Arduino Uno board uses digital pins 0 and 1 for direct communication, it is possible to
communicate with the these pins via a USB to Serial chip on the Arduino board.
Thus when the Arduino board is connected via USB to a computer, it appears as serial port.&lt;/p&gt;

&lt;p&gt;When the board is connected to your computer it will appear as serial device, and all the
communication (uploading sketches or sending firmata commands) will be carried out using
serial communication&lt;/p&gt;

&lt;h3 id=&#34;firmata:63f754f3e8a08c9d0f1e05cdc34c3d1b&#34;&gt;Firmata&lt;/h3&gt;

&lt;p&gt;When staring up, the Arduino board runs a program (stored in it&amp;rsquo;s flash memory) called the bootloader.
The bootloader carries out the following actions in the given order -&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Check to see if another program (e.g sketch) is being uploaded, if so, write the
uploaded program into lower part of the flash memory.&lt;/li&gt;
&lt;li&gt;Run and pass control over to whatever program is stored in the lower part of the flash memory&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When using the Arduino IDE to upload a program to Arduino, a reset signal is sent to the board.
This triggers the bootloader to run. As per the above actions, the bootloader
then notices that the IDE is attempting to upload a sketch/program, it accepts the sketch and stores
the sketch/program in the lower part of the flash memory and runs it.
&lt;em&gt;Note: There&amp;rsquo;s a reset button on the Arduino board that can also be used to reset the board.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://github.com/firmata/protocol&#34;&gt;Firmata&lt;/a&gt;&lt;/strong&gt; is a communication protocol. It allows you to
send commands (and get responses) to a microcontroller.
Arduino IDE comes with sketches/programs that implement the Firmata protocol.
These programs are written in C++ and are under the &lt;code&gt;File -&amp;gt; Examples -&amp;gt; Firmata&lt;/code&gt; Menu in the
Arduino IDE.  Some of these Firmata sketches implement Firmata protocol over different
physical interfaces (e.g StandardFirmataWifi communicates vi a Wifi shield).&lt;/p&gt;

&lt;p&gt;For what we are doing, the most important concept to understand is that a Firmata
sketch/program is a continously running program that the Arduino bootloader will load/run.
Once running, it will execute commands sent via the Firmata protocol and send responses
via the Firmata protocol.&lt;/p&gt;

&lt;h2 id=&#34;connect-your-board:63f754f3e8a08c9d0f1e05cdc34c3d1b&#34;&gt;Connect your board&lt;/h2&gt;

&lt;p&gt;Connect and setup your board by following the appropriate OS guide below&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://www.arduino.cc/en/Guide/Windows&#34;&gt;Windows Setup Guide&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.arduino.cc/en/Guide/MacOSX&#34;&gt;Mac Os X Setup Guide&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.arduino.cc/en/Guide/Linux&#34;&gt;Linux Setup Guide&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you are having problems connecting to your Arduino board please consult one of
the following links&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://www.arduino.cc/en/Guide/Troubleshooting&#34;&gt;General Trouble Shooting Guide&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;If you have problems accessing the device file in Linux, consult this &lt;a href=&#34;http://playground.arduino.cc/Linux/All&#34;&gt;page&lt;/a&gt; (especially the &amp;ldquo;Serial port permissions&amp;rdquo; section)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&#34;communicating-via-the-repl:63f754f3e8a08c9d0f1e05cdc34c3d1b&#34;&gt;Communicating via the REPL&lt;/h2&gt;

&lt;p&gt;To communicate with the Arduino board from a Clojure REPL, we&amp;rsquo;ll need to have a program
constantly running on the board which will interpret Firmata commands/requests from a
Firmata client.&lt;/p&gt;

&lt;h3 id=&#34;upload-the-firmata-sketch-onto-the-arduino-board:63f754f3e8a08c9d0f1e05cdc34c3d1b&#34;&gt;Upload the Firmata Sketch onto the Arduino Board&lt;/h3&gt;

&lt;p&gt;After connecting the board to your computer,
We&amp;rsquo;ll upload the Firmata sketch/program onto the Arduino board, by first selecting
the &lt;code&gt;File -&amp;gt; Examples -&amp;gt; Firmata -&amp;gt; StandardFirmata&lt;/code&gt; Menu Item in the Arduino IDE.

&lt;figure &gt;
    
        &lt;img src=&#34;http://dayooliyide.com/img/clojure-arduino-part1/StandardFirmataMenuItem.jpg&#34; /&gt;
    
    
&lt;/figure&gt;
&lt;/p&gt;

&lt;p&gt;Check the Menu items &lt;code&gt;Tools -&amp;gt; board&lt;/code&gt; and &lt;code&gt;Tools -&amp;gt; port&lt;/code&gt; to ensure that the correct
Arduino board and device file have been selected.

&lt;figure &gt;
    
        &lt;img src=&#34;http://dayooliyide.com/img/clojure-arduino-part1/PortBoardMenuItem.jpg&#34; /&gt;
    
    
&lt;/figure&gt;
&lt;/p&gt;

&lt;p&gt;Now Upload the Firmata sketch by selecting &lt;code&gt;Sketch -&amp;gt; Upload&lt;/code&gt; menu item.
You should see Tx and Rx leds blinking on the board, but more importantly the Arduino IDE&amp;rsquo;s
status bar will show the progress and then the message &lt;code&gt;Done uploading&lt;/code&gt; when the sketch
has been successfully uploaded.&lt;/p&gt;

&lt;h3 id=&#34;use-a-clojure-firmata-client-library:63f754f3e8a08c9d0f1e05cdc34c3d1b&#34;&gt;Use a Clojure Firmata Client library&lt;/h3&gt;

&lt;p&gt;The client library we&amp;rsquo;ll be using is &lt;a href=&#34;https://github.com/peterschwarz/clj-firmata&#34;&gt;clj-firmata&lt;/a&gt;.
Create a new project using leiningen e.g
&lt;pre&gt;&lt;code class=&#34;bash&#34;&gt;lein new sandpit &lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;Enter the newly created directory (sandpit) and edit the project.clj to include the
clj-firmata library.
&lt;pre&gt;&lt;code class=&#34;clojure&#34;&gt; (defproject sandpit &amp;ldquo;0.1.0-SNAPSHOT&amp;rdquo;
  :description &amp;ldquo;FIXME: write description&amp;rdquo;
  :url &amp;ldquo;&lt;a href=&#34;http://example.com/FIXME&amp;quot;&#34;&gt;http://example.com/FIXME&amp;quot;&lt;/a&gt;
  :license {:name &amp;ldquo;Eclipse Public License&amp;rdquo;
            :url &amp;ldquo;&lt;a href=&#34;http://www.eclipse.org/legal/epl-v10.html&amp;quot;}&#34;&gt;http://www.eclipse.org/legal/epl-v10.html&amp;quot;}&lt;/a&gt;
  :dependencies [[org.clojure/clojure &amp;ldquo;1.7.0&amp;rdquo;]
                 [clj-firmata &amp;ldquo;2.1.1&amp;rdquo;]])
&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;Now start up a repl
&lt;pre&gt;&lt;code class=&#34;bash&#34;&gt;lein repl&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;Require the firmata.core namespace from the clj-firmata library
&lt;pre&gt;&lt;code class=&#34;clojure-repl&#34;&gt;user=&amp;gt; (require &amp;lsquo;[firmata.core :as fm])
nil
&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;Please note the following -&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Whenever you use the clj-firmata library to communicate with the board,
you&amp;rsquo;ll notice the TX and RX LEDs blink as the instructions are sent via
the firmata protocol to Firmata sketch/program running on the board.&lt;/li&gt;
&lt;li&gt;The RX LED is associated to PIN 0&lt;/li&gt;
&lt;li&gt;The TX LED is associated to PIN 1&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now open a connection to your Arduino board and hold a reference to it.
&lt;em&gt;Note: this reference is actually a clojure map&lt;/em&gt;
&lt;pre&gt;&lt;code class=&#34;clojure-repl&#34;&gt;user=&amp;gt; (def board (fm/open-serial-board :auto-detect))
#&amp;lsquo;user/board
&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;Arduino Uno&amp;rsquo;s board has a LED associated to PIN 13. We are going to switch this LED
on and off. But before we proceed, we need to ensure that this PIN&amp;rsquo;s mode is set to
output
&lt;pre&gt;&lt;code class=&#34;clojure-repl&#34;&gt;user=&amp;gt; (fm/set-pin-mode board 13 :output)
&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;The above expression will return the board (a clojure map) that was given to it.
&lt;em&gt;Note: the following expressions will return the board that they are given,
for now you can ignore it&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;We&amp;rsquo;ll now switch the LED associated with PIN 13 on, by setting that pin&amp;rsquo;s digital value
to high
&lt;pre&gt;&lt;code class=&#34;clojure-repl&#34;&gt;user=&amp;gt; (fm/set-digital board 13 :high)
&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;Then switch it off, by setting the pin&amp;rsquo;s digital value to low
&lt;pre&gt;&lt;code class=&#34;clojure-repl&#34;&gt;user=&amp;gt; (fm/set-digital board 13 :low)
&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;Congratulations!! you are now able to send instructions from a clojure repl and
have them executed on the Arduino Board.&lt;/p&gt;

&lt;h3 id=&#34;using-the-arduino-board-as-a-basic-morse-code-signaller:63f754f3e8a08c9d0f1e05cdc34c3d1b&#34;&gt;Using the Arduino Board as a basic Morse Code Signaller&lt;/h3&gt;

&lt;p&gt;What we&amp;rsquo;ve done so far is pretty basic stuff, we can now build on it to do more.&lt;/p&gt;

&lt;p&gt;&lt;a href=&#34;https://en.wikipedia.org/wiki/Morse_code&#34;&gt;Morse code&lt;/a&gt; is a way of translating
characters (letters, numbers) into a series of signals (tones, clicks or flashing lights).&lt;/p&gt;

&lt;p&gt;By switching the LED attached to PIN 13 on and off, we can create a simple Morse Code
signaller.&lt;/p&gt;

&lt;p&gt;I&amp;rsquo;ve created a small &lt;a href=&#34;https://github.com/DayoOliyide/morse-code&#34;&gt;clojure library&lt;/a&gt; for &amp;ldquo;blinking&amp;rdquo; the onboard LED (PIN 13) and for
translating characters (letters and numbers) and words into Morse code.&lt;/p&gt;

&lt;p&gt;First thing to do is to replace the clj-firmata entry, in the project.clj, with an entry
for the &lt;a href=&#34;https://github.com/DayoOliyide/morse-code&#34;&gt;morse code library&lt;/a&gt;.
&lt;pre&gt;&lt;code class=&#34;clojure&#34;&gt; (defproject sandpit &amp;ldquo;0.1.0-SNAPSHOT&amp;rdquo;
  :description &amp;ldquo;FIXME: write description&amp;rdquo;
  :url &amp;ldquo;&lt;a href=&#34;http://example.com/FIXME&amp;quot;&#34;&gt;http://example.com/FIXME&amp;quot;&lt;/a&gt;
  :license {:name &amp;ldquo;Eclipse Public License&amp;rdquo;
            :url &amp;ldquo;&lt;a href=&#34;http://www.eclipse.org/legal/epl-v10.html&amp;quot;}&#34;&gt;http://www.eclipse.org/legal/epl-v10.html&amp;quot;}&lt;/a&gt;
  :dependencies [[org.clojure/clojure &amp;ldquo;1.7.0&amp;rdquo;]
                [com.dayooliyide/morse-code &amp;ldquo;0.1.0&amp;rdquo;]])
&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;Now restart the repl and use the morse-code.core namespace
&lt;pre&gt;&lt;code class=&#34;clojure-repl&#34;&gt;user=&amp;gt; (use &amp;lsquo;morse-code.core)
nil
&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;Initialise the connection to the board.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Please note the following&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Note: if not done, the first use of the api will trigger the initialisation of a connection
to the board which causes some blinking of the onboard led. This might lead to some confusion
hence the reason to initialise the board before using the other functions&lt;/p&gt;&lt;/li&gt;

&lt;li&gt;&lt;p&gt;Note: calling the init-board! fn will return a clojure map representation of the board and
the connection to it&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;&lt;code class=&#34;clojure-repl&#34;&gt;user=&gt; (init-board!)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now you can blink/flash the onboard LED for 1 second and then 5 seconds
&lt;pre&gt;&lt;code class=&#34;clojure-repl&#34;&gt;user=&amp;gt; (blink! 1000)
nil
user=&amp;gt; (blink! 5000)
nil
&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;You can flash the LED to represent a Morse dot (200 millis) or a dash (600 millis)
&lt;pre&gt;&lt;code class=&#34;clojure-repl&#34;&gt;user=&amp;gt; (dot!)
nil
user=&amp;gt; (dash!)
nil
&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;You can also transmit words
&lt;pre&gt;&lt;code class=&#34;clojure-repl&#34;&gt;user=&amp;gt; (morse! &amp;ldquo;SOS&amp;rdquo;)
nil
&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;And also words
&lt;pre&gt;&lt;code class=&#34;clojure-repl&#34;&gt;user=&amp;gt; (morse! &amp;ldquo;Hello World&amp;rdquo;)
nil
&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;

&lt;p&gt;Which brings us to the end of this post, I hope you have found it useful.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>About</title>
      <link>http://dayooliyide.com/about/</link>
      <pubDate>Tue, 10 May 2016 14:16:40 +0100</pubDate>
      
      <guid>http://dayooliyide.com/about/</guid>
      <description>

&lt;h2 id=&#34;about-me:6083a88ee3411b0d17ce02d738f69d47&#34;&gt;About Me&lt;/h2&gt;

&lt;p&gt;Todo :)&lt;/p&gt;

&lt;h2 id=&#34;about-this-blog:6083a88ee3411b0d17ce02d738f69d47&#34;&gt;About this blog&lt;/h2&gt;

&lt;p&gt;This blog is about me sharing some of the knowledge and tips that I&amp;rsquo;ve acquired.&lt;br /&gt;
I hope you find it of use.&lt;/p&gt;
</description>
    </item>
    
  </channel>
</rss>