Fieldclimate JSON API V1

Contents

 

Fieldclimate JSON API V1. 1

Introduction. 2

About  JSON.. 4

Authentication. 5

API Methods. 5

API Keys. 5

PESSL JSON Library v.02. 7

The "Hello, World" of Fieldclimate JSON API V1. 8

Reading the List of Stations. 10

Getting Configuration of Station. 13

Getting Sensors Info. 18

Getting Weather Data. 21

Disease Models and Weather Forecast. 29

API Reference. 31

For developers. 31

 


 

 

Introduction

This API allows anyone to write applications that interact with Fieldclimate JSON API. You can get started by checking out the API Methods .

The API consists of a set of callable methods and API endpoints. The arguments, responses, and error codes for each method are described.

rest

To perform an action using API, send a request (specifying a method and some parameters) to an API endpoint. A response will then be sent back to you.

All requests take a list of named parameters.

The REST format is a simple JSON-based protocol - it is a conventional HTTP GET or POST action.

The  REST endpoint URL is  http://www.fieldclimate.com/api/

For example, to request the CIDIStationList_GetFirst service, you would invoke the following:

1.      http://www.fieldclimate.com/api/CIDIStationList/GetFirst  (Friendly URL)

2.      http://www.fieldclimate.com/api/index.php?action=CIDIStationList_GetFirst

The required parameter action is used to specify the method to be called.

example1

All responses are returned in JSON format. By default, character encoding is UTF-8.

Successful Response

{"ReturnDataSet":[
{"f_station_code":"282",
"f_date":"2009-04-20 12:07:21",
"f_dev_id":"1",
"f_name":"00000146",
"f_descr":"imetos avr","f_info":"\r\nImetos 1 software: 02.55  hardware: 01.00  compiled: Apr 23 2009 12:23:00",
"f_uid":"2147483647",
"f_status":"0",
"f_create_time":"2007-01-22 08:59:42",
"f_master_name":null,
"f_date_min":"2005-03-08 12:50:00",
"f_date_max":"2010-10-11 02:20:00",
"f_date_last_down":"2010-10-11 01:22:40",
"f_date_sens":"2010-05-20 12:30:50.625755",
"f_date_data":"2010-01-24 19:02:12.19124",
"f_date_conf":"2010-10-11 03:22:40.462109",
"f_sernum":"326",
"f_timezone":"60",
"f_latitude":"47.2055",
"f_longitude":"15.63507",
"f_altitude":"443",
"f_date_comm":1286756560,
"f_user_station_name":"Pessl Instruments Company Weather '\u00b4\u00b4",
"f_user_name":"Pessl Instruments Company Weather '\u00b4\u00b4"}],
"ReturnParams":{"row_count":"1","station_code":1}}
 

Failure Response

{"faultcode":5,
"faultactor":"CIDIStationList",
"faultstring":"No rights",
"faultdetail":"CIDIData interface error"}
 

 

About  JSON

JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate.

JSON is built on two structures:

    * A collection of name/value pairs. In various languages, this is realized as an object, record, struct, dictionary, hash table, keyed list, or associative array.

    * An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence.

These are universal data structures. Virtually all modern programming languages support them in one form or another. It makes sense that a data format that is interchangable with programming languages also be based on these structures.

For more information you can have a look at

http://www.json.org/

http://en.wikipedia.org/wiki/JSON

Authentication

To use  Fieldclimate API and authenticate users, it needs username, password or API KEY.

Logging with username and password.

http://www.fieldclimate.com/api/index.php?action=CIDIStationList_GetFirst&user_name=austria&user_passw=guest

The required parameter user_name is username Fieldclimate.

The required parameter user_passw is password Fieldclimate.

Logging with with username and API KEY

http://www.fieldclimate.com/api/index.php?action=CIDIStationList_GetFirst&user_name=austria&user_passw=&api_key=b6589fc6ab0dc82cf12099d1c2d40ab994e8410c

The required parameter user_name is username Fieldclimate.

The required parameter api_key is specially generated application api key for authorization client's apps .

API Methods

All methods , arguments are described http://www.fieldclimate.com/cidiweb.php

More soon coming….

API Keys

For getting API KEY mail the following details to support@metos.at

After short verification you will receive necessary instructions and code for the sticker


PESSL JSON Library v.02

Pessl Instruments Gmbh has  released set of  classes javascript libraries. It wrappers all AJAX calls in a nice classes so that you don't need to deal with JSON and AJAX at all.

jsonlib

You can download last version   PESSL JSON Library v.02

You can read JSDOC documention

You can download libraries and examples  all-in-one  PESSL JSON Examples

Requirements:  jQuery 1.3.2


 The "Hello, World" of Fieldclimate JSON API V1

