AN ASSESSMENT WIKI FOR INTERNET OF THINGS

This is my first publication done with my classmates in the American University of Sharjah. it is about an integration between an assessment wiki and multiple sensors connected to an arduino board that sends the telemetry to a raspberry Pi board then the integration is done through a message oriented middle-were called openfire through the XMPP protocol the outcome of this implementation is that contributors to the wiki can write questions that includes sensor readings from the physical world and users can answer questions that dynamically change the answers based on the readings from the sensors, below is the paper citation.

http://library.iated.org/view/ZUALKERNAN2014ANA2

Introduction to Internet Explorer Browser Automation

Browser automation, this technology seemed like black magic or forbidden for some, but it may be your last resort of integration (not really an integration) if there is no interface to integrate with the web application you need to interact with and exchange information. for many years it was my favorite resort for quick wins and workaround solutions for many issues, to list a few:

  • You have a list of thousands of data entry rows you need to update to a web form
  • You have an application that needs to automatically type data to a web page and submit it in a macro style function
  • You need to retrieve data from thousands of pages and compile them in one tabular format
  • You need to create your own web SSO application

The list is not limited to the above but can be endless in terms of quick win solutions. some companies offer you frameworks to purchase that does this black magic for you but I need to make a point that it is too simple and easy to perform that you don’t need to rely on a specific framework to do it for you.

I am going to concentrate on IE automation due to the reason that most enterprise environments rely (unfortunately) on internet explorer to run their applications, even some web applications only run on IE. I will be writing a different guide for using the Selenium framework in java that is more suited for Firefox automation although it also has IE drivers to run automations on.

Some say why do you have to do it in IE, why not use the webbrowser control from the .Net framework? a simple answer is that the webbrowser control is limited and does not offer the complete features of running web applications on it, say for example running an activex, or making some SSO (Single Sign On) applications that also does automation to work with the application you are going to write for your desired automation, additionally it will offer the user the same experience of a native web browser which is a huge advantage.

Follow these steps and you will have the key to begin automating your tasks in internet explorer using .Net framework:

In the below example we are going to automate google.com to search for a specific term that the user will enter in your application.

  1.  Create a windows forms (or console if you desire) project in visual studio (windows forms is used for simplicity)
  2. add reference to Microsoft internet controls (shdocvw.dll) step2
  3. import shdocvw to the windows form class
    using SHDocVw;
  4. add a button and a textbox to your form step4
  5. Create a new object that contains the internet explorer instance at the class level and create a Boolean variable to trigger automation when desired and a string variable to pass to the document complete event to avoid cross thread exception in your debugging environment
            //Create a new object that contains the internet explorer instance
            InternetExplorer iExplorer = new InternetExplorer();
            //Create a boolean variable to trigger automation when desired
            bool doAutomation = false;
            //Create a string variable to pass to the document complete event
            string searchTerm = "";
            
  6. add the following code to the form load event to make the internet explorer instance visible and add a handler to the document complete event of the webbrowser, the document complete event is the event that fires when the page is completely loaded in the browser (except for ajax loads)
    private void Form1_Load(object sender, EventArgs e)
            {
                //add a handler to the document complete event in internet explorer
                iExplorer.DocumentComplete += iExplorer_DocumentComplete;
                //Make the internet explorer instance visible
                iExplorer.Visible = true;
            }
            
  7. add the following code to the button click event to navigate to a desired URL, set the search term variable from the input text box and trigger the automation by setting the Boolean variable assigned to true:
    private void button1_Click(object sender, EventArgs e)
            {
                //Set a flag to do the automation
                doAutomation = true;
                //Set the search term from the input textbox in the form application
                searchTerm = textBox1.Text;
                //Navigate to a URL like google
                iExplorer.Navigate("https://www.google.ae/");
            }
            
  8. add reference to the Microsoft HTML object library step8
  9. import mshtml to the form class:
    using mshtml;
  10. go to internet explorer developer tools (press f12) and search by clicking on the elements you want to automate and get their IDs, in our case, the google search input id is “q” and the search button id is “gbqfba” step10
  11. add the following code the browser complete event, the code is commented and you can understand how it works from the comments
    void iExplorer_DocumentComplete(object pDisp, ref object URL)
            {
                //check if the desired URL is loaded & automation is triggered
                if (URL.ToString() == "https://www.google.ae/" && doAutomation)
                {
                    //reset the automation trigger to avoid automation when not required
                    doAutomation = false;
                    //cast pDisp to an internet explorer variable
                    InternetExplorer iEplorerDOC = (InternetExplorer)pDisp;
                    //get the document object from the internet explorer instance
                    mshtml.HTMLDocument doc = iEplorerDOC.Document;
                    //get the search input element from the document object by ID
                    mshtml.IHTMLElement searchElem = doc.getElementById("q");
                    //set the search value to the desired term by setting the attribute of the input textbox of google to any value
                    searchElem.setAttribute("value", searchTerm);
                    //get the search button object from the document loaded
                    mshtml.IHTMLElement searchBtn = doc.getElementById("gbqfba");
                    //invoke the click command to simulate the onclick method of the element in the document loaded in the browser
                    searchBtn.click();
                }
            }
            
  12. Run the application, input your search term then press the search button to observe the black magic (see how simple was that!)
    step 12

