Functional Programming with IOT (FIOT) – Day 3

Well the direct compilation of the code didn’t work. I had to do some tweaks to make it work which included copying the librxtxSerial.jnilib from target to /Library/Java/Extensions.

$ cp $PROJECT_HOME/firmata-test/target/native/macosx/x86_64/librxtxSerial.jnilib /Library/Java/Extensions/

After fixing that issue the project was running with the following warning.

WARNING: RXTX Version mismatch
Jar version = RXTX-2.2pre2
native lib Version = RXTX-2.2pre3

I will add the full source code and the method to run it in my next post. I spent alot of time today just debugging the issue.

Functional Programming with IOT (FIOT) – Day 2

Today is the day 2 of the FIOT, as discussed in the previous post i shall be exploring the ESP8266 with a mainstream software engineering functional programming(FP) language.

In my current employment, we work in Clojure due to the language’s pureness and immutability. There is a discussion on StackOverflow that you can follow to read more about it being “probably the closest” to functional.

Following is the picture of the hardware i have chosen for this experiment.

ESP8266 Programming Kit
ESP8266 Programming Kit

At this stage, we have a set hardware and programming language, now we need some sort of IDE to convert our code into binary right?

Wrong, it is not that simple.

Unfortunately, Clojure cannot be directly compiled into binary at this stage. So we would have to use an intermediate bridge to communicate with the hardware. This is where Firmata comes to the rescue. The concept is that your hardware will run a Firmata protocol server and you will use a client library to instruct the hardware to do the job. It is not ideal but it is one step forward then not using a functional programming language at all.

The Firmata protocol is based on the midi message format but fortunately, we don’t have to learn what they are as the client libraries are a good wrapper. Since we have picked Clojure we have the following client library choices:

I have chosen Clodiuno for this task simply because it has good documentation and the code is straight-forward. I noticed the examples in clj-Firmata are using channels in clojure which i don’t think is needed for a “hello world” program.

So lets start,

Step 1 is to load the Standard Firmata onto the ESP-01.

Connect the ESP-01 in programming mode with your computer.

ESP01 in Programming Mode
ESP01 in Programming Mode

Open Arduino IDE and from Files->Examples->Firmata, select StandardFirmata. Upload that onto the ESP-01, you should see something like this:

Ardunio IDE Firmata Upload
Ardunio IDE Firmata Uploaded

After loading the StandardFirmata onto the ESP-01 i have noticed that the built-in LED is always HIGH.

I am going to test the blinking LED example in Clojure to see if that works. Next step is to create a Clojure project. Then use the example provided by the Clodiuno for blinking LED.

From the Ardunio IDE, i know that my hardware is connected on “/dev/cu.wchusbserial1450” so i will replace that in the code for communication.

The next step is to compile and test the Clojure code. Fingers crossed.

Lets continue from here tomorrow and see what exciting results we get from the compilation.

I am looking forward to it.

Functional Programming with IOT (FIOT) – Day 1

Today, i have started exploring how we can use Functional Programming with hardware. Typically, hardware programming is done in C, Assembly or dialects of C/C++. It is easy to compile the code written in those languages and convert it into binary to burn it onto the hardware as a new firmware.

A simple google search will show you that there are people in the past like John Lee[1] who published a book in 1972, who presented the concept of describing hardware as notations. Then in 1985, Meshkinpour[2] and Ercegovac [3] proposed another Functional Programming style language called FHDL.  So the idea about using functional programming with hardware is not new but the approach that has always been taken is to develop a separate language from the mainstream software programming languages and look at hardware as a completely different world.

The book Infrastructure as Code disagrees with the idea that hardware should be treated separately from your software component. The reason for treating hardware separately in the past was that it was expensive and it took more effort to add a new hardware or get a bigger machine for your use case. There is no reason to do that anymore as hardware is more affordable and easily accessible.

So in the upcoming blog posts i shall explore one of the most famous ICs for Internet of Things ESP8266 using a functional programming language. I am interested in hardware parallelisation, performance and code simplicity. Also, i shall explore some design patterns for functional programming languages like function composability.

Lets start this journey!



[1] J. A. N. Lee, Computer Semantics, Van Nostrand Reinhold Company, 1972.

[2] F. Meshkinpour and M. D. Ercegovac, “A functional language for description and design of digital systems: sequential constructs,” in Proceedings of the 22nd ACM/IEEE Conference on Design Automation, pp. 238–244, ACM Press, 1985. View at Scopus

[3] M. D. Ercegovac and T. Lang, “A high-level language approach to custom chip layout design,” Technical Report MICRO Project Reports 1982-83, University of California, Berkeley, Calif, USA, 1982. View at Google Scholar