The easiest way to start learning about the Fieldclimate JSON API is to see a simple example.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

 

<title> The "Hello, World" of Fieldclimate JSON API

V1</title>

<script type="text/javascript" src="../../js/jquery-1.3.2.min.js"></script>

<script type="text/javascript" src="../pessl.json.js"></script>

<script type="text/javascript">

 

      $j('document').ready(function() {

            checkLogin();          

      });

 

      function checkLogin() {

            var login = new PESSL.json.Basic();

                  login.onFault = function(rep) {

                        if (rep.faultcode == 5) {

                             $j('#dialog-form').show();

                        } else {

                             alert('Fault: ' + rep.faultcode + ' ' + rep.faultstring);

                        }

                        return true;

                  };

                 

                  login.onComplete = function(obj) {

                        if (obj.faultcode == -1) {

                             $j('#dialog-form').hide();

                             $j('#user-box').html('You have logged!');

                        }          

                  };

            login.Login();

      }

     

      function doLogin() {

            var login = new PESSL.json.Basic();

 

            login.username = $j("#name").val();

            login.password = $j("#password").val();

                 

            login.onFault = function(rep) {

                  if (rep.faultcode == 5) {

                        $j('#dialog-form').show();

                        $j('#login_error_msg').html(rep.faultstring);

                  } else {

                        alert('Fault: ' + rep.faultcode + ' ' + rep.faultstring);

                  }

                  return true;

            };

            login.onComplete = function(obj) {

                  if (obj.faultcode == -1) {

                        $j('#dialog-form').hide();

                  }

            };

            login.Login();

      }

 

      function Logout() {

            var logout = new PESSL.json.Basic();

            logout.onFault = function(rep) {

                  alert('Fault: ' + rep.faultcode + ' ' + rep.faultstring);

                  return true;

            };

            logout.onComplete = function() {

                  window.location.reload();

            };

            logout.Logout();

      }

</script>

</head>

<body>

 

<h3> The "Hello, World" of Fieldclimate JSON API V1</h3>

 

<div id="dialog-form" title="Login box">

<p>All form fields are required.</p>

<p><span id="login_error_msg" style="color: red;"></span></p>

<form>

<fieldset><label for="name">Username</label><br />

<input type="text" name="name" id="name" /><br />

<label for="password">Password</label><br />

<input type="password" name="password" id="password" /><br />

<input type="button" value="Login" onclick="doLogin();"></fieldset>

</form>

</div>

<div id ="user-box"></div>

<a href="javascript: Logout();">Logout</a>

</body>

</html>

First create a new instance of the class  var login = new PESSL.json.Basic();

Then you need to provide the user name and password

  login.username = 'austria';

  login.password = 'guest';

Then define events

login.onComplete(obj)  - A method to be called if the request completed.

 login.onFault(obj) - A method to be called if the request has fault

login.onError(obj) - A method to be called if the request fails

The parametr obj is reference of current instance.

 

The method login.Login() will be used to authorize.

 If the request completed then property obj. dataset  contains instance of PESSL.json.DataSet.

The property obj. dataset   has two objects

-          obj. dataset.rs -  ReturnDataSet (The array of data which returns Web service)

-          obj. dataset .params - ReturnParams (The array of output  parameters)

{"ReturnDataSet":0,

"ReturnParams":{"user_name":"austria","cookie":"6adae1951d9b9fc3d137bbfa8e87fe85"}}

 

If the request has fault then properties  obj.faultcode and obj.faultstring contain info about fault. This fault be generated by Web service.

{"faultcode":5,

"faultactor":"CIDIUser",

"faultstring":"No rights",

"faultdetail":"CIDIData interface error"}

 

If the request  fails then properties  obj.error contains instance of PESSL.json.Error

obj.error.code  - Error code

obj.error.text - Error message

Live demo is available here  The "Hello, World" of Fieldclimate JSON API V1

Reading the List of Stations

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

 

<title>Example 1 -  Reading the List of Stations</title>

<script type="text/javascript" src="../../js/jquery-1.3.2.min.js"></script>

<script type="text/javascript" src="../pessl.json.js"></script>

</head>

<body>

<script type="text/javascript">

 