Below is the full code example:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SHDocVw;
using mshtml;

namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        //Create a new object that contains the internet explorer instance
        InternetExplorer iExplorer = new InternetExplorer();
        //Create a boolean variable to trigger automation when desired
        bool doAutomation = false;
        //Create a string variable to pass to the document complete event
        string searchTerm = "";
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //add a handler to the document complete event in internet explorer
            iExplorer.DocumentComplete += iExplorer_DocumentComplete;
            //Make the internet explorer instance visible
            iExplorer.Visible = true;
        }

        void iExplorer_DocumentComplete(object pDisp, ref object URL)
        {
            //check if the desired URL is loaded & automation is triggered
            if (URL.ToString() == "https://www.google.ae/" && doAutomation)
            {
                //reset the automation trigger to avoid automation when not required
                doAutomation = false;
                //cast pDisp to an internet explorer variable
                InternetExplorer iEplorerDOC = (InternetExplorer)pDisp;
                //get the document object from the internet explorer instance
                mshtml.HTMLDocument doc = iEplorerDOC.Document;
                //get the search input element from the document object by ID
                mshtml.IHTMLElement searchElem = doc.getElementById("q");
                //set the search value to the desired term by setting the attribute of the input textbox of google to any value
                searchElem.setAttribute("value", searchTerm);
                //get the search button object from the document loaded
                mshtml.IHTMLElement searchBtn = doc.getElementById("gbqfba");
                //invoke the click command to simulate the onclick method of the element in the document loaded in the browser
                searchBtn.click();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //Set a flag to do the automation
            doAutomation = true;
            //Set the search term from the input textbox in the form application
            searchTerm = textBox1.Text;
            //Navigate to a URL like google
            iExplorer.Navigate("https://www.google.ae/");
        }
    }
}

XMPP vs MQTT-SN for IoT Applications

XMPP vs MQTT-SN

In a class I am attending for Dr.Imran Zulkernan for advanced internet computing we were discussing a very interesting topic for message oriented middle-wares using both publish subscribe and request response mechanisms, we were assigned an exciting homework to compare both XMPP & MQTT-SN middle-wares for use in IoT applications. I wanted to share the results and hope that it may come in handy for your decision if you are interested in this topic.

MQTT-SN: Message Queuing Telemetry Transport (MQTT) is an open pub/sub protocol. MQTT-SN is an extension of the open publish/subscribe protocol designed for constrained devices used in telemetry applications. [2]

XMPP: Extensible Messaging and Presence Protocol (XMPP), which is standardized by the IETF and widely deployed for real-time data stream and Instant Messaging (IM) applications. XMPP itself is a set of flexible and open XML technologies that are expandable by protocol extensions (XEPs) to adopt to various environments
and scenarios. [1]

Criteria XMPP MQTT-SN
Suitable for Devices with limited ROM resources Has a modified version called uXMPP which has reduced functionality & the output code is around 12.21 kb Full implementation is 12 kb but it can be reduced further by implementing predefined topic IDs
Addressing Single Devices The devices can be directly addressed and messages can be identified from by the jabber ID of the device Devices are publishing topics and only the broker identifies the device for QOS reasons but the subscriber doesn’t get the device id by default, rather the subscriber get the topic contents aggregated from one or multiple devices
Addressing Multiple Devices XEP implementation XEP-0045 can help in addressing multiple devices using a chat room, but these chat rooms cannot be addressed in a hierarchal fashion. If we need devices in the same floor they all need to be in a chat room, and if these same devices needs to be grouped to include all the building these devices need to be also joined to a different chat room including all devices in the building Devices are publishing topics and topics can be addressed in a hierarchal fashion, there are wildcards supported that can select multiple topics such as multiple room temperatures for a certain floor and room temperatures for the whole building
Actuator Control Device can be identified by jabber id and control message can directly reach the destination device Device needs to be subscribed to a control topic and the control message needs to be published to the same topic
Main Method for providing readings Based on the event of receiving a message, but can be extended to publish-subscribe with XEP-0060 Polling where the device needs to continuously provide readings to the subscriber within a certain time interval & can be based on certain conditions. A workaround can be done by making the device subscribe to a topic and publish based on a message received from a topic
Data exchange format XML Stanzas, where the device can publish multiple attributes along with headers but it will add additional overhead in the message packet Content can be stored in the packet for the topic in any format and can be very lightweight
Failover mechanisms uXMPP is using the XEP standard XEP-0174 Serverless Messaging via Multicast DNS (mDNS) and DNS Service Discovery

