Weather Alert & Assistance
Tags: mulesofthackathon, weatherforcastapi, mulesoft, showdev
Published: 2020-11-09 15:57:13



# Everyday is an API day

Welcome to weather alert application inspired by the mulesoft integration platform which provides an easy way to integrate multiple APIs, call in parallel, Apply transformation and aggregate the result to expose as a single API.
While going for outdoor activities or outside travel, knowing weather conditions is a must. Sometimes we gone through sudden weather changes which put us in trouble. Getting assistance is very difficult in unfavorable situation whether the place is known or unknown. No worry this application has been designed to Keep in mind to provide help whenever you need . 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/m17j6ne7ph77e3roslyp.jpg)

## What is weather, Air quality and weather-alert Api?

 There are various APIs are available that provide weather information & Air quality level. These APIs are available in a rest or Soap format but it's in bits and pieces.

**openweathermap** provides essential weather parameters such as temperature, precipitation, probability of precipitation, humidity, feels like, pressure, cloudiness, wind, etc.

**aircheckr** provides the available outside air quality information of the particular location.

**weather-alert** provides the recommendation based on outside available air quality and weather information. This application, runs a custom algorithm to derive recommendations based on the permissible limit of human life. It also allow user to send an alert at the time when situation is not in his favor and need help. Alert response includes message, weather condition and current location of the needy people.
     > For visualization and demonstration purposes web UI has been used. In real implementation it would be a mobile application. User location will be auto detected and alert generated in abnormal situation.    
 
About the mule-weather-alert application
------------------------------------------------------------------

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/xw1aajmytlt4ophfp39j.jpg)

In this application we have collected information from various sources of(Weather & Air) API and run a custom algorithm to provide weather & Air recommendation. 
Weather & Air provides information like temperature, visibility, humidity, wind speed, direction and air quality. By applying a custom algorithm we calculate heat index, wind index, Recommendation(Non-Sensitive Group) and Recommendation(Sensitive Group). All calculations are based on current location or provided location(by latitude and longitude).
It also has the capability to send an alert or notification to your near and dear when you are in trouble and you are seeking for a help. 
In an alert response we  send custom messages, weather information and geo location so that you would get assistance as soon as possible. Geo location helps to traverse exact locations on map and and surrounding weather information. It helps to understand the kind of help you need. Rescuer can prepare a better plan using this information. 

1. API Specification (RAML)
------------------------------------------------------------------
/weather-app:
  /get-weather-data:
      This end point is used to forecast weather information by clubbing weather and Air quality api. Latitude and longitude of current and provided location received in request. The  response includes details of temperature, visibility, humidity, wind speed, direction and air quality. Based on our analysis calculate heat index, wind index, Recommendation(Non-Sensitive Group) and Recommendation(Sensitive Group)

/weather-app:
   /send-email-alert:
      This end point is used to send an alert. When we come to know that our surrounding weather is not appropriate and we need help from our loved ones. API receives message & email of the person to be notified and detects the coordinate of your location  and sends the alert. email details and message receive in request and alert sends with message, current weather information and google link of the location. confirmation message send as a response.

```
#%RAML 1.0
baseUri: https://anypoint.mulesoft.com/mocking/api/v1/links/65f94373-f769-4504-89e5-67ac9da63ede/ # 
title: weather-alert-specification
types:
  alert:
    type: Alert
  Alert:
    properties:
      email: string
      message: string
    
/weather-app:
  /get-weather-data:
    get:
      description: This end point is used to forecast weather information by clubbing weather and Air api. Latitude and longitude of current and provided location received in request. The  response includes details of temperature, visibility, humidity, wind speed, direction and air quality. Based on our analysis calculate heat index, wind index, Recommendation(Non-Sensitive Group) and Recommendation(Sensitive Group)
      queryParameters:
        latitude:
          type: string
          example: "51.5052986145"
        longitude:
          type: string
          example: "0.0552779995"
      responses:
        200:
          body:
            application/json:
              
              example: !include examples/weather-api-response.raml
  /send-email-alert:
    post:
      description: This end point is used to send an alert. When we come to know that our surrounding weather is not appropriate and we need help from our loved ones. API receives message & email of the person to be notified and detects the coordinate of your location  and sends the alert. email details and message receive in request and alert sends with message, current weather information and google link of the location. confirmation message send as a response.
      body:
        application/json:
          type: alert
          example: !include examples/alert-request.raml
            
      responses:
        201:
          body:
            application/json:
              example:
                {
                "response": "Alert sent successfully"
                }

          
          
```
2. API Implementation (Mule application)
------------------------------------------------------------------

**Home page** : A html web page where either we can provide a location as latitude and longitude and submit button _**Use This Location**_ or _**Use Current Location**_ for auto detect current location 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/d988hgb967l61hy3hxuv.png)

**get-weather-data** : A mule flow receive _GET_ request with query parameter latitude and longitude. Based on latitude and longitude weather and Air quality has been called. weather and Air quality information send as a json object in response. Web page show the detail data.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/8u6vq65w7btmkvqpvifu.png)

**send-email-alert** : A mule flow is being trigger as a _POST_ with payload having email id and message to be sent to the notified person with the location of the notifier.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/bjausoejdt65u9ehaa08.png)

`**Note**` : Update email user name and password in configuration file.

3. Test application
------------------------------------------------------------------
CloudHub URL :[Home page](http://weather-alert-project.us-e2.cloudhub.io/weather-app/home)
**Note** 
1. *For quick demo use latitude:51.5052986145 & longitude :0.0552779995*
2. If you face issue when use current location, use work around given here
[Enable the unsecure origin](https://medium.com/@Carmichaelize/enabling-the-microphone-camera-in-chrome-for-local-unsecure-origins-9c90c3149339)

`**Home page**`

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/b24tpa5vmqth02al81iy.png)
------------------------------------------------------------------
------------------------------------------------------------------
`**Weather detail page**`

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/3k4amg12qulwlkcam32m.PNG)
------------------------------------------------------------------

`**Alert page**`

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/v6mb9idnptu9dfpibp3a.png)
------------------------------------------------------------------

`**Email detail**`

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/fry8o5f9gil7dp555xqv.png)
------------------------------------------------------------------

------------------------------------------------------------------

### Color visualization

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/oc45z0q0bh0kisbs4q0f.PNG)

4. References and Code  
------------------------------------------------------------------
[Source code refrence](https://github.com/mukesh-aec/repo_mule_weather_alert)
[Clone](https://github.com/mukesh-aec/repo_mule_weather_alert.git)

[Asset (RAML) refrence](https://anypoint.mulesoft.com/exchange/portals/persistent-system-87/7e5bda23-008c-484b-ac78-ee4a3416ac7c/mule-weather-alert-specification/)

5. About the author  
------------------------------------------------------------------
Mukesh Thakur worked as a solution Architect at Persistent System Ltd. He is a hands on Technology evangelist & Integration Architect with expertise in conceptualizing and implementing end to end solutions. He has the right blend of Developer, Architecture, Technology Consulting, agile practitioner and diverse cultural experiences gained through the implementation experiences across complex Integration roll outs around the globe. He also leads Pune MuleSoft Meetup and loves to speak in various meetup events.
Email me: [mukesh.aec@gmail.com]()
LinkedIn: [https://www.linkedin.com/in/mukesh-thakur-3b9720a/]()
DZone: [https://dzone.com/users/3365003/mukeshaec.html]()