$j('document').ready(function() {

      var stations = new PESSL.json.StationList();

      stations.username = 'austria';

      stations.password = 'guest';

      stations.api_key = '';

 

      var s = 0;

      stations.onError = function() {

            alert('Error code:'+stations.error.code+' '+stations.error.text);

      };

      // on Fault

      stations.onFault = function(rep) {

            if (rep.faultcode == 5) {

                  // handle fault

                  alert('You have no rights!');

            } else {

            }

 

            return true;

      };

 

      // On complete

      stations.onComplete = function() {

 

            var stations_div =  $j('#stations_list');

            if (stations.faultcode > 0) {

                  return false;

            }

 

            if (stations.dataset == null) {

                  return false;

            }

            var stations_list = "";

 

            for ( var f in stations.dataset.rs) {

                  var station = stations.dataset.rs[f];

                  var lat = parseFloat(station.f_latitude);

                  var long = parseFloat(station.f_longitude);

                  var title = station.f_user_name;

 

                  stations_div.html(stations_div.html() + ' - '+ title +  '<br/>');

 

                  s++;

            }

            ;

 

            if (stations.dataset.rs != null) {

                  stations.GetNext();

            }

            ;

      };

 

      stations.GetFirst();

});  

</script>

<h3>Example 1 -  Reading the List of Stations</h3>

<div id="stations_list"></div>

</body>

</html>

 

You start from reading out the list of available station. First create a new instance of the class var stations = new PESSL.json.StationList();

Then you need to provide the user name and password

  stations.username = 'austria';

  stations.password = 'guest';

Then define events

stations.onComplete(obj)  - A method to be called if the request completed.

 stations.onFault(obj) - A method to be called if the request has fault

stations.onError(obj) - A method to be called if the request fails

The parametr obj is reference of current instance.

The methods stations.GetFirst(), stations.GetNext() will be used for reading list of stations.

 If the request completed then property obj. dataset  contains instance of PESSL.json.DataSet.

The property obj. dataset   has two objects

-          obj. dataset .rs -  ReturnDataSet (The array of data which returns Web service)

-          obj. dataset .params -  ReturnParams (The array of output  parameters)

{"ReturnDataSet":[

{"f_station_code":"282",

"f_date":"2009-04-20 12:07:21",

"f_dev_id":"1",

"f_name":"00000146",

"f_descr":"imetos avr",

"f_info":"\r\nImetos 1 software: 02.55  hardware: 01.00  compiled: Apr 23 2009 12:23:00",

"f_uid":"2147483647",

"f_status":"0",

"f_create_time":"2007-01-22 08:59:42",

"f_master_name":null,

"f_date_min":"2005-03-08 12:50:00",

"f_date_max":"2010-10-29 12:00:00",

"f_date_last_down":"2010-10-29 11:01:52",

"f_date_sens":"2010-05-20 12:30:50.625755",

"f_date_data":"2010-01-24 19:02:12.19124",

"f_date_conf":"2010-10-29 13:01:52.26496",

"f_sernum":"326",

"f_timezone":"60",

"f_latitude":"47.2055",

"f_longitude":"15.63507",

"f_altitude":"443",

"f_date_comm":1288346512,

"f_user_station_name":"Pessl Instruments Company Weather '\u00b4\u00b4",

"f_user_name":"Pessl Instruments Company Weather '\u00b4\u00b4"}],

"ReturnParams":{"row_count":"1","station_code":1}}

 

If the request has fault then properties  obj.faultcode and obj.faultstring contain info about fault. This fault be generated by Web service.

{"faultcode":5,

"faultactor":"CIDIUser",

"faultstring":"No rights",

"faultdetail":"CIDIData interface error"}

 

If the request  fails then properties  obj.error contains instance of PESSL.json.Error

obj.error.code  - Error code

obj.error.text - Error message

 

 

Live demo is available here  Example 1 - Reading the List of Stations

Getting Configuration of Station

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

 

<title>Example 2 -  Getting Configuration of Station</title>

<script type="text/javascript" src="../../js/jquery-1.3.2.min.js"></script>

<script type="text/javascript" src="../pessl.json.js"></script>

</head>

<body>

<script type="text/javascript">

 

$j('document').ready(function() {

 

      var conf = new PESSL.json.StationConfig();

            conf.username = 'austria';

            conf.password = 'guest';

            conf.api_key = '';

            conf.station_name = '00000146';

 

            conf.onError = function() {

                  alert('Error code:'+conf.error.code+' '+conf.error.text);

            };

 

            // on Fault

            conf.onFault = function(rep) {

                  if (rep.faultcode == 5) {

                        // handle fault

                        alert('You have no rights!');

                  } else {

                  }

                  return true;

            };

           

            // On complete

            conf.onComplete = function() {

 

                  var conf_div =  $j('#station_conf');    

                 

                  for ( var f in conf.dataset.rs) {

                        var row = conf.dataset.rs[f];

                        var title = row.f_name;

 

                        for (var field in row) {

                             conf_div.html(conf_div.html() + field+'='+ row[field] +  '<br/>');

                        }

                  }

                  ;

            };

            conf.Get();

});  

</script>

<h3>Example 2 -  Getting Configuration of Station</h3>

