THE SELF-LEARNING WATERING SYSTEM

Smart Gardener

REST API Documentation Logic Architecture Requirements Sensor network architecture Component selection

REST Server API

The SmartGardener Core provides some of its functionalities to other applications and services by means of a REST Server. This allows easy extension and integration with other services and software. Data can be obtained from the core and commands as well can be sent to it.

In development mode (which can be enabled using the options in the Settings module) additional commands and data are available. Development features are those underlined and red in the list below.

All commands are currently implemented as GET requests.

In order to use the REST server the Core must be running on the Controller, which, in turn, needs to be connected to a Local Area Network.

Command

Description

/system

Returns a JSON formatted dictionary containing the following keys:

 

- Version: a string which indicates which version of the Core is currently running on the controller;

 

- Build : a string which indicates which build of the Core is currently running on the controller;

 

- Boards Connected : an integer corresponding to the number of boards detected during the last self-discovery cycle; This string will not contain a value unless the I2C module has been started and initialized;

 

-City: a String which indicates the closest city to the location detected by the Geolocation module; This string will not contain a value unless the Geolocation module has been started and initialized and a connection to the Internet is present;

 

-IP: a String which indicates the current IP address of the Internet connection available to the controller; This string will not contain a value unless the Geolocation module has been started and initialized and a connection to the Internet is present;

 

-Longitude: a String which indicates the longitude detected by the Geolocation module; This string will not contain a value unless the Geolocation module has been started and initialized and a connection to the Internet is present;

 

-Latitude: a String which indicates the latitude detected by the Geolocation module; This string will not contain a value unless the I2C module has been started and initialized and a connection to the Internet is present;

 

Example of response:

{

    "City": "Torino",

    "IP": "2.230.90.xx",

    "Longitude": 7.6667,

    "Version": "alpha 0.2",

    "Build": "24/05/2014 17:00",

    "Latitude": 45.05,

    "Boards_Connected": 3

}

 

 

/system/boards

Returns a JSON formatted dictionary containing a listing of the features and the data of all the sensor boards discovered during the discovery procedure. The structure returned is organized in the following way:

 

….

Board(n-1):

{

[…]

},

Board(n):

{

 […]

 },

Board(n+1):

{

 […]

 }

 ….

The internal structure […] is structured in the same way as the single board data. Please refer to the following section for further information.

 

Example of response:

{
    "Board1": {
        [...]
    }, 
    "Board2": {
        [...]
    }, 
    "Board3": {
        [...]
    }
}

 

 

/system/boards/[N]

Returns a JSON formatted dictionary containing the list of the features and the data of the N sensor board discovered during the discovery procedure. The structure returned is organized in the following way:

 

- Board_model: an integer which indicates which version of the Board is connected to the bus;

 

- Cal_data_available: a Boolean which indicates if the given boards supports and provides calibration data. If true the data provided in the Data section will

Be displayed already calibrated. If false only raw data will be presented: this is the case when sensor boards host only sensors whose content is raw (e.g. water excess).

 

-Data: a JSON formatted dictionary containing the data from the sensors present on the board.

 

 -Format: a JSON formatted dictionary containing Booleans listing which sensors are present on the board.

 

-Protocol_version: an integer which indicates which protocol version is supported by the board.

 

-UID: an integer value which is unique identifier for the given board. This allows to internally identify sensors regardless of their self-discovery addresses.

 

Example of a response:

{
    "Board_model": 1, 
    "Cal_data_available": true, 
    "Data": {
        "Temperature": 23.52, 
        "Water_excess": true
    }, 
    "Features": {
        "Extra": false, 
        "Humidity": false, 
        "Light": false, 
        "Rain": false, 
        "Soil_humidity": false, 
        "Temperature": true, 
        "Water_excess": true
    }, 
    "Protocol_version": 2, 
    "UID": 1
}

/status

Returns a JSON formatted object containing information pertaining to the status of the system .

The structure returned is organized in the following way:

 

