Saturday, March 7, 2015

Happy Women's Day

I’m a female tech lead.

That’s enough to set me apart and I truly wish for the day it won’t.

Some will ask, “Are you blind? Don’t you see that all tech companies have so many female employees?”   From them I ask “How many women leads and architects do you see in them?” And they will shut up!

Why is it that we have very few females in the senior end of dev track? We do see so many female sw engineers. Does that mean the glass ceiling is at the lead level?

Ok. Stop. Why do we even bother?  Women in SL get a nice education, attend universities and hold so many positions. They get a nice paycheck, make decisions, drive their own cars, and travel on their own. Does it really matter if we don’t have many females in these very specific roles? 

Let me tell you a story.

There was this 17 year old girl who did not get a nice English education as her brothers did, and was married off to a 42 year old man against her will by her father. If a woman can read a medical prescription, isn’t it enough? he asked.

Well, that girl is well over 80 and is my grandmother.

Look at the difference two generations have made.  In the first generation it’s enough for a girl to know how to read or write. In the second generation it’s enough for a girl to have university education and in the third generation it’s enough for a girl to have a well-paying job.

Here’s another story.

In the 1940s the record time for running a mile had reached 4:01 min. It was believed by doctors and scientists that it was physically impossible to run a mile in less than four minutes. And no one did until 1954. In 1954 Roger Bannister broke the 4 min barrier and set a new record in Olympics. Interesting part is not him breaking the record, but another one breaking it after a month and half a dozen breaking it within the next few years.

Both stories are about stereotypes, norms, paradigms, whatever the term we like to use. Once the barrier is broken, once the paradigm is changed, the norm will change.

Most evil of the stereotypes are the ones that exist in our own heads.

Happy women’s day to all the lovely ladies who silently do a battle in their own fronts without even knowing that they do so.

Friday, February 13, 2015

JAXB2 Annotate Plugin

I was using maven-jaxb2-plugin plugin to generate objects from a standard xsd and created a web service that accept from xml and json types of DeliveryInfoNotification object. In my cxf-servlet there was org.codehaus.jackson.jaxrs.JacksonJsonProvider that was used for binding JSON content to and from POJOs.

Web service was working fine with xml requests but for json requests it was giving the following error.

Unrecognized field "deliveryInfoNotification" (Class oma.xml.rest.netapi.messaging._1.DeliveryInfoNotification), not marked as ignorable

org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "deliveryInfoNotification" (Class oma.xml.rest.netapi.messaging._1.DeliveryInfoNotification), not marked as ignorable

 at [Source: org.apache.cxf.transport.http.AbstractHTTPDestination$1@c85f54d; line: 2, column: 33] (through reference chain: oma.xml.rest.netapi.messaging._1.DeliveryInfoNotification["deliveryInfoNotification"])

In order to get rid of that I had to annotate the DeliveryInfoNotification with @JsonIgnoreProperties

How do I get annotations in generated POJOs?

Answer was to use JAXB2 Annotate Plugin.

After several trial and errors it worked. With some configurations it was not giving any errors but was not generating the annotations which was a little frustrating. There were 2 options to configure annotations, add them in xsd or an external bindings file. I used the second option since it was not a great idea to change the standard xsd.

I got the following and had to add a dependency to the plugin to get rid of it.

Caused by: org.jvnet.annox.annotation.AnnotationClassNotFoundException: Annotation class [org.codehaus.jackson.annotate.JsonIgnoreProperties] could not be found.
    ... 32 more
Caused by: java.lang.ClassNotFoundException: org.codehaus.jackson.annotate.JsonIgnoreProperties

Anyway here is the final configuration that worked.

