JSON REST API and Open Weather Map Microservices

JSON REST API

JSON REST API is a system container that provides a restful endpoint and allows to transform the data generated by a microservice.

The config for the container should look in the following way:

{"buffersize":3,"contentdataencoding":"utf8","contextdataencoding":"utf8","outputfields":{"publisher":"source","contentdata":"temperature","timestamp":"time"}}

Config explanation:

{"buffersize":3} - this instructs the microservice to show last 3 messages

"publisher" - the uuid of ms sent messages

"contentdata" - message format

E.g. if we route the microservice with Open Weather Map microservice, this will allow to access the weather data in a browser or in any other application or any device cloud.

Open Weather Map

Open Weather Map is a system container that retrieves the data from https://openweathermap.org/.

The config for the container should look in the following way:

{"citycode":"5391997","apikey":"6141811a6136148a00133488eadff0fb","frequency":1000}

Config explanation:

"citycode" - the code of the city

"apikey" - the api key of open weather map

"frequency" - the frequency of message sending in millis

Launching the Containers

Enter iofog-controller user add -f first-name -l last-name -e email -p password in terminal.

Enter iofog-controller flow add -n name -d description -a -u user-id in terminal.

Enter iofog-controller iofog add -n name -l location -t latitude -g longitude -d description -D docker-url -M disk-limit -T disk-directory -m memory-limit -c cpu-limit -G log-limit -Y log-directory -C log-file-count -s status-frequency -F change-frequency -Q device-frequency -B -w -a -y fog-type -u user-id in terminal.

Enter iofog-controller iofog provisioning-key -i node-id in terminal.

Enter iofog-agent provision {provision-key}.

iofog-controller microservice add -n jsonRestApi -c 7 -F flow-id -I iofog-uuid -g '{"buffersize":3,"contentdataencoding":"utf8","contextdataencoding":"utf8","outputfields":{"publisher":"source","contentdata":"temperature","timestamp":"time"}}' -R -p 80:5555 -u user-id

iofog-controller microservice add -n weather -c 6 -F flow-id -I iofog-uuid -g '{"citycode":"5391997","apikey":"6141811a6136148a00133488eadff0fb","frequency":1000}' -R -u user-id

iofog-controller microservice route-create --route openweather-uuid:jsonrestapi-uuid

catalog-id = 7 (JSON REST API)

catalog-id = 6 (Open Weather Map)

Request

$ curl localhost:5555

Response

[
  {
    "source": "CmdxYrfZmPRLTH7rXMwKpW92zRHtggxw",
    "temperature": "{\"coord\":{\"lon\":-122.45,\"lat\":37.77},\"weather\":[{\"id\":801,\"main\":\"Clouds\",\"description\":\"few clouds\",\"icon\":\"02n\"}],\"base\":\"stations\",\"main\":{\"temp\":279.46,\"pressure\":1028,\"humidity\":65,\"temp_min\":276.45,\"temp_max\":282.55},\"visibility\":16093,\"wind\":{\"speed\":1.5,\"deg\":320},\"clouds\":{\"all\":20},\"dt\":1548161760,\"sys\":{\"type\":1,\"id\":5817,\"message\":0.0037,\"country\":\"US\",\"sunrise\":1548170436,\"sunset\":1548206570},\"id\":5391997,\"name\":\"San Francisco County\",\"cod\":200}",
    "time": 1548163407511
  },
  {
    "source": "CmdxYrfZmPRLTH7rXMwKpW92zRHtggxw",
    "temperature": "{\"coord\":{\"lon\":-122.45,\"lat\":37.77},\"weather\":[{\"id\":801,\"main\":\"Clouds\",\"description\":\"few clouds\",\"icon\":\"02n\"}],\"base\":\"stations\",\"main\":{\"temp\":279.46,\"pressure\":1028,\"humidity\":65,\"temp_min\":276.45,\"temp_max\":282.55},\"visibility\":16093,\"wind\":{\"speed\":1.5,\"deg\":320},\"clouds\":{\"all\":20},\"dt\":1548161760,\"sys\":{\"type\":1,\"id\":5817,\"message\":0.0037,\"country\":\"US\",\"sunrise\":1548170436,\"sunset\":1548206570},\"id\":5391997,\"name\":\"San Francisco County\",\"cod\":200}",
    "time": 1548163408502
  },
  {
    "source": "CmdxYrfZmPRLTH7rXMwKpW92zRHtggxw",
    "temperature": "{\"coord\":{\"lon\":-122.45,\"lat\":37.77},\"weather\":[{\"id\":801,\"main\":\"Clouds\",\"description\":\"few clouds\",\"icon\":\"02n\"}],\"base\":\"stations\",\"main\":{\"temp\":279.46,\"pressure\":1028,\"humidity\":65,\"temp_min\":276.45,\"temp_max\":282.55},\"visibility\":16093,\"wind\":{\"speed\":1.5,\"deg\":320},\"clouds\":{\"all\":20},\"dt\":1548161760,\"sys\":{\"type\":1,\"id\":5817,\"message\":0.0037,\"country\":\"US\",\"sunrise\":1548170436,\"sunset\":1548206570},\"id\":5391997,\"name\":\"San Francisco County\",\"cod\":200}",
    "time": 1548163409419
  }
]