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