<div id="station_conf"></div>

</body>

</html>

 

To request data of a particular station, instantiate class

 var conf = new PESSL.json.StationConfig();

Then you need to provide the user name and password and station_name

 conf.username = 'austria';

 conf.password = 'guest';

 conf.station_name='00000146';

Then define events

conf.onComplete(obj)  - A method to be called if the request completed.

 conf.onFault(obj) - A method to be called if the request has fault

conf.onError(obj) - A method to be called if the request fails

The parametr obj is reference of current instance.

Now we can read out configuration of the station using method conf.Get();

 If the request completed then property obj. dataset  contains instance of PESSL.json.DataSet.

The property obj. dataset   has two objects

-          obj. dataset .rs -  ReturnDataSet (The array of data which returns Web service)

-          obj. dataset .params -  ReturnParams (The array of output  parameters)

{"ReturnDataSet":[

{"f_station_code":"282",

"f_date":"2009-04-20 12:07:21",

"f_dev_id":"1",

"f_name":"00000146",

"f_descr":"imetos avr",

"f_info":"\r\nImetos 1 software: 02.55  hardware: 01.00  compiled: Apr 23 2009 12:23:00",

"f_uid":"2147483647",

"f_status":"0",

"f_create_time":"2007-01-22 08:59:42",

"f_master_name":null,

"f_date_min":"2005-03-08 12:50:00",

"f_date_max":"2010-11-03 13:00:00",

"f_date_last_down":"2010-11-03 12:02:02",

"f_date_sens":"2010-05-20 12:30:50.625755",

"f_date_data":"2010-01-24 19:02:12.19124",

"f_date_conf":"2010-11-03 13:02:02.256111",

"f_measure_int":"10",

"f_data_int":"0",

"f_timezone":"60",

"f_latitude":"47.2055",

"f_longitude":"15.63507",

"f_altitude":"443",

"f_hw_ver_major":"1",

"f_hw_ver_minor":"0",

"f_sw_ver_major":"2",

"f_sw_ver_minor":"102",

"f_sms_warn_numbers":"10",

"f_sms_warn_values":"18",

"f_gsm_mcc":"232",

"f_gsm_mnc":"1",

"f_gprs_apn":null,

"f_gprs_user_id":null,

"f_gprs_passw":null}

]}

 

This array contains only 1 row that is an associative array with the following fields

f_station_code

Ignore

f_date

Date of registration in database

f_dev_id

Code of device

f_name

Name of station

f_descr

Textual description of station

f_info

Extended textual description of the station

f_uid

Ignore

f_create_time

Ignore

f_measure_int

Measure interval (0 - default)

f_data_int

Logging interval (0 - default)

f_webserv_dom

Ignore

f_webserv_url

Ignore

f_webserv_port

Ignore

f_emergency_sms

Ignore

f_timezone

Time zone in minutes (60=+1H -60 = -1H)

f_latitude

Latitude

f_longitude

Longitude

f_hw_ver_major

Major number of hardware version

f_hw_ver_minor

Minor number of hardware version

f_sw_ver_major

Major number of software version

f_sw_ver_minor

Minor number of software version

f_sms_warn_numbers

Maximum number of telephone numbers for SMS warnings

f_sms_warn_values

Maximum number of conditions for SMS warnings

f_gsm_mcc

MCC code of GSM operator

f_gsm_mnc

MNC code of GSM operator

f_gprs_apn

APN of GRPS connection

f_gprs_user_id

User name of GPRS connection

f_gprs_passw

Password for GPRS connection

 

If the request has fault then properties  obj.faultcode and obj.faultstring contain info about fault. This fault be generated by Web service.

{"faultcode":5,

"faultactor":"CIDIUser",

"faultstring":"No rights",

"faultdetail":"CIDIData interface error"}

 

If the request  fails then properties  obj.error contains instance of PESSL.json.Error

obj.error.code  - Error code

obj.error.text - Error message

 

Live demo is available here  Example 2 - Getting Configuration of Station

Getting Sensors Info

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

 

<title>Example 3 -  Getting Sensors Info</title>

<script type="text/javascript" src="../../js/jquery-1.3.2.min.js"></script>

<script type="text/javascript" src="../pessl.json.js"></script>

</head>

<body>

<script type="text/javascript">

 

