Sensor Characteristics

The sensor is a transducer that converts a physical property into an electrical signal. The physical property can be Weight, Temperature, Pressure, Percentage Composition, Force, Electric or Magnetic or Electromagnetic, Position and Orientation, etc.

The sensors are classified as active sensors and passive sensors based on their working principle. The active sensors use an external or self-generated signal to measure. For example, RADAR emits a series of intense radio waves for a short time and waits for the radio waves or signal to return and calculate the distance of the distant object using the signal flight time. The passive sensors work by changing their electrical properties like resistance or capacitance based on the physical property. For example, an LDR changes its resistance based on the intensity of light.

Sensors must have the following significant properties to define the quality of a sensor:

Range

Every sensor has a range in which they work with an acceptable error. If the input is not in range, then the output is unpredictable.

Drift

The signal level varies for the same input over a long period; this is called as drift. The drift will cause an error in the measured value. The drift may result from aging of the sensor or temperature variance.

Sensitivity

Sensitivity is defined as the change in output per unit change in input of the property being measured. The sensitivity of the sensor may be constant or linear for the entire range of sensor or vary exponentially if the sensor is a non-linear sensor

Selectivity

Selectivity is the ability of the sensor to measure a target property in the presence of other properties. For example, if an oxygen sensor does not react to other gasses like CO2 then it has good selectivity.

Resolution

The resolution of a sensor is the minimum change in the target property that can produce a detectable change in output. For example, consider a temperature sensor with a resolution of 1C; this temperature sensor cannot produce a different output for 0.1C change in input.

Response and Recovery Time

The response time is the time taken by the sensor for its output to reach 95% of its final value when it is exposed to a target material. The Recovery Time is defined conversely.

Linearity

If the sensitivity of the sensor is constant for the range, then it is called as linearity of the sensor. The linear sensors are easier to use while the non-linear sensors require complex mathematical equations to measure the physical property.

Hysteresis

The hysteresis is the characteristic of a sensor by which the sensor produces a different set of outputs if the data is recorded in different directions (increasing input or decreasing input). The hysteresis can be observed in the following figure:

sensor-characteristics-1

Calibration

If a meaningful measurement is to be made, it is necessary to tune the output of the sensor with accurately known input.

Full-Scale Output

The full-scale output is the difference between the output for maximum input and the output for minimum input. Based on this, the ADC’s reference voltages have to be selected properly.

Precision

The precision of a sensor is its ability to produce same output when repeatedly measured for the same input. The precision is determined using statistical analysis standard deviation.

Accuracy

The accuracy of a sensor defines how close the output is to the real value. The accuracy defines the maximum error the sensor may produce.

sensor-characteristics-2

References:

https://www.uam.es/docencia/quimcursos/Scimedia/chem-ed/data/acc-prec.htm

http://www.mfg.mtu.edu/cyberman/machtool/machtool/sensors/fig2.gif

FacebookTwitterGoogle+Share
Challenges without External Hardware

With the world moving towards Mobility, there are umpteen applications available in the market to capture data. However, businesses have to still largely depend on external hardware scanners to capture data related to identity. Recently, at Vmoksha we developed an application that required barcode scanner integrations. We decided to develop the application using in-app barcode scanners and initiated the project.

Let’s discuss some of the challenges we faced while using the in-app barcode scanners.

in-app barcode scanner

Focusing

Barcode-scanning applications on mobile devices rely on “display aiming,” which requires a user to find the barcode when it appears on a device screen; align the barcode with a virtual aimer, and keep still long enough for the device to focus, capture, and decode the barcode. This can delay the time taken to decode.

Integration with internal applications

Integration of application with available barcode readers can be tricky especially when customization is required. We tried integrating barcode readers in the app, where a front camera is needed for scanning. Initially, it was difficult to find readers that allow reading barcode from the front camera; but to achieve the required response time was a roadblock due to the quality of the front camera.

Quality of barcode

Almost all the in-app barcode readers fail when the barcode is damaged or distorted. The quality of the barcode degrades as the product moves along the operations or due to wear and tear. The risk of no reads can be reduced with some of the external barcode scanners, which are equipped to read the damaged barcodes.

User Experience

The speed of delivery and ease of use plays a very important role in user experience.

The above-discussed issues will impact the acceptance of the application by the customer. In-app readers would be a good choice from cosmetic aspect but external hardware scanners that can be seamlessly integrated with the application and with better speed are still better suited to bring about positive user experience. Hence, eventually, we delivered the project using external hardware scanners and successfully implemented at the client side.