In pom.xml build->plugins->

                org.jvnet.jaxb2.maven2
                maven-jaxb2-plugin
                0.8.2
                
                    
                        
                            generate
                        
                    
                
                
                    src/main/resources/xsd
                    src/main/resources/xsd
                    ${project.build.directory}/generated-sources/xjc
                    binding.xjb
                    true
                    
                        -XtoString
                        -Xequals
                        -XhashCode
                        -Xannotate
                    
                    
                        
                            org.jvnet.jaxb2_commons
                            jaxb2-basics
                            0.6.4
                        
                        
                            org.jvnet.jaxb2_commons
                            jaxb2-basics-annotate
                            0.6.4
                        
                    
                
                
                    
                        org.codehaus.jackson
                        jackson-jaxrs
                        1.9.13
                    
                
            

In binding.xjb




    
        
        
            
        
        
    





Friday, January 30, 2015

First Ever IoT Community And First Ever IoT Meetup In Sri Lanka




Colombo IoT community was founded in November, 2014 with a vision of educating and supporting innovation of IoT in Sri Lanka.

Being true to the futuristic vision of Intel, Intel Sri Lanka was the driving force behind the first ever meetup conducted by the community on 21st January 2014 as the sole sponsor of the event.
We had a packed audience of more than 200 IoT enthusiasts with both industry and academia well represented.

Introductory session was conducted by Kasun Dilunika, Tech Lead at Intel Software. Kasun was instrumental in this initiative from the very beginning and is in the process of building an IoT enabled smart switch to solve a household problem he experienced.
He explained how the evolution of internet progressed from Internet of Places, Internet of People and finally to Internet of Things, with 40 billion devices expected to be connected by Year 2020.
Microcontrollers and sensors are the two main driving forces of IoT. There are many to choose from with different capabilities and varying sizes. Want to connect your house keys to internet, anyone?
Kasun answered a question that was surely in the minds of many who attended the meetup. There were home automation solutions etc years back. Isn’t it the same old thing that has come in a new dress as IoT?