-Connected to internal network: a boolean value which is true if a connection to the internal sensor network has been correctly estabilished.

 

-Connected to internet: a boolean value which is true if a connection to the internet has been detected.

 

-Internal Network OK: a boolean value which is true if no faults have been encountered during transactions with the sensor boards.

 

-Pump available: a boolean value which is true if no faults have occurred during the initialization or during the activation of the water delivery system.

 

-REST service available: a boolean value which is true if no faults have occurred during the set-up of the REST server.

 

-Sensor boards available: an integer value which represents the number of sensor boards connected to the system.

 

-Weather forecasts available: a Boolean value which is true if the system is able to retrieve updated weather information.

 

Example of a response:

{

    "Connected to internal network": true,

    "Connected to internet": true,

    "Internal Network OK": true,

    "Pump available": true,

    "REST Service available": true,

    "Sensor boards available": 5,

    "Weather forecasts available": true

}

 

/status/weather

Returns a JSON formatted dictionary containing the current weather forecast obtained by means of the weather module. This data is only available if an Internet connection is available to the controller and requires initialization of both the weather and the geolocation modules .

The structure returned is organized in the following way:

 

-Description: a string containing a short description of the current weather for the location determined by the geolocation system.

-Humidity: an integer which presents the current humidity value expressed as a percentage.

-Max_Temperature: a floating point number which represent the maximum temperature forecast in Celsius degrees for the next 3 hours.

 

-Min_Temperature: a floating point number which represent the minimum temperature forecast in Celsius degrees for the next 3 hours.

 

-Precipitation: a floating point number which represent the rainfall forecast for the next 3 hours in millimeters of rain.

 

- Temperature: a floating point number which represent the temperature at the time of the last update in Celsius degrees.

 

 

Example of a response:

{
    "Description": "overcast clouds", 
    "Humidity": 100, 
    "Max_Temperature": 27.03000000000003, 
    "Min_Temperature": 27.027000000000044, 
    "Precipitation": 0.0, 
    "Pressure": 1.0123858869972728, 
    "Temperature": 27.03000000000003
}

 

 

/status/waterdb

Returns a JSON formatted dictionary containing the record, for the last 30 days, of the seconds of activation of the water delivery system.

 

- WDMonth: the current month for which the record is intended expressed as an integer value.

 

 

Example of a response:

{

    "1": 302,

    "10": 240,

    "11": 243,

    "12": 225,

    "13": 288,

    "14": 238,

    "15": 180,

    "16": 135,

    "17": 148,

    "18": 187,

    "19": 180,

    "2": 230,

    "20": 233,

    "21": 142,

    "22": 228,

    "23": 152,

    "24": 0,

    "25": 261,

    "26": 0,

    "27": 0,

    "28": 0,

    "29": 0,

    "3": 242,

    "30": 0,

    "4": 256,

    "5": 180,

    "6": 143,

    "7": 135,

    "8": 186,

    "9": 204,

    "WDMonth": 6

}

 

 

/status/lightdb

Returns a JSON formatted dictionary containing the record, for the last 30 days, of the seconds of activation of the light delivery system.

 

- WDMonth: the current month for which the record is intended expressed as an integer value.

 

 

Example of a response:

{

    "1": 2430,

    "10": 2405,

    "11": 2439,

    "12": 2610,

    "13": 1768,

    "14": 1650,

    "15": 1820,

    "16": 1560,

    "17": 1849,

    "18": 1967,

    "19": 2048,

    "2": 2230,

    "20": 1789,

    "21": 2470,

    "22": 2459,

    "23": 0,

    "24": 0,

    "25": 113,

    "26": 0,

    "27": 0,

    "28": 0,

    "29": 0,

    "3": 1890,

    "30": 0,

    "4": 1649,

    "5": 2039,

    "6": 2203,

    "7": 1780,

    "8": 1970,

    "9": 2093,

    "WDMonth": 6

}

 

 

/led/on

Activates the lighting system (if the SmartGardener system supports the functionality).

 