$j('document').ready(function() {

 

      var station_name = '00000146';

      var user_name           = 'austria';

      var user_password = 'guest';

      var api_key             = ''

 

      var sensors                        = new PESSL.json.StationSensors();

            sensors.station_name    = station_name;

            sensors.username        = user_name;

            sensors.password        = user_password;

            sensors.api_key         = api_key;

 

            sensors.onError = function() {

                  alert('Error code:'+sensors..error.code+' '+sensors.error.text);

            };

            // on Fault

            sensors.onFault = function(rep) {

                  if (rep.faultcode == 5) {

                        // handle fault

                        alert('You have no rights!');

                  } else {

                  }

 

                  return true;

            };

           

            sensors.onComplete = function() {

 

                  var sens_div =  $j('#sensors_div');

                  var sens = sensors.dataset.rs;

                  var sens_html = '';

                 

                  for ( var f in sens) {

                        var sensor = sens[f];

                        var name    = sensor.f_sensor_user_name;

                        var unit    = sensor.f_unit;

                       

                        sens_html+='-'+name+'('+unit+')'+'<br/>';     

                  }

 

                  sens_div.html(sens_html);

            }

            sensors.Get();

});  

</script>

<h3>Example 3 -  Getting Sensors Info</h3>

<div id="sensors_div"></div>

</body>

</html>

Next step is to read the list of sensors connected to this station

 var sensors = new PESSL.json.StationSensors();

 

Then you need to provide the user name , password and station_name

 sensors.username = 'austria';

 sensors.password = 'guest';

 sensors.station_name='00000146';

Then define events

sensors.onComplete(obj)  - A method to be called if the request completed.

 sensors.onFault(obj) - A method to be called if the request has fault

sensors.onError(obj) - A method to be called if the request fails

The parametr obj is reference of current instance.

Now we can read sensors info of the station using method sensors.Get();

 If the request completed then property obj. dataset  contains instance of PESSL.json.DataSet.

The property obj. dataset   has two objects

-          obj. dataset .rs -  ReturnDataSet (The array of data which returns Web service)

-          obj. dataset .params -  ReturnParams (The array of output  parameters)

Again, the returned value is a 2-dimensional array. Each row has the following fields

Field

Meaning

f_station_code

Ignore

f_sensor_ch

Channel of the sensor. Every sensor connected to the station has a unique channel number

f_sensor_code

Global code of the sensor. Every model of sensor has its own code. Don't confuse with the channel. More then one sensors with the same code can be connected to the same station, but their channels will be different. For example, two air temperature sensors with code 0 connected to the same station may have channels 0 and 1 respectively

f_chain_code

Code of chain is sensors are chained. Some of sensors may be chained through a special cable. One chain may have tens of different sensors. Through channel code one may group sensors by chain to display or do some specific calculations

f_group_code

Code of group to which the sensor belongs. Every model of sensor belongs to a globally defined group. For example, all different air temperature sensors belong to one group, wind speed sensors belong to another group, etc. Group allows recognising of different sensors and unifying their parameters.

f_unit_code

Ignore

f_name

Original name of the sensor. Human readable name of the sensor, assigned by Pessl Instruments

f_unit f_div

Ignore

f_mul

Ignore

f_val_neg

Sensor may have negative values

f_val_log

Ignore

f_val_last

Last measured value is available

f_val_sum

Sum is available

f_val_aver

Average is available

f_val_min

Minimum value is available

f_val_max

Maximum value is available

f_val_time

Value is time interval

f_val_user

Ignore

f_create_time

Ignore

f_group_name

Name of group to which this sensor belongs

f_color

HTML colour assigned to this sensor in fieldclimate web site

f_sensor_user_name

User defined name for this sensor

f_user_unit_code

Ignore

 

If the request has fault then properties  obj.faultcode and obj.faultstring contain info about fault. This fault be generated by Web service.

{"faultcode":5,

"faultactor":"CIDIUser",

"faultstring":"No rights",

"faultdetail":"CIDIData interface error"}

 

If the request  fails then properties  obj.error contains instance of PESSL.json.Error

obj.error.code  - Error code

obj.error.text - Error message

Live demo is available here  Example 3 - Getting Sensors Info

Getting Weather Data

 

Class PESSL.json.StationData

Method

Description

GetFirst

Reads first block of data

GetNext

Reads next block of data

GetPrev

Reads previous block of data

GetLast

Reads last block of data

GetFromDate

Reads block of data starting from a specified date

Property PESSL.json.StationData .row_count defines how many data records one block should contain

Next and previous blocks are always calculated relatively to the previous call using variable dt_from. This variable also serves as a status of the object. To keep track between different http sessions it is enough to recreate the PESSL.json.StationData object and set dt_from.

Before calling  GetFromDate dt_from should be implicitly set.

Like all previously mentioned interfaces, weather data functions return a 2-dimensional array.

The number of columns and their names depend on what sensors are connected to the station in question.

It is possible to read data grouped by hour, day, and month or not grouped. To define the group function assign PESSL.json.StationData .group_code to

0

no group (default)

1

hour

2

day

3

month

 