Role of Scorecard in Prioritizing Feature Set & Positioning our Product among Competitors!

Vmoksha is going to launch a comprehensive Food Hygiene & Safety Management System to assist Food Manufacturers and Processors in maintaining their food safety and quality. We named it Ionhaccp to convey users that our product ensures HACCP compliance, which is a fundamental requisite for food businesses.

We thoroughly understood the requirements from the global food market and designed ionhaccp with advanced features to compete with the current key market players. Considering future trends in food safety, we also integrated IoT technology to our product, which can capture Critical Control Points to prevent food safety hazard. IoT not only simplifies the task of capturing critical data but also gives valuable infographics and sends alerts to user’s mobile devices if anything goes beyond the predefined limits.

Prior to designing our product we have analyzed different feature sets available in the market. During the process of analysis, we have given scores to each and every feature based on the feature significance and availability, which helped us in understanding the weightage and priority of the features.

Let’s see how Scorecard has helped us in prioritizing ionhaccp features & competitively positioning of our Product.

Before we start, let’s know the basics –

What is a Scorecard?

Scorecards have scores (Weights) given for each product features on the basis of their priority. The scoring method helps to rank your features and understand which features are crucial to include in your product. While there are many inputs that ultimately go into a product decision, a scoring model can help the team have an objective conversation.

Why to calculate weightage and scoring?

To have a comprehensive view of major competitors’ products, their feature set, and to identify the potential gap. Arrive at an optimum feature set to gain market share.

What is our approach to achieving that?

  • Identify the key players
  • Identify the key features
  • Comparative analysis of features
  • Develop scorecard

How we Prioritize our Product Features?

Our team has conducted a thorough research online and offline and came up with all possible set of parameters (Features) and top market leaders (Competitors). Next, we have created a table with Competitors Products and listed all features available from all the competitor products.

Scorecard

As shown in the table above, we categorized the features into different heads. Narrowing the features was based on factors that impact Operational Efficiency. Following are the factors that determine the success of an effective product.

  • Functional
  • Technical
  • Architecture
  • Support
  • Licensing & Documentation
  • User Experience
  • Pricing
  • Security
  • Market Share

 Scorecard

Figure 1 – Feature & Competitors Representation

Next Step in the competitive analysis is to figure out the list of features available or missing in all the products. Then, we have to identify the list of important features and give them scores. Scores are weightage given to each feature listed based on its operational efficiency or significance.

First, we need to give maximum values to the score column; here we have given value 5 for the features that are inevitable. This means, for any feature which is given a score of 5 is considered of high priority (5 being the maximum score). If a product feature seems of least significance, we gave it a weight of 1 (1 being the lowest score). Based on the maximum values given in the Score column, we gave weights for our competitor’s products as well as our own product for each feature listed under the head. It must be noted that a product expert team after detailed analysis of competitors should give the weightages.

Once all features are given weight on 1-5, our Scorecard table was looking like this. (The data represented in the picture are completely based on our analysis and not taken from any outside sources)

 Scorecard

After allocating the proper scores, it’s time to see the total scores obtained for each product listed. Summing up all the scores vertically gave us the total scores obtained by each product. Once it’s done, we were able to find out which player has obtained the maximum scores and see the ranks obtained by each player. This is how our scorecard total looks like after summing up.

Scorecard

Now based on the total scores obtained, we could easily determine the ranks for each product. Hence, we were capable of finding our product’s rank & thereby where our product stands among the competition. Representing scorecard details graphically or tabular format is much easier to understand. Let’s see how we showcased our scorecard details.

Scorecard

Scorecard

Scorecard  

Based on our competitive analysis and the scoring, ionhaccp will be able to offer the must-have features as identified in the scorecard and will become one of the top 3 key players in this segment.

Material Design for Android

Introduction

In 2014, Google developed a new visual design language called Material Design for Android Lollipop and higher versions. The visual specifics in material design are amusing, and the material objects have x, y and z dimensions, which allows you to create an incredible 3D world. Material design is not about how to use dazzling colors, best images, and the elevation of the object; it is about how we create the amazing experience to users with the positive brand reality.

Google has proposed some rules and regulations while adding the material design to application to improvise its standards. Instead of using a palette selection tool that pulls colors to the content of an app, using of material design makes the Android application’s graphic layout more simplified and standard format. To be noted, the material design is not only being used for rectangular or tablet screen; it should also be used for circular watch screen, etc. So if we create a grid, then it precepts all the spacing and should match to all the types of screens, which is a must for apps that are identified everywhere.

Android Material Design