(DNS-SD) for directly sending messages to the device without an XMPP server which is a failover mechanism in case the XMPP server is down

In MQTT-SN the device has to communicate with a gateway and a broker for the topic to reach the subscriber, no backup mechanism presented
Power saving XMPP can make the device wake up for many times unnecessarily when requesting for data, the extension XEP-0060 can help in resolving that and making it join a chatroom MQTT-SN can help the device stay in sleep mode and publish only in certain conditions without being invoked to wake up and send data
Changing devices XMPP gets affected when changing devices because the new jabber id needs to be configured, the dynamic and up-to-date roster is a workaround to overcome this limitation As the devices publish topics, the subscriber doesn’t care if the device changed because the topic will remain the same
QoS Not available by default but can be added Handles QoS and has 3 levels
Security XMPP supports TLS/SSL, but uXMPP doesn’t currently support it Security is not available in the standard but the messages can be encrypted
Scalability XMPP can be scalable by extending the XMPP server to multiple servers connected together where the message can travel from one server to another Scalability is limited by the number of devices that can be connected to the gateway and the number of gateways that can be connected to the broker

Type of applications suited for XMPP:

  • Actuator networks where identifying each device by its address rather than the topic is important to send control signals to the device.
  • Scenarios where the middleware is not reliable and failover mechanism is required
  • Simple Human-Machine interaction where the human can type control messages to get the required data such as sending a query to a certain device to get the current image of the connected camera.
  • In Feature rich IoT applications such as home automation XMPP is suitable due to the available XEPs that extend the protocol
  • Applications where network is stable and QoS is not very important
  • Applications where integrations with third party solutions from different vendors are required, as XMPP relies on XML as a messaging format, third party solutions can easily adapt to it
  • Applications where security is a concern and TLS/SSL standards needs to be followed
  • When the IoT device has many readings and actuator functionality where they can be easily addressed by the XML format where in XMPP it is the standard and only format, applications similar to getting readings from smartphones where it has multiple sensors where the data can be easily expressed in XML

Type of applications suited for MQTT-SN:

  • Large number of temperature sensors distributed in rooms across different buildings for HVAC control, due to the publish-subscribe mechanism which is mostly suitable for this application
  • Highly constrained devices with limited power that communicate over low bandwidth network
  • Fleet management where the subscriber can subscribe to topics sending GPS locations of grouped devices and monitoring their location on certain interval
  • Applications where the scope is limited such as getting temperature readings for an area
  • Applications where the network quality and performance is low and failures are high, QoS in MQTT-SN helps manage the arrival of messages
  • Suitable for smart-grid applications for getting meter readings from homes where the meters have very limited processing powers
  • Applications such as fire alarms where the sensor needs to be sleeping most of the time and will send readings based on a certain event

References:

[1] Klauck, R.; Kirsche, M., “Chatty things – Making the Internet of Things readily usable for the masses with XMPP,” Collaborative Computing: Networking, Applications and Worksharing (CollaborateCom), 2012 8th International Conference on , vol., no., pp.60,69, 14-17 Oct. 2012

[2] Hunkeler, U.; Hong Linh Truong; Stanford-Clark, A., “MQTT-S — A publish/subscribe protocol for Wireless Sensor Networks,” Communication Systems Software and Middleware and Workshops, 2008. COMSWARE 2008. 3rd International Conference on , vol., no., pp.791,798, 6-10 Jan. 2008

http://www.iotprimer.com/2013/11/iot-protocol-wars-mqtt-vs-coap-vs-xmpp.html
http://stackoverflow.com/questions/7129821/mqtt-vs-xmpp-which-should-i-choose

Microsoft Workflow Foundation

This is my first sort of training video :P, it shows you how to work with flowchart implementation in the workflow foundation 4 framework in visual studio 2010. I have done it as part of an assignment last semester to show a practical use of State Machine and Dataflow Diagrams. An example was taken which was the Inres Protocol and specifically the SCP implementation, hope you like it, please let me know in the comments if would like more videos similar to this one and if you would like the source code and presentation

Requirements:
Microsoft Visual Studio 2010 SP1 or later

https://www.dreamspark.com/Student/Default.aspx

http://www.microsoft.com/en-us/download/details.aspx?id=23691

.Net framework 4.0.1 (both designer and runtime updates)

http://www.microsoft.com/en-us/download/details.aspx?id=608

http://www.microsoft.com/en-us/download/details.aspx?id=11705

http://www.microsoft.com/en-us/download/details.aspx?id=8483