First column always contains the date of the measurement and is called f_date

Other column names are built according to the scheme explained below

sens_aggr_ch_code

where aggr can be

 

 

 

aver

Average value

min

Minimum value

max

Maximum value

last

Last value

time

Time

 

ch   channel of the sensor

Code  code of the sensor

Example of data array

{"ReturnDataSet":[

{"f_date":"2010-06-06 20:50:00","f_log_int":"600","sens_aver_1_600":"0","sens_aver_2_501":"18.9","sens_min_2_501":"18.8","sens_max_2_501":"19","sens_aver_4_0":null,"sens_min_4_0":null,"sens_max_4_0":null,"sens_sum_5_6":"0","sens_aver_6_5":"0","sens_max_6_5":"0","sens_last_7_7":"6650","sens_time_8_4":"0","sens_aver_9_123":"200","sens_aver_10_123":"200","sens_aver_11_123":"200","sens_aver_12_123":"200","sens_aver_13_123":"200","sens_aver_14_123":"200","sens_aver_22_506":"19.28","sens_min_22_506":"19.21","sens_max_22_506":"19.35","sens_aver_23_507":"75.09","sens_aver_24_506":"19.57","sens_min_24_506":"19.5","sens_max_24_506":"19.64","sens_aver_25_507":"73.73","sens_aver_26_21":"14.6","sens_min_26_21":"14.6","sens_max_3101_3101":"0","sens_max_3102_3102":"0","sens_max_3103_3103":"0","sens_max_3104_3104":"0","sens_max_3201_3201":null,"sens_max_3601_3601":null},{"f_date":"2010-06-06 21:00:00","f_log_int":"600","sens_aver_1_600":"0","sens_aver_2_501":"18.8","sens_min_2_501":"18.8","sens_max_2_501":"18.9","sens_aver_4_0":null,"sens_min_4_0":null,"sens_max_4_0":null,"sens_sum_5_6":"0","sens_aver_6_5":"0","sens_max_6_5":"0","sens_last_7_7":"6610","sens_time_8_4":"0","sens_aver_9_123":"200","sens_aver_10_123":"200","sens_aver_11_123":"200","sens_aver_12_123":"200","sens_aver_13_123":"200","sens_aver_14_123":"200","sens_aver_22_506":"19.09","sens_min_22_506":"19.01","sens_max_22_506":"19.18","sens_aver_23_507":"76.09","sens_aver_24_506":"19.35","sens_min_24_506":"19.25","sens_max_24_506":"19.45","sens_aver_25_507":"75.18","sens_aver_26_21":"14.6","sens_min_26_21":"14.6","sens_max_3101_3101":"0","sens_max_3102_3102":"0","sens_max_3103_3103":"0","sens_max_3104_3104":"0","sens_max_3201_3201":null,"sens_max_3601_3601":null}],

"ReturnParams":{"row_count":"2","dt_from":"2010-06-06T20:50:00","dt_to":"2010-06-06T21:00:00","min_date":"2005-03-08T12:50:00","max_date":"2010-06-06T21:00:00","_eof":1,"_bof":0}}

 


 

f_date

f_log_int

sens_aver_1_600

sens_aver_2_501

sens_min_2_501

sens_max_2_501

sens_aver_4_0

sens_last_7_7

sens_aver_9_123

sens_aver_10_123

2010-06-06 20:50:00

600

0

18.9

18.8

19

null

6650

200

200

2010-06-06 21:00:00

600

0

18.9

18.8

18.9

null

6610

200

200

 

Example 4.1

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

 

<title>Example 4.1 -  Getting Weather Data</title>

<script type="text/javascript" src="../../js/jquery-1.3.2.min.js"></script>

<script type="text/javascript" src="../pessl.json.js"></script>

<style>

#loading {

      position: fixed;

      top: 0;

      left: 0;

      z-index: 5000;

      background-color: blue;

      font-size: 150%;

      color: white;

      padding: 2px;

}

 

</style>

</head>

<body>

<script type="text/javascript">

 