Overall to say, material design is straightforward, clear and brilliant. Because of these dazzling features, it has become an imperative for a broad number of gadgets than any other UI in history.

Goals of Material Design

  • To design the application UI like a magical paper. Let’s say, something that appears like real, appreciable objects.
  • Animations have been pulled to make the experience more lively by safeguarding the maximum amount of content is always visible.
  • With Material Design, Google also determined to robotize the experience for users.
  • Mobile rules are fundamental but touch, voice, mouse, and keyboard are all excellent input methods.

The materials take energy from the users, from their fingers, from their mouse click, their touch and use it to transform and animate.

In material design, software elements are treated as real things. For example, take paper and ink. Every pixel drawn in an application is similar to a dot of ink on a piece of paper. Assume that paper is plain and doesn’t have any color whereas the ink can be of any color. So the content color of a paper depends on the color of the ink. Likewise in Android application, it can be a menu, button or image.

And also the paper can be of any size. It might fill the whole screen, or it might even shrink to small square or round shape. So the ink will not have any restrictions. It will be throughout the paper. It just has to fit inside the paper to be visible. The papers can change its shape, split, move, join and re-size. Likewise, every application made in material design will have all these characteristics.

Principles of Material Design

1.  Material is the metaphor

A material metaphor is a bring together theory of a rationalized space and a system of motion. A metaphor is a figure of speech that specifies flashy effect to one thing by observing another thing. It is open to imagination and magic.

Android Material Design

2. Surfaces are spontaneous and natural

Surfaces and edges provide visual hints that are familiarized in our knowledge of reality. The use of ordinary material attributes conveys to a primal part of our brain and advice us to quickly understand its need.

Android Material Design

3. Dimensionality supports interaction

The basics of light, surface, and movement are keys to transfer how objects cooperate. Sensible lighting shows bond, divides space, and demonstrate moving parts.

Android Material Design

4.  One flexible design

A single underlying design system establishes interactions and space. Each device follows a different view of the same fundamental system. Each view is made custom-fit to the size and interaction appropriate for that device. Colors, iconography, hierarchy, and spatial relationships stand constantly.

Android Material Design

5.  Content is bold, graphic, and wilful

Bold content provides grouping, meaning, and focus. Cautious color choices, edge-to-edge imagery, and intentional white space create captivation and clarity.

Android Material Design

6.  Color, surface, and iconography highlights actions

User action is all about the significance of experience design. Color in material design is inspired by bold complexion, deep shadows, and brilliant highlights. The whole design is reconstructed by the change of points in the immediate actions.

Android Material Design

7.  Users introduce alteration/change

Alterations in the UI extract their energy from user actions. Motion that forces from touch respects and emphasizes the user as the best mover. It means that the widgets or material takes the energy from users’ fingers during the mouse click or on touch and that energy is used to animate to show it as reality.

Android Material Design

8.  Animation is choreographed on a common step

All action takes place in one surrounding. When objects are restructured and transformed, the user will be given with the experience without collapsing the continuity of it.

Android Material Design

9.  Motion provides meaning

Motion is meaningful and convenient. It helps to focus attention and preserves continuity. The following elements assists in material design for apps of Android version 5.0 (Lollipop) or higher.

Android Material Design

Themes

The material theme is defined as,

@android:style/Theme.Material (dark version)

@android:style/Theme.Material.Light (light version)

@android:style/Theme.Material.Light.DarkActionBar

Android Material DesignAndroid Material Design

 

To use the material theme in your apps, customize the color palette as shown below,

<resources>
<!-- inherit from the material theme -->
<style name="AppTheme" parent="android:Theme.Material">
<!-- Main theme colors -->
<!-- your app branding color for the app bar -->
<item name="android:colorPrimary">@color/primary</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="android:colorPrimaryDark">@color/primary_dark</item>
<!-- theme UI controls like checkboxes and text fields -->
<item name="android:colorAccent">@color/accent</item>
</style>
</resources>

The following example describes how to add material design to a button

styles.xml

<resources>
<!-- Base application theme. -->
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<!-- Customize your theme here. -->
<style name="MyButton" parent="Theme.AppCompat.Light">
<item name="colorControlHighlight">@color/calbutton_focus</item>
<item name="colorButtonNormal">@color/background_color</item>
</style>
</resources>

activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height=" match_parent ">

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:theme="@style/MyButton"
android:layout_gravity="center"
android:text="Click"
android:textAllCaps="true"
android:textColor="@color/white"/>

</LinearLayout>

Cards and Lists