This command allows to specify the number of seconds that the lighting system is requested to be activated by using the following syntax:

/led/on?seconds=XXX

The seconds value can also be omitted. In this case the system will activate the light for a default time of one hour.

 

On success returns the number of seconds the system is to be activated. If the operation fails the string “Failure” is displayed.

/led/off

Deactivates the lighting system (if the SmartGardener system supports the functionality) overriding previous commands or automatic activations.

 

/pump/on?seconds=XXX

Activates the water delivery system for the specified amount of seconds.

 

This command overrides the manual scheduling of the watering systems and forces the system to immediately activate the water delivery system for an XXX number of seconds. Updates of the learning algorithm for the intelligent controller will be inhibited, disregarding the next iterations, for the next 3 hours after an override has been performed. On success returns the number of seconds the system is to be activated. If the operation fails the string “Failure” is displayed.

Warning: no feedback is provided with respect to the actual success of the operation, since this would require waiting for a XXX number of seconds!

/blink/[N]

Sends a command to the sensor board with UID N which causes the activation of the blink functionality on that given board.

 

To enable the user to easily identify boards a led is installed on each sensor board. This command can be used to activate the blinking functionality on a desired board.

On success returns the string “board N will blink for 5 seconds”. If the operation fails the string “Failure” is displayed.

 

/rename/[N]?new_name=[name]

This command sets the name of a sensor board to a given string specified by the user.

 

This command enables renaming of the sensor boards so that they can be more easily identified by the user. On success returns the string “board N  renamed name.”. If the operation fails the string “Failure” is displayed.

 

/devel/kill

This command requests a shutdown of the system.

 

[Requires settings.DEVEL=1]

 This command terminates, if the operation can be safely executed, the execution of the SmartGardener Core and modules. Complete switch off is ensured within 10 seconds unless a watering operation is in process. In such a case the watering operation is first completed to ensure a safe shut down of the system.

No answer is sent back from the service when this command is executed.

/devel/update_boards

This command forces an immediate update of the sensor board data.

 

[Requires settings.DEVEL=1]

This command forces the system to perform an immediate update of the data from all the boards, disregarding the current update scheduling. On success returns the string “Sensor data updated”. If the update operation fails the string “Failure” is displayed

/devel/update_weather

This command forces an immediate update of the weather data.

 

[Requires settings.DEVEL=1]

This command forces the system to perform an immediate update of the data from the weather module, disregarding the current update scheduling. On success returns the string “Weather data updated”. If the update operation fails the string “Failure” is displayed.

/settings/natural_light/on

This command enables, on SmartGardener versions supporting the functionality, the natural lighting functionality.

 

The natural lighting functionality tries to duplicate outdoor conditions in an indoor environment by synchronizing the lighting cycle with the natural sunset and sunrise.

On success it returns the string “Natural Lighting enabled”. If the feature is not supported the string “Feature not supported” will be returned. Finally if the operation fails the string “Failure!” is displayed.

 

/settings/natural_light/off

This command disables, on SmartGardener versions supporting the functionality, the natural lighting functionality.

 

On success it returns the string “Natural Lighting disabled”. If the feature is not supported the string “Feature not supported” will be returned. Finally if the operation fails the string “Failure!” is displayed.

 

/settings/correction?factor=[factor]

This command sets the watering correction factor to a user-defined value.

 

This setting allows further irrigation time tailoring by the user which can specify a correction factor to be applied to the computed irrigation time. On success it returns the string “System wide correction factor set to [factor]”. If the command fails the string “Failure” is returned instead.

 

/settings/location?lat=[latitude]&

lon=[longitude]

This command sets the current latitude and longitude to a user specified value.

 

This setting allows the user to improve the accuracy of the system by manually specifying the coordinates of the system installation, thus overriding the setting computed by the geolocation module.

 

On success it returns the string “Location data set: Latitude [latitude], Longitude [longitude]”. If the command fails the string “Failure” is returned instead.