$j('document').ready(function() {

 

      $j("#loading").ajaxStart(function() {

            $j(this).show();

      });

 

      $j("#loading").ajaxStop(function() {

            $j(this).hide();

      });

 

      var station_name = '00000146';

      var user_name           = 'austria';

      var user_password = 'guest';

      var api_key             = ''

 

      var station_data                   = new PESSL.json.StationData();

            station_data.station_name    = station_name;

            station_data.username        = user_name;

            station_data.password        = user_password;

            station_data.api_key         = api_key;

            station_data.row_count       = 2;

           

            station_data.onError = function() {

                  alert('Error code:'+station_data..error.code+' '+station_data.error.text);

            };

            // on Fault

            station_data.onFault = function(rep) {

                  if (rep.faultcode == 5) {

                        // handle fault

                        alert('You have no rights!');

                  } else {

                        alert ('Fault:'+rep.faultstring);

                  }

                  return true;

            };

           

            station_data.onComplete = function() {

 

                  var st_data_div =  $j('#station_data_div');

                  var st_data = station_data.dataset.rs;

                  var st_data_html = '';

 

                  $j('#station_name').html(station_name);

 

                  st_data_html+="<table border=\"1\">";

                  st_data_html+="<tr>";

                  for ( var f in st_data[0]) {

                        st_data_html+="<th>"+f+"</th>";

                  }    

                  st_data_html+="</tr>";

                  for ( var f in st_data) {

                        var st_data_row   = st_data[f];

 

                        st_data_html+="<tr>";

                        for (var s in st_data_row) {

                             st_data_html+='<td>'+st_data_row[s]+'</td>';           

                        }

                        st_data_html+="</tr>";

                  }

                  st_data_html+="</table>"

                  st_data_div.html(st_data_html);

            }

           

            station_data.GetLast();

});  

</script>

<h3>Example 4.1 -  Getting Station Data for  <span id="station_name"></span></h3>

<div id="loading">Loading...</div>

<div id="station_data_div"></div>

</body>

</html>

 

Live demo is available here  Example 4.1 - Getting Weather Data

The names of columns are not very descriptive in this example.

Below is an example of using this function to display the name of sensor and measurement unit in the header of weather data table.

Example 4.2

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

 

<title>Example 4 -  Getting Weather Data</title>

<script type="text/javascript" src="../../js/jquery-1.3.2.min.js"></script>

<script type="text/javascript" src="../pessl.json.js"></script>

</head>

<body>

<script type="text/javascript">

 

$j('document').ready(function() {

 

      var station_name = '00000146';

      var user_name           = 'austria';

      var user_password = 'guest';

      var api_key             = ''

 

      var sensors = new PESSL.json.StationSensors();

      sensors.station_name = station_name;

      sensors.username = user_name;

      sensors.password = user_password;

      sensors.api_key = api_key;

      sensors.onComplete = function() {

 

            // Get sation data

            var station_data = new PESSL.json.StationData();

            station_data.username = user_name;

            station_data.password = user_password;

            station_data.api_key = api_key;

            station_data.station_name = station_name;

            station_data.group_code = 0;

            station_data.row_count = 100;

 

            station_data.onComplete = function() {

                  var data = station_data.dataset.rs;

                  var sens = sensors.dataset.rs;

                  var lastdata = HtmlDataHours (sens, data);

 

                  $j('#data_div').html(lastdata);

 

            };

            station_data.GetLast();

            // End station data

      }

      sensors.Get();

});  

 

 

function GetSensorValue(s, fields, info, data, aggr) {

      var val = null;

      var sens_field = "sens_" + aggr[fields[s]] + "_" + info.f_sensor_ch + "_"

                  + info.f_sensor_code;

      if (data[sens_field]) {

            val = data[sens_field];

      }

      ;

      return val;

};

 

function HtmlDataHours(sens, data) {

      var html = "";

 

      if (!data || data.length < 1) {

            return html;

      }

      var aggr = {

            f_val_min : "min",

            f_val_max : "max",

            f_val_aver : "aver",

            f_val_sum : "sum",

            f_val_time : "time",

            f_val_last : "last"

      };

 

      html += "<table border='1'>";

      html += "<tr><th>Date</th><th colspan=2>" + data[0].f_date + "</th></tr>";

      for ( var f in sens) {

            var sensor = sens[f];

            var name = sensor.f_sensor_user_name;

            var unit = sensor.f_unit;

            var fields = [];

 

            if (sensor.f_val_max == 1) {

                  fields.push("f_val_min");

            }

 

            if (sensor.f_val_max == 1) {

                  fields.push("f_val_max");

            }

 

            if (sensor.f_val_aver == 1) {

                  fields.push("f_val_aver");

            }

 

            if (sensor.f_val_sum == 1) {

                  fields.push("f_val_sum");

            }

 

            if (sensor.f_val_time == 1) {

                  fields.push("f_val_time");

            }

 

            if (sensor.f_val_last == 1) {

                  fields.push("f_val_last");

            }

 

            if (sensor.f_val_user == 1) {

                  fields.push("f_val_user");

            }

 

            var vals = [];

            var notnulls = [];

            var valnull = false;

 

            for ( var i = 0; i < fields.length; i++) {

                  var val = GetSensorValue(i, fields, sensor, data[0], aggr);

                  vals[i] = ((val != null) ? val : '');

                  if (val != null) {

                        notnulls[i] = val;

                  }

 

                  if (i == fields.length - 1 && notnulls.length < 1) {

                        valnull = true;

                  }

            }

 

            if (valnull) {

                  continue;

            }

 

            html += "<tr>";

            html += "<td rowspan='" + fields.length + "'>" + name + "[" + unit

                        + "]" + "</td>";

 

            if (fields.length > 1) {

                  html += "<td>" + aggr[fields[0]] + "</td>";

            }

 

            html += "<td " + ((fields.length == 1) ? "colspan=2 " : "") + ">"

                        + vals[0] + "</td>";

            html += "</tr>";

 

            for ( var i = 1; i < fields.length; i++) {

                  html += "<tr><td>" + aggr[fields[i]] + "</td><td>" + vals[i]

                             + "</td></tr>";

            }

            ;

 

      }

      html += "</table>";

      return html;

};

 

