Unique ID in Raspberry Pi

Sometimes we might need a unique id from a raspberry PI. We don’t have to worry about generating a unique id for every device. There is a simple way to use an already existing unique number within the device. The serial number of the chip will be good enough to use as a unique key.

The following command will give the details of the cpu. We can find a serial number from this details and can be used as a unique id.

pi@raspberrypi:~ $ cat /proc/cpuinfo
processor   : 0
model name   : ARMv7 Processor rev 4 (v7l)
BogoMIPS   : 38.40
Features   : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer   : 0x41
CPU architecture: 7
CPU variant   : 0x0
CPU part   : 0xd03
CPU revision   : 4

processor   : 1
model name   : ARMv7 Processor rev 4 (v7l)
BogoMIPS   : 38.40
Features   : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer   : 0x41
CPU architecture: 7
CPU variant   : 0x0
CPU part   : 0xd03
CPU revision   : 4

processor   : 2
model name   : ARMv7 Processor rev 4 (v7l)
BogoMIPS   : 38.40
Features   : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer   : 0x41
CPU architecture: 7
CPU variant   : 0x0
CPU part   : 0xd03
CPU revision   : 4

processor   : 3
model name   : ARMv7 Processor rev 4 (v7l)
BogoMIPS   : 38.40
Features   : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer   : 0x41
CPU architecture: 7
CPU variant   : 0x0
CPU part   : 0xd03
CPU revision   : 4

Hardware   : BCM2709
Revision   : a02082
Serial      : 00000000xxxxxxxx

Hope this info is helpful. !!

Good Quote.!!

“A beginning programmer writes her programs like an ant builds her hill, one piece at a time, without thought for the bigger structure. Her programs will be like loose sand. They may stand for a while, but growing too big they fall apart.

Realizing this problem, the programmer will start to spend a lot of time thinking about structure. Her programs will be rigidly structured, like rock sculptures. They are solid, but when they must change, violence must be done to them.

The master programmer knows when to apply structure and when to leave things in their simple form. Her programs are like clay, solid yet malleable.”

— Master Yuan-Ma, The Book of Programming

A simple program to begin with python tornado

Python tornado is a powerful framework for dealing with HTTP requests. It helps us to write responses to HTTP requests in a very simple and elegant way. We can write handlers for responding to the HTTP requests very easily using tornado. This is very simple to learn and use. We can create an excellent application in very few lines of code. Here I am explaining about a simple tornado application. The code is attached below. For running this code, you need tornado to be installed in your machine.

In the beginning of the code, you can see few imports related to tornado. These libraries are required for our tornado application. After that you can see a define function. This define is imported from a library called options in tornado. Using this we can get user defined arguments from commandline. Here we are defining the port in which our tornado application should run. If the user is specifying the port in the command line, it will use that value, else it will use the default value. Here I gave default value as 8888. 

The next part is a class named HelloWorldHandler. This is a class extending the tornado RequestHandler class. This is basically a handler, which means this will handle an HTTP request. This class will be called based on the navigation rules that we define in the tornado. In this class there is only one method called get(). So this handler can handle only get requests. In the get method, we are just printing a text “Someone called me” and writing a response. So whenever this class is called, The text “Someone called me” will be printed in the console and the self.write(“Welcome to Tornado..!!”) will send the this string to the HTTP response.

The next part will run the tornado application. The “tornado.web.Application(handlers=[(r”/”, HelloWorldHandler)])” defines when to invoke the handler. the r”/” is a regex. So if the url comes without any path, the request will be navigated to HelloWorldHandler class. Similar to this we can have a list of regex – handler class pairs. Here we have only one.

Execution.

python HelloTornado.py –port 9090

This will run the application in 9090 port. After this open the web browser and check http://localhost:9090. You will get a message “Welcome to Tornado.!!” on the screen. For every hit, you can see a message “Someone called me” getting printed in the console.

python HelloWorld.py

This will run the application in the default port that we specified. I specified 8888. So open the webbrowser and check http://localhost:8888.

Note: If you are executing the code in a different machine, you should use the ip address of the machine instead of localhost.

Happy Learning … 🙂

We connected computers in the past, Now computers are connecting us…!!

A new revolution is going to happen in the world with connected devices and human life. We can call it as Internet of Things. Now lot of discussions and experiments are happening around the world to make this concept a reality. This is a very simple concept from the point of view of a person who knows electronics. But the problem is that for making this internet of things a reality and to make it usable by every individuals, it needs much more effort. For developing an application that makes our life easier by connecting things, we need the skillsets of a software engineer and electronics engineer. An electronics engineer can design the circuit, wire up and get the signals in the proper way. But those signals are just some electrical signals which will be useful only to the technical people. These systems were already in the past. Then what is different in IoT..??