Cards and Lists are the two new widgets in Android with material design styles and animation. To create cards and Lists, RecyclerView can be used, which is introduced from Android version 5.0 (Lollipop). It is an adoption of ListView, which supports various layout types and contributes performance improvements. Part of data can be shown inside the card with a constant look over apps in CardView.

An example shown below demonstrates how to add a CardView in your layout.

 

build.gradle

dependencies {
// CardView
compile 'com.android.support:cardview-v7:23.3.+'
}

activity_card.xml

<android.support.v7.widget.CardView
android:id="@+id/card_view"
android:layout_width="200dp"
android:layout_height="200dp"
card_view:cardCornerRadius="3dp">
...
</android.support.v7.widget.CardView>

 

To use RecyclerView widget in your layout, necessary attribute is shown below,

build.gradle

dependencies {
// RecyclerView
compile 'com.android.support:recyclerview-v7:23.1.1
}

activity_main.xml

<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:scrollbars="vertical" />

Android Material Design

Floating Action Button

Another interesting widget introduced in material design is floating action button.  This button floats on UI in a circular shape with an action attached to it. By default, its behavior is to animate on the screen as an expanding piece of material.

We can also provide shadows and elevation to the buttons. The distance between surfaces and the depth of its shadow signifies elevation. To set the elevation of a view, use the android:elevation attribute in your layouts. The bounds of a view’s background drawable determine the default shape of its shadow.

In addition to the X and Y properties, views in Android material design now have a Z property. This new property serves as the elevation of a view, which concludes the size of the shadow i.e., a view with greater Z values launches bigger shadows.

< android.support.design.widget.FloatingActionButton
android:id=”@+id/my_floatbutton”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android: layout_gravity="top|end”
android: src="@android:drawable/ic_add”
android:background=”@color/white”
android:elevation="5dp" />

14

build.gradle

dependencies{
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
}

activity_main.xml

<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android: layout_width="wrap_content"
android: layout_height="wrap_content"
android: layout_gravity="bottom|end" // position the floating button
android: layout_margin="@dimen/fab_margin"
android: src="@android:drawable/ic_dialog_email"/>

You can also define own background color for floating button using app:backgroundTint. The size of the button can also be defined by using app:fabSize attribute.

15

CollapsingToolbarLayout

A new widget called CollapsingToolbarLayout was also introduced from Android version 5.0 (Lollipop). This comes with an amazing animation; whenever a user scrolls up the control provides the fabulous animating effect. According to the Android documentation, CollapsingToolbarLayout is a wrapper for Toolbar which implements a collapsing app bar. It makes the header image collapse into the Toolbar, adjusting its title size and it is designed to be used as a direct child of an AppBarLayout.

To add CollapsingToolbarLayout to your layout, see the following,

build.gradle

dependencies{
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
}

activity_main.xml

<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
.....
.....
</android.support.design.widget.CollapsingToolbarLayout>

16

Conclusion

Google developed material design to bring together the user experience from different Google platforms. Totally, material design made the user interaction smooth, simpler and greater intuitive. When you think about material design, it has so many technologies, which will only create the impression for users while using apps during interactions. The physical world is the very big part of the material design. So all in all, what do you think of Material Design in Android? Don’t you think it’s the best part to unite and enhance the user experience while using the Android application?

Displaying Listings Similar to Search Results

Searching for similar things/places based on some parameters is quite normal in the current online world. Therefore, displaying listings that are similar to what users are looking for is a must for businesses and throws a challenge for developers. Here, I have explained a scenario taking Real Estate web application as an example.

Example

A real estate web application has multiple property listings where a user will search for one property and would like to explore similar properties in that particular area. In this scenario, we need to display all the properties based on Geo Location and Zip Code.

Prerequisites

 Save the Geo-Location (Latitude and Longitude) and Zip Code of the Property while it is listing.

Property Listing and Validation

Step 1:

Before updating any property, we should get inputs from user:

1) Street Line 1

2) Street Line 2

3) City

4) State

5) Country

6) Zip Code

Step 2:

Get Geo Location (i.e. Latitude and Longitude)

a) By Address:

//calling Google maps API for fetching Geo-Location Based on address

"https://maps.googleapis.com/maps/api/geocode/json?address=" + <FullAddress> + "&sensor=true&key=" + <GoogleApiKey>

SimilarListings[1]

b) By Zip Code and Country Code:

//calling Google maps API for fetching Geo Location Based on Country Code and Zip code

"https://maps.googleapis.com/maps/api/geocode/json?components=country:" + <Country> + "|postal_code:" +  <pincode> + "&sensor=true&key=" + <GoogleApiKey>;