</script>

<h3>Example 4 -  Getting Weather Data</h3>

<div id="data_div"></div>

</body>

</html>

Live demo is available here  Example 4.2 - Getting Weather Data

 

 

Disease Models and Weather Forecast

Except weather data, there can be additional data, generated by fieldclimate modules, like diesase modules, forecast, etc. This data has the same structure as weather data and is represented in a form of additional sensors of the station. It means that it can be read with JSON API interface without any modifications. You simply read sensors and data of the station.

Example 4.3

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

 

<title>Example 4.3 -  Getting Weather Data</title>

<script type="text/javascript" src="../../js/jquery-1.3.2.min.js"></script>

<script type="text/javascript" src="../pessl.json.js"></script>

<style>

#loading {

      position: fixed;

      top: 0;

      left: 0;

      z-index: 5000;

      background-color: blue;

      font-size: 150%;

      color: white;

      padding: 2px;

}

 

</style>

</head>

<body>

<script type="text/javascript">

 

$j('document').ready(function() {

 

      $j("#loading").ajaxStart(function() {

            $j(this).show();

      });

 

      $j("#loading").ajaxStop(function() {

            $j(this).hide();

      });

 

      var station_name = '00000146';

      var user_name           = 'austria';

      var user_password = 'guest';

      var api_key             = ''

 

      var station_data                   = new PESSL.json.StationData();

            station_data.station_name    = station_name;

            station_data.username        = user_name;

            station_data.password        = user_password;

            station_data.api_key         = api_key;

            station_data.row_count       = 10;

            station_data.show_user_app  = true;

           

            station_data.onError = function() {

                  alert('Error code:'+station_data..error.code+' '+station_data.error.text);

            };

            // on Fault

            station_data.onFault = function(rep) {

                  if (rep.faultcode == 5) {

                        // handle fault

                        alert('You have no rights!');

                  } else {

                        alert ('Fault:'+rep.faultstring);

                  }

                  return true;

            };

           

            station_data.onComplete = function() {

 

                  var st_data_div =  $j('#station_data_div');

                  var st_data = station_data.dataset.rs;

                  var st_data_html = '';

 

                  $j('#station_name').html(station_name);

 

                  st_data_html+="<table border=\"1\">";

                  st_data_html+="<tr>";

                  for ( var f in st_data[0]) {

                        st_data_html+="<th>"+f+"</th>";

                  }    

                  st_data_html+="</tr>";

                  for ( var f in st_data) {

                        var st_data_row   = st_data[f];

 

                        st_data_html+="<tr>";

                        for (var s in st_data_row) {

                             st_data_html+='<td>'+st_data_row[s]+'</td>';           

                        }

                        st_data_html+="</tr>";

                  }

                  st_data_html+="</table>"

                  st_data_div.html(st_data_html);

            }

           

            station_data.GetLast();

});  

</script>

<h3>Example 4.3 -  Getting Station Data for  <span id="station_name"></span></h3>

<div id="loading">Loading...</div>

<div id="station_data_div"></div>

</body>

</html>

You can see that that now station has much more sensors than in previous examples. This is because we have requested not only the weather data but also sensors generated by additional modules. This is done by setting property show_user_app of PESSL.json.StationData class to true.

station_data.show_user_app  = true;

Live demo is available here  Example 4.3 - Getting Weather Data

API Reference

This reference contains inline documentation in JavaScript source files, and produces an documentation of the JavaScript code.

http://www.fieldclimate.com/json_manual/jsdoc/index.html

For developers

After learning the basics of data interface you can start developing your own applications.

Here you will find a complete example with Google Map API integration http://www.fieldclimate.com/json_manual/demos/map/index.html

Here you will find dynamic example reading weather data with navigation pages http://www.fieldclimate.com/json_manual/demos/index.htm

Please send error reports, suggestions, requests for support and examples of your applications to software@metos.at