IoT devices have 3 main capabilities; Control, Compute and Communication. We call them 3C (ccc) devices. Unlike their pre-IoT era siblings, today’s IoT devices have all 3Cs as a single unit in a small form factor.  Earlier devices mainly lacked in communication aspect. With Raspberry PI, Arduino, Intel Edison and Galileo, programming to hardware has become a child’s play. (We’re serious! Check this out http://www.raspberrypi.org/resources/make/)

Come up with an idea, it was said. It doesn’t have to be world changing, mind boggling complete with a nuclear reactor and a particle splitter. Kasun explained how our friend Jagath Makumbura came up with an idea for a Smart Susan after having chicken gravy spilt on him when using the turn table (lazy Susan) at a Chinese restaurant. Jagath’s Smart Susan was also on display during the meetup.


We’re sure many young minds were inspired by Kasun when he invited everyone to come up with their own project ideas and insisted on the fact that those who do will be guided by the Colombo IoT community. We truly hope that it will ultimately result in a product with “Made in Sri Lanka” label on it.
It was exciting news for the potential IoT innovators that 5 best IoT project proposals will be given Intel® Galileo Gen 2 microcontroller boards each.

Chamara Ratnaweera (Senior Architect at Intel Software), Chandana Kithalagama (Senior Architect at Intel Software) & Banuka Amarasinghe (Senior Software Engineer at Intel Software) presented “Kumana IoT Project”, a unique demonstration of IoT in a practical scenario.
Kumana is a national park in Sri Lanka which was severely affected by drought in 2014. Many animals were dying due to the lack of drinking water. Efforts taken by park authorities to deliver water to water holes from bowsers were not very effective. An initiative was taken by Intel Sri Lanka employees along with many other environmental enthusiasts to provide drinking water to the animals. Idea was to install a solar powered water pump to draw water from a tube well and fill a watering hole with it.

It was completed successfully. We were happy, animals were happy; but there was a small problem! The equipment was located in a remote area inside the thick jungle and there was no way of getting any information on how it was functioning. We didn’t want the water to be pumped when it was raining, we wanted to know if any of the equipment was malfunctioning and we knew Sri Lankan elephants are known to attack anything foreign! We couldn’t possibly get an elephant to telephone us if anything goes wrong.

Chamara got the bright idea of implementing an IoT solution to solve all of the above.


 A sensor array would gather environmental data (ambient light, temperature, humidity) and other relevant data such as voltage generated by the solar panel, amperage flowing through the system, water flow rate from motor to tank and water level of the main water hole for animals.
Sensor Data Aggregator (SDA) would periodically consolidate the sensor data at a particular point of time, process them and send it to onsite controller module. An Arduino board was used due to the ease of handling low level devices, low cost and low power consumption.
It was decided to use SMS as the communication channel since the onsite deployment is in a remote area.

Handling communication by sending out the data SMS and receiving and processing control SMS and also issuing control signals to the motor is the responsibility of Motor Control Module. A Raspberry Pi would run the show in this module and the decision to use a Pi was inspired by the fact that it’s better at working with high level languages like Python.
Central Processing Unit (CPU) hosted in cloud complete with an analytical module decided when to send a control signal to stop/start the motor and when to alert the stakeholders of a possible breakdown.

CPU provided an API to extract data and control the system.
A fancy UI application called the API exposed by the CPU and displayed it in a nice dashboard and provided control functionality, and of course you could access it via the internet on whatever smart device you choose to view it from.

Chamara, Banuka, Jagath, Sachindra, Chandana, Buddhi, Madhura, Kushan and many others contributed in successfully building up the prototype that was on display during the meetup.
Aruna Dissanayaka, Director of Engineering at Intel Software, took the audience on a global tour in his key note speech, highlighting on the need for IoT in major cities to cater their booming population. He explained that having enough IP addresses is not sufficient for the exponential growth in IoT devices. Standards would have to adapt, for example IP stack doesn’t suit most IoT devices.
Kolitha Ratwatte, General Manager, Intel Software Sri Lanka, whose immense support helped make this event a success, concluded the meetup speaking about the way forward for Colombo IoT community.

A Q&A session followed with many interesting questions raised by the audience.

This is the story of the first ever IoT meetup in Sri Lanka sponsored by Intel. It might be a small step, but as they say “A journey of a thousand miles must begins with a single step.”

Tuesday, January 20, 2015

Sending and receiving SMS using your dongle

I've almost forgotten I had a blog :|

I had to keep the following somewhere other than my memory since I know how unreliable it is.

There was a need to send and receive SMS for an app and people were wondering if we need to buy a separate GSM modem for that. Easier solution was to use a dongle (which is, well, basically a GSM modem J )

After a little research I thought of using SMSLib as recommended by many folks on internet. (http://smslib.org/)

SMSLib is a SMS messaging library. As mentioned in their home page two SMSLib versions currently available. The old, stable v3.x and the newer v4. SMSLib v4 is under development.

I used smslib-3.5.4.jar.

Downloads can be found at http://smslib.org/download/. Some of the paths given for artifacts in installation directory are not working, so I used the downloads page.

Used
  • HUAWEI Mobile HSPA+ dongle
  • Win64
  • smslib-3.5.4
  • java 7

1. Plug in dongle to USB port and find port number (Control Panel -> Device Manage -> Ports) It was COM11 in my case
2. Add RXTXcomm library as mentioned below
3. Create a sample java project and add smslib-3.5.4.jar in lib
4. Run the following java code. (Update port)

import org.smslib.*;
import org.smslib.modem.SerialModemGateway;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;


public class SmsSenderReceiver {

    public void sendMessage() throws Exception {

        SerialModemGateway gateway = new SerialModemGateway("", "COM11", 9600, "", "");
        gateway.setInbound(true);
        gateway.setOutbound(true);

        OutboundNotification outboundNotification = new OutboundNotification();
        InboundNotification inboundNotification = new InboundNotification();

        Service service = Service.getInstance();
        service.setOutboundMessageNotification(outboundNotification);
        service.setInboundMessageNotification(inboundNotification);
        service.addGateway(gateway);
        service.startService();

        OutboundMessage msg = new OutboundMessage("0722452122", "test111");
        service.sendMessage(msg);
    }

    public class InboundNotification implements IInboundMessageNotification {
        @Override
//Get triggered when a SMS is received
        public void process(AGateway gateway, Message.MessageTypes messageTypes, InboundMessage inboundMessage) {

            System.out.println(inboundMessage);
            try {
                gateway.deleteMessage(inboundMessage);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public class OutboundNotification implements IOutboundMessageNotification {

//Get triggered when a SMS is sent
        public void process(AGateway gateway, OutboundMessage outboundMessage) {
            System.out.println(outboundMessage);
        }
    }

    public static void main(String args[]) {
        SmsSenderReceiver app = new SmsSenderReceiver();
        try {
            app.sendMessage();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

A prerequisite of using SMSLib is having Java Communications library as mentioned in http://smslib.org/doc/installation/.
They list two options

1.  Win32 :-> Java Comm v2
2.  For others :-> Java Comm v3 or RxTx

Java Comm didn't work for me. Use RxTx.


(Above are found at http://smslib.org/download/)

File RXTXcomm.jar should go under JDKDIR/jre/lib/ext/
The necessary library (e.g.the librxtxSerial.so) should go under JDKDIR/jre/bin/


In Linux
Tried to do the same in Linux environment, but unfortunately I kept receiving NoSuchPortException.

Tailed /var/log/messages to view updates.

Device was first identified as "usb-storage". usb_modeswitch was used

usb_modeswitch -H -v 0x12d1 -p 0x1506

View changes.
lsusb

View the port numbers and their permissions. Can see the ports that are mapped to GSM modem.
ls /dev/tty* -l

Added read write permissions
chmod o+rw /dev/ttyUSB*
chmod o+rw /dev/ttyS*

Can use minicom to see if the dongle is functioning as expected.

java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path thrown while loading gnu.io.RXTXCommDriver
Exception in thread "Thread-3" java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path
               at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1886)

librxtxSerial.so had to be added to JDKDIR/jre/lib/amd64 instead of  JDKDIR/jre/bin/ to solve the above.

As suggested in http://smslib.org/doc/smslib/troubleshooting/ added the soft links to something resembling a standard serial port.
ln -s /dev/ttyUSB_utps_diag /dev/ttyS20
ln -s /dev/ttyUSB_utps_modem /dev/ttyS21
ln -s /dev/ttyUSB_utps_pcui /dev/ttyS23

The above hack and more useful infor can be found at http://rxtx.qbang.org/wiki/index.php/Trouble_shooting too.
View "How does rxtx detect ports? Can I override it?" Section.

Kept on getting the following warning too.

check_group_uucp(): error testing lock file creation Error details:Permission deniedcheck_lock_status: No permission to create lock file.
please see: How can I use Lock Files with rxtx? in INSTALL

Adding my user to group uucp didn’t solve it L

usermod -aG uucp myUser

vim /etc/group

Sunday, September 29, 2013

Fuse ESB : Email Attachement Issue

I faced a very annoying issue when I tried to send an email with attachments using Fuse ESB. I created a simple project in Fuse IDE which sent a mail with attachments and it was working fine as a stand alone application but when the bundle was deployed in Fuse it was not sending the mail when there are attachments. There was no exception in logs, but then it was found that there is actually an exception and it was getting set to the exchange.

javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed;

Many have come across this issue when dealing with javamail in other containers and for most of them it was because javamail jar was not found by the container.

Some solutions that have worked were found in this.
http://blog.hpxn.net/2009/12/02/tomcat-java-6-and-javamail-cant-load-dch/

But unfortunately it didn't work for me. 

javax.activation package exposed by the jre was not working. Removing it and adding an OSGI friendly version of this package created by Servicemix resolved the issue.

Solution
  1. Comment out the javax.activation export from jre.properties
  2. Install following bundle instead. install mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.activation-api-1.1/2.2.0