Step 3:

Validating Zip Code:

The two Geo Locations needs to be compared by taking approximate round off values, and if both of them matches then we allow a user to move to the next step else we should clear zip code field and give an alert message like ‘wrong zip code entered’.

Step 4:

Save the Latitude and Longitude into the Address Table.

 

Implementation

To display similar listings when a user clicks on similar property option, the below process needs to be followed:

Step 1:

We will get below input parameters of the clicked property listing:

1) Latitude

2) Longitude

3) Price Range (Min and Max)

4) Zip Code

Step 2: (Optional based on application requirement)

In addition to Step 1, we should add two more input parameters

1) Distance Unit ( Constant  : 111.045 km per degree & 69 statute miles per degree or 60 nautical miles per degree & 552 furlongs per degree)  ~ 12.92297284

2) Radius (Km Radius) ~ 05.0

Step 3:

By gathering input parameters from step 1 & 2, call custom API, get dataset and bind back to the UI.

The Custom API is responsible for below operations

1) Taking Input parameters

2) Querying Database and fetching data from property table based on the input parameters

3) Sending the result dataset back to the client

Result

End user will be able to see various Similar Property Listings which falls under below criteria of the clicked property

1) Within Price Range (Min & Max)

2) Within 5 Km Radius of the Geo Location (Latitude and Longitude)

3) With Same Zip Code

Conclusion

The above process can be used for various applications to implement similar search. However, the search criteria can be changed based on the requirement.

Sending Exception Detail as Email through AWS SES

Amazon Simple Email Service (Amazon SES) is a highly scalable and cost-effective email service for developers and businesses. Amazon SES eliminates the complexity and expenditure of building an in-house email solution or licensing, installing, and operating a third-party email service for this type of email communication. In addition, the service integrates with other AWS services, making it easy to send emails from applications being hosted on AWS.

Prerequisites

  1. AWS SES
  2. AWS SNS
  3. AWS S3
  4. AWS Lambda

Requirement

When a user uploads an excel file to web console, each row data from the excel file should save into the database. If this process got failed due to some exception, the exception error message must go to the configured email Id’s.

Workflow

We are using two lambda functions. One is used for uploading excel sheet to s3 bucket and another for sending exceptional email to administrator.

When we are uploading excel sheet to s3 bucket, if any failure or exception occurs in that time, Excel upload lambda function will send the error result to SNS (Simple Notification Service) and Exception email lambda function will trigger the SNS and send an exceptional email to the administrator by using SES.

Solution

Setting up Prerequisites

1) AWS SNS

Create a SNS Topic by following below steps,

  1. Open AWS account à choose services as SNS
  2. Click on Create Topic à give the Topic name and Display Name
  3. Click on Create topic

2) AWS S3 Bucket

Create an AWS S3 Bucket with add permission and enable CORS configuration.

3) AWS Lambda

Two Lambda functions are required:

i) For reading excel file and saving each row data into concerned database

a)   Create the lambda function using below code:

