- It is a very simple language to learn and easy to implement and deploy, so you don't need to spend a lot of time learning lots of formatting standards and compiling options.
- It is portable, expandable and embeddable, so, it is not system dependent, and hence supports a lot of single board computers on the market these days, irrespective of architecture and operating system.
- Most importantly, it has a huge community which provides a lot of support and libraries for the language.
It's about this last point that this post attempts to discuss.
The Internet of Things is a big deal today. Some consider it to be a buzzword,others say it's a phase while many others, large industries included, stand by their belief that it is going to be a game changer. However, when all is said and done, the Internet of Things has no classical definition, and as a result, its meaning is about as uniform as philosophical ideologies. Because the Internet of Things paradigm has its hands in a lot of pies, the semantics of it are largely dependent on your perspective. For me, the recipe for the Internet of Things is very simple. A 'thing', which could literally be anything, is fitted with an embedded system which connects it to the internet, in other words, it has its own IP address. This thing may now interact with other things, remote or local over the internet. The possibilities made possible by this infrastructure are used cases for At this junction, IoT occupies a place of importance in Wireless Sensor Networks, Data Analytics, Cyber Physical Systems, Big Data and Machine Learning. It is also very focused on real time analytics and processes. So, for the development of an IoT solution, one would need a programming language which spans these diverse fields, while being lightweight and scalable at the same time. I wonder which programming language can do that?
In this post, I'll be discussing the Python packages I use for developing IoT applications. I mostly develop applications on the Raspberry Pi Model 3 or the Intel Edison. Both are extremely capable Single Board Computers, with a lot of peripherals to play around with. Both support Linux derived OS distributions and support full Python 2.7 or 3.4. With the right Python packages installed, both of these devices become very versatile components in the IoT domain.
mraa is a skeleton GPIO library for most SBCs which support Python. The good thing about it is that there's just one library for all devices, so I don't have to use different ones for an Edison and a Pi. Being a high level library, reading from and writing to pins is a one line affair, and the library also provides support for communication protocols such as I2C, UART and SPI.
sockets is a package which facilitates networking over TCP/IP and UDP using Python. It provides access to Berkeley socket APIs to access the Internet. Both TCP/IP and UDP being Transport layer protocols, are ideal for communication with devices on the same WiFi network. One of the more interesting uses of sockets, in my experience is that one can build their own communication protocol using this package as the base.
A database is a no-brainer when it comes to most IoT applications. For something whose sole purpose is to send data to the internet, there should be a database, at least a remote one which stores all this generated data. MySQL is the go-to relational database for most developers. In this regard, mysqldb is a very convenient little tool which circumvents the need to execute shell commands within a Python script to read and write to a database.
Having used MatLab extensively during my undergraduate studies, I've grown accustomed to dealing with arrays. Python, on the other hand, deals with lists as a substitute for the array which is the same as having a birch tree replace your Rottweiler as the guardian of the house. It just doesn't work. Thankfully, numpy is there to help you out. It is, in essence, a package for scientific computing using Python, very similar to MatLab, but much lighter. The feature I use most is to read sensor data in bulk from my databases and work on them using the inbuilt functions.
Data visualization is one of the most fundamental operations that can be performed. It looks pretty impressive when you convert a huge list of numbers to a concise graph which can be understood intuitively. It's also very useful if you happen to be an academician. You know how important those graphs can be in a publication. matplotlib provides a number of different styles of graphs that can be plotted using local data. If you're a data scientist, this is althemore useful to you. Personally, matplotlib is a very useful tool to quickly give me insight to the data I have at my disposal.
Another library for data scientists, pandas is a package dedicated towards data analysis. It is in essence, a local alternative to using SQL databases which is more suited to dealing with data as it is built on numpy. It has many advantages over the former, such as a more streamlined approach to data handling and analysis, direct operations on local datasets and the ability to handle heterogeneous and unordered data.
The big brother of signal processing, image processing, was traditionally the domain of high performance, custom built hardware. Although such devices still carry out the job much faster than their single board counterparts, it is at the very least, a possibility. And, in situations where mobility and connectivity are prioritized over speed, this may just be the solution for those rare times. Opencv is a Python port of the very successful C library for image processing. It contains high-level variants of familiar image processing functions which make photo analysis much easier.
Although this library does come preinstalled with all installations of Python, its still worthy of a mention. Tkinter is a GUI development library which comes bundled in with all distributions of Python. For people who are more comfortable with a stab wound rather than object oriented programming, learning how to use this package may be a bit daunting at first, but the rewards more than make up for the effort. Every aspect of your Python script can be controlled via a completely ad hoc GUI. This is extremely useful in situations such as functionality testing or repeated executions of the same code.
Tensorflow is a package for numerical computations for machine learning. It utilizes a different mathematical representation called data flow graphs which use nodes as mathematical operations and edges as data arrays. This is a very useful library to have if you deal with a lot of non linear datasets or work extensively with decision trees and neural networks.
HTTP is one of the major protocols used in traditional internet based resource exchange, being more suited towards large data exchanges. The requests package is used in Python to make HTTP calls and parse responses. This package is useful when dealing with HTTP based third party cloud services.
MQTT is a protocol developed solely for for the Internet of Things paradigm. Its focus on high speed communication for low payload communication between resource constrained devices. the paho-mqtt library gives a very user friendly version of the protocol for use with embedded systems. MQTT requests can be made directly within Python, without any additional setup to be done. Especially useful in the prototyping stage.
Which libraries do all of you use? It would be great if we could find a few very useful libraries in this discussion!