IoT includes connecting systems, sensing each and every members in the network and controlling of every single node in the network based on the feedback. The control may not be based on a pre-written script, it can be dynamic. This requires extensive analytic knowledge along with electronics knowledge. If we sense and control every member of a large network, the data size will be high. Here we have big data solutions. So if we combine the electronics and analytic knowledge, we can build superb systems that can revolutionize the world. If we make everything connected and everything under control, there are some pros and cons. This will be just like the atomic energy. Good people used it for energy sustenance by generating energy and bad people used it as atom bomb for destroying people. Hope IoT will be used in the right way..!!!!

The internet of bees could save our food supply

Jenkins/Hudson not executing jobs (pending – waiting for next executor)

Problem

I faced an issue in jenkins while executing multiple jobs in parallel. Upto a specific number of jobs are running in parallel, but beyond that, if we submit any job, it was going to waiting state.

Solution

In this case, jenkins is executing jobs in parallel upto some number. That means somewhere we need to increase the parallelism paramater.

  • go to Jenkins -> Manage Jenkins -> Manage Nodes
  • check whether all nodes are active and healthy
  • Check whether disk space is available in nodes
  • If everything is fine and if the machine have enough hardware configuration, you can increase the number of executors.

For that, click on configure and increase the number of executors as per your requirement. 

NB: If the jenkins is not at all executing jobs, then it might be because of offline master.

“Missing artifact jdk.tools:jdk.tools:jar:1.6”

While using maven, we may face an error like
“Missing artifact jdk.tools:jdk.tools:jar:1.6”

This problem can be fixed by adding the below lines to your pom.xml file.
Replace ${JAVA_HOME} in the xml file with the absolute path of JAVA_HOME.

<dependency>
<groupId>jdk.tools</groupId>
<artifactId>jdk.tools</artifactId>
<scope>system</scope>
<version>1.6</version>
<systemPath>${JAVA_HOME}/lib/tools.jar</systemPath>
</dependency>

Python code to find the md5 checksum of a file

Checksum calculation is an unavoidable and very important step in places where we transfer files/data. The simplest way to ensure whether a file reached the destination properly or not is by comparing the checksum of source and target files. Checksum can be calculated in several ways. One is by calculating the checksum by keeping the entire file as a single block. Another way is multipart checksum calculation, where we calculate the checksum of multiple small chunks in the file and finally calculating the aggregated checksum.
Here I am explaining about the calculation of checksum of a file using the simplest way. I am using the hashlib library in python for calculating the checksum.
Suppose I have a zip file located in the location /home/coder/data.zip. The checksum of the file can be calculated as follows.

import hashlib
file_name = ‘/home/amal/data.zip’
checksum = hashlib.md5(open(file_name).read()).hexdigest()
print checksum

One common mistake I have seen among people is passing the file name directly without opening the file

Eg: hashlib.md5(file_name).hexdigest()

This will also return a checksum. But it will be calculating the checksum of the file name, not the checksum calculated based on the contents of the file. So always use the checksum calculation as follows

hashlib.md5(open(file_name).read()).hexdigest()

This will return the exact checksum.

In linux, you can calculate the md5sum using a commandline utility also.

> md5sum file_name

Processes started and running fine, but running processes are not listing in jps

Today I met a strange issue while installing hadoop on a linux machine.

I started all the processes, it was working fine also, but those processes were not listed in jps. I struggled with issue for some time, later I found the solution. The reason was because, some files like hsperfdata_<username> were present in /tmp folder. I deleted those files, after that jps listed all the running processes.. 🙂

Actually this hsperfdata_ is a feature Not bug. It’s a log directory created by jvm while running and its a part of Java performance counter. This folder created inside tmp folder of any operating system by default.
JVM uses this folder for process monitoring.
This folder contains perfdata corresponding to java process id running from user mentioned in hsperf Data folder name.

Hello World

I am Amal G Jose, an Electrical Engineer by qualification, currently I am working as a Software Engineer. Before starting my career as a software engineer, I was unaware of this field. After a few months, I found some interesting areas in software field. Because of God’s grace, I got an opportunity to work in the latest technologies in this field like BigData Solutions, hadoop, hive,  pig, hadoop cluster etc. I started my carrer as a hadoop administrator. That was a nice experience and got a lot of knowledge. After that I started working in development projects also. I got good exposure in administration & development fields and I am tuning myself to this industry. I am here to share my learning, so that it may help someone like me who is new to this field.