var s3file = s3.getObject(params,function (err,data){

if(err){

result.message = 'error while getting ' + key + 'from' + bucketName +' bucket name';

result.describtion = err;

context.fail(result);

}else{

var wstream = fs.createWriteStream('/tmp/user.xlsx');

wstream.write(data.Body , function(err){

if(err){

console.log(err);

} else{

exceltojson({

input: '/tmp/user.xlsx',

output: null,

},function(err, rest) {

if(err) {

result.message = 'error while reading the'+key+ ' file from '+bucketName;

} else{

maxCount = rest.length;

console.log('max count f rows in excel/cvs file = ' + maxCount);

ExcelData = rest;
}

}

}

b)   Upload the Zip file containing NodeJS Code, which holds logic for reading the excel file and pushing each row data into the concerned database by calling custom API.

c)   Map AWS Lambda Trigger to AWS S3 when putObject() method invoked inside AWS S3.

 

ii) To send the exception email

a)   Create lambda function using below code:

var ses = new aws.SES({

apiVersion: '2010-12-01'

});

// Generating params to send Email

var params = {

Destination: {},

Message: {

Subject: {

Data:Subject,

Charset: 'UTF-8'

},

Body: {

Html: {

Data: message,

Charset: 'UTF-8'

}

}

}

};

params.Destination.ToAddresses = [emailTOAddress];

params.Source = FromAddress;

// calling send email function

ses.sendEmail(params, function (err, data) {

if (err) {//failure message

result.message = err, err.stack;

console.log(result);

context.fail(result);

} else {//Sucess

result.message = 'Email send successfully';

result.data = data;

console.log(result);

context.succeed(result);

}

});

b)  Map AWS Lambda Trigger to AWS SNS topic when any exception occurs in the first lambda function i.e. while saving each row of excel file into the database.

Implementation

Step 1: Upload the excel file directly into AWS S3 bucket manually or through AWS SDK

Step 2: If everything goes well, all the records from excel file will be saved into database. Else an email will go to the configured (admin) email id with exception details

Conclusion

Based on the configuration and given excel file, records will be saved into the database and if any exception occurs then it will go as an email to the admin (configured email).

 

Solutions Infini SMS gateway integration using Node.js, AWS lambda & API Gateway

AWS lambda

AWS Lambda runs your code on a high-availability compute infrastructure and performs all of the compute resource management including the operating system and server maintenance, automatic scaling and code monitoring, capacity provisioning, etc., which makes it ideal for sending messages.

Node.js Support

The AWS SDK for Node.js enables developers to build libraries and applications that use AWS services. You can use the JavaScript API in the browser and inside Node.js applications on the server.

API Gateway

Amazon API Gateway manages all the tasks involved in accepting and processing up to hundreds of thousands of concurrent API calls, including authorization and access control, traffic management,  monitoring, and API version management.

Requirement

Sending an SMS based on the request parameters through API call.

Prerequisites

  • AWS lambda function
  • API Gateway
  • Node.js

Solution

sms gateway

The following Steps are required for implementing the above flow chart:

Step 1: Create a Lambda function using the below code.

var globalTunnel = require('global-tunnel');

var aws = require("aws-sdk");

var solutionInfiApiUrl = “http://alerts.solutionsinfini.com/api/v3/index.php?method=sms.json&api_key=” + <APIKey>;

var request = require('request');

//initializing Json request

              var Json = {};

              Json.sender = <Sender Number>;

              Json.message = <Message>;

              Json.format = 'json';

              Json.flash = 0;

              Json.sms = [];

              var receiver = {}

              receiver.to =<receiver Number>;

              Json.sms.push(receiver);

                var body = JSON.stringify(Json);                     

              // making POST request to send SMS

              request.post({

                       url:  solutionInfiApiUrl,

                       body:   body

                  }, function(error, response){

                 if (error) {

                     result.message = 'Send SMS faild'

                       result.error = error ;

                             context.fail (result);

}

                else{

                   result.message = 'SMS sent Successfully to ' + phoneMumber;

                   console.log('response' +  JSON.stringify(response));

                     context.succeed(result);

                 }

           }); 

Step 2: Create an API Gateway and add mapping of above lambda function.

Step 3: Test the API through Postman (Chrome App) by passing the below request parameters.

Request Format Type:  JSON 

      Method:  POST.

{

 "PhoneNumber": "<ReceiverMobileNumber>",

 "ProjectName": "<ProjectName>",

 "PropertyName": "<PropertyName>"

}

Conclusion

Using solutions inifini, we can create multiple Dynamic templates as well as a static template. Hence, we can send both dynamic and static SMS through AWS for the given phone number.

 

Elastic Search Query to Retrieve Records from Elastic Server

Elastic Search is an open-source search tool that is built on Lucene but natively it is JSON + RESTful. Elastic Search provides a JSON-style domain-specific language which can be used to execute queries, and is referred as the Query-DSL.

The search API allows us to execute a search query and get back search hits that match the query. Elastic search will fetch the records at lightning speed because of schema-less table structure. The query can either be provided using a simple query string as a parameter or using a request body.

Here I am showing how to write queries for Elastic search with some good set of standard queries as an example.

 

Basic Queries Using Only the Query String

Basic queries can be done using only query string parameters in the URL. For example, the following searches for the text ‘test’ in any field in any document and return at most 5 results:
{ElasticURL}/_search?size=5&q=test

 

Full Query API

Full Queries are powerful and complex ones which include queries that involve in faceting and statistical operations and should use the full elastic search query language and API. The queries are written as JSON structure in the query language and sent to the query endpoint (query language details are given below). There are two options to send a query to the search endpoint:

1. Either as the value of a source query parameter e.g. :

{ElasticURL}/_search?source={Query as JSON}

2. Or in the request body, e.g.,

{
     "query" : {
         "term" : { "PropertyName": "test" }
     }
 }

From & Size in Query

Pagination of results can be done by using the ‘from’ and ‘size’ parameters. The ‘from’ parameter defines the offset from the first result we want to fetch. The ‘size’ parameter allows us to configure the maximum amount of hits to be returned.

{
     "size" : 10,
     "from" : 0,
     "query" : {}
 }

Sample response from Elastic server

{
  "took": 7,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 4,
    "max_score": 4.5618434,
    "hits": [
      {
        "_index": "ph_property",
        "_type": "property",
        "_id": "10322",
        "_score": 4.5618434,
        "_source": {
          "PropertyID": 10322,
          "PropertyCode": "VTELD21NGXKK3V02GJRLPRROB",
          "BuilderCode": "BY67DP",
          "BuilderName": "Janet Spencer",
          "PropertyName": "AWS test",
          "BHK": "",
          "PropertyTypeCode": "DO20ET",
          "PropertyType": "Residential Land"
        }
      }
    ]
  }
}

Query DSL Examples

1. Match all/Find Everything

{
     "query" : {
         "match_all" : { }
     }
 }

2. Filter on one field

{
     "query" : {
         "term" : { field-name: value }
     }
 }

3. Match with a field

{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "field": "value"
          }
        }
      ]
    }
  }
}

4. Multi-match query builds on the match query to allow multi-field queries

{
  "multi_match" : {
    "query":    "this is a test",
    "fields": [ "subject", "message" ]
  }
}

5. Find documents which consist the exact term specified in the field specified

{
  "query": {
    "bool": {
      "should": [
        {
          "term": {
            "status": {
              "value": "urgent"
            }
          }
        },
        {
          "term": {
            "status": "normal"
          }
        }
      ]
    }
  }
}

6. Find documents, where the field specified consist values (strings, numbers, or dates) in the range specified

{
  "size": "9",
  "query": {
    "bool": {
      "must": [
        {
          "range": {
            "BudgetFrom": {
              "gte": 50000
            }
          }
        },
        {
          "range": {
            "BudgetTo": {
              "lte": 2231346
            }
          }
        }
      ]
    }
  }
}

7. The filtered query is used to combine a query that is used for scoring with another query that is used for filtering the result set.

{
  "filtered": {
    "query": {
      "match": { "tweet": "full text search" }
    },
    "filter": {
      "range": { "created": { "gte": "now-1d/d" }}
    }
  }
}

8. Filters documents that only have the provided ids.

{
    "ids" : {
        "type" : "my_type",
        "values" : ["1", "4", "100"]
    }
}

9. Filters documents that are matching the provided document/mapping type.

{
    "type" : {
        "value" : "my_type"
    }
}

10. Filter on two fields

{
    "query": {
        "filtered": {
            "query": {
                "match_all": {}
            },
            "filter": {
                "and": [
                    {
                        "range" : {
                            "b" : { 
                                "from" : 4, 
                                "to" : "8"
                            }
                        },
                    },
                    {
                        "term": {
                            "a": "john"
                        }
                    }
                ]
            }
        }
    }
}

An actual example with some search parameter:

{
  "from": "0",
  "size": "9",
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "ProjectTypeCode": "EQ92JK"
          }
        },
        {
          "match": {
            "PropertyStatusCode": "AS82IZ"
          }
        },
        {
          "match": {
            "PropertyTypeCode": "SJ85GF"
          }
        },
        {
          "match": {
            "MicroMarketCode": "DX60DL"
          }
        },
        {
          "range": {
            "SizeFrom": {
              "gte": 1000
            }
          }
        },
        {
          "range": {
            "BudgetFrom": {
              "gte": 50000
            }
          }
        },
        {
          "range": {
            "BudgetTo": {
              "lte": 2231346
            }
          }
        },
        {
          "range": {
            "PossessionDate": {
              "gte": "2016-01-01"
            }
          }
        },
        {
          "match": {
            "City": "Bengaluru"
          }
        }
      ]
    }
  }
}

Conclusion

These are the few frequently used queries to retrieve the data from Elastic server. However Elastic Search response can be retrieved using various other queries like Geo queries, joining queries, compound queries, specialized queries, etc. We can even join multiple queries to get the hits from elastic server. The response we get from Elastic Server is very fast compared to MySQL/Sql Server queries and hence it is now being used widely.

Source Code Generation using Razor Template Engine for Both Client Side and Server Side

Automating Source code generation can be surprisingly easy and will reap major benefits. It will help you develop 90% of the API’s for any project in just a button click. The primary benefits of automating source code generation are shown below in the form of a Bar chart.

AWS Source Code Generation

Explanation

Creating dynamic source code (Controller, facade, and Dao including interfaces) using code templates and razor template engine.

Steps to be followed to generate controller code are as follows

1. Create a controller template and keep only the common operations. Rename the file with extension as .txt.

2. Inside the file, where ever the Entity name is there replace it with razor template code (@Model.Entity). Assume Entity is your “table name” which will be given as  input parameter in reality.

3. Create a model object of dynamic type (refer email sending template in our solution)

4. Then bind data in the template like

var result = Utilities.BindDataInTemplate(template, “reg-email”, input.User as Object); Here BindDataInTemplate functions which is written in utilities file, binds the data in the template.

5. Save the result string as “.CS” Controller.cs.

The above similar steps are followed to generate other source code (facade and Dao including interfaces).

Details of API to generate server side dynamic source code 

API URL : http://localhost:53154/api/controller/create

Method Type : POST

Request :

{

"Entity": "Table name",

"Author": "User name";

}

 

Details of API to generate client side dynamic source code 

(simple html,route.js,module.js,controller.js,service.js)

API URL : http://localhost:53154/api/controller/create/js

Method Type : POST

Request :

{

"Entity": "Table name",

"Author": "User name",

"ControllerDescription" : "Description for Controller.js"

"ServiceDescription"    : "Description for Service.js"

"FilePath"              : "FilePath (Example: "E: Angulartemplate")";

}

  

Reference : Please refer trick#2 in the below link for using code templates and razor template engine

http://odetocode.com/blogs/scott/archive/2013/01/09/ten-tricks-for-razor-views.aspx.

Conclusion

Reliability, availability, productivity, performance, and cost reduction are powerful arguments for adopting automation solution. It helps you to create over 90% of the API’s that are required for an application. However, the tool generates code for API’s with common operations i.e. Save/Update, GetById, GetAll, Search, Search with Pagination and Delete. The API’s which are specific to the application should be taken care.

 

Automating Deployment of AWS Lambda

AWS Lambda is a compute service that lets you run code without provisioning or managing servers. AWS Lambda executes your code only when needed and scales automatically, from a few requests per day to thousands per second.

Deploying Codes into AWS Lambda through AWS Web Console is insecure and time taking, since every time user needs to login into AWS Lambda console and then they have to upload the zip file or need to provide AWS S3 file path manually. To overcome this issue, there is a very simpler way to automate the deployment process as shown in the below flow chart.

Automating-Deployment-of-AWS-Lambda

Setup and Configuration:

Step 1: Create an AWS Lambda function and deploy the below zip file into it,

https://github.com/avinashl3175/Vm_BlogContent/blob/master/Deploying_Lambda.zip

Step 2: Enable Lambda trigger with AWS S3 bucket when putObject method is invoked. Both S3 and Lambda Function should be in same region.

Step 3: Enable Versioning inside AWS S3 Bucket.

Step 4: Create a config.json file using any of the below configurations,

a) For Deployment into a new Lambda Function:

{

"accessKeyId" : "< AccessKeyId >",

"secretAccessKey": < SecretAccessKey >",

"region": "<Region>",

"lambdaFunctionName" : "<LamdaFunctionName>",

"lambdaFunctionType":  "new",

"lambdaHandler":"index.handler",

"lambdaRole":"<ARN Name>",

"lambdaRuntime":"nodejs4.3",

"lambdaDescription":"<Description>"

}

b) For Deployment into an old Lambda Function:

{

"accessKeyId" : "< AccessKeyId >",

"secretAccessKey": < SecretAccessKey >",

"region": "<Region>",

"lambdaFunctionName" : "<LamdaFunctionName>",

"lambdaFunctionType":  "old"

}

Step 5: Make a zip file containing following file(s)

a) Lambda code written in nodejs (index.js)

b) Node Modules folder (node_modules)

c) Other Relevant files

 

Deploying into AWS Lambda:

You can deploy the lambda code into any of the existing Lambda function or a new Lambda function anytime.

Steps needs to follow

Step 1: Push config.json file into AWS S3 bucket where trigger event mapping is done.

Step 2: Make the visibility of config.json file as public.

Step 3: Push <Lambda>.zip file into AWS S3.

Step 4: Deployment of lambda function will be done according to your config.json file. To verify it, go to the AWS Cloud Watch Console and go through the logs.

Note:  Copying files into AWS S3 can be done in two ways,

a) Copying file by login into AWS S3 Web Console.

b) By invoking putObject() method by using AWS SDK (Platform Independent).

Conclusion:

The Zip file pushed into AWS S3 will be deployed into AWS lambda according to the configuration file (config.json). The automation of lambda function deployment can be configured for any AWS account.