RainMachine REST API JavaScript implementation

From RainMachine wiki page
Jump to: navigation, search

Contents

RainMachine REST API JavaScript implementation

Downloading

If you want to develop javascript applications to control RainMachine, we are providing a javascript API here

git clone https://github.com/sprinkler/rainmachine-developer-resources.git

Documentation for REST API is available | here

This implementation is used on our device web UI: https://github.com/sprinkler/rainmachine-web-ui

Using

To use the javascript API, the provided async.js and rainmachine-api-v4.js files must be loaded from the html file.

<html>
<head>
	<title> RainMachine REST API JavaScript Test </title>
	<meta charset="utf-8" />
	<link rel="icon" type="image/ico" href="http://rainmachine.com/favicon.ico">
	<script src="js/async.js"></script>
	<script src="js/rainmachine-api-v4.js"></script>
</head>
<body onload="testAPI()">
	<script language="javascript">
	    function testAPI() {
			//asynchronous example
			APIAsync.getApiVer().then(function(receivedData){ console.log("ASYNC CALL: %o", receivedData);});
			//synchronous example
			console.log("SYNC CALL: %o", APISync.getApiVer());
	    }
	</script>
</body>
</html>

Available functions

You can use the functions below by either synchronous method:

var version = APISync.getApiVer()

or aynchronously:

APIAsync.getApiVer().then(function(response) { var version = response; })


List of functions:

getApiVer = function()

http://docs.rainmachine.apiary.io/#reference/api-versions

auth = function(password, remember)
authChange = function(oldPass, newPass)

http://docs.rainmachine.apiary.io/#reference/authentication

getProvision = function()
getProvisionWifi = function()
getProvisionCloud = function()
setProvision = function(systemObj, locationObj)
setProvisionName = function(name)
setProvisionCloud = function(cloudObj)
setProvisionCloudEmail = function(email)
setProvisionCloudEnable = function(isEnabled)
setProvisionCloudReset = function()
setProvisionReset = function(withRestart)

http://docs.rainmachine.apiary.io/#reference/provision

getDailyStats = function(dayDate, withDetails)

http://docs.rainmachine.apiary.io/#reference/daily-stats

getRestrictionsRainDelay = function()
getRestrictionsGlobal = function()
getRestrictionsHourly = function()
getRestrictionsCurrently = function()
setRestrictionsRainDelay = function(days)
setRestrictionsGlobal = function(globalRestrictionObj)
setRestrictionsHourly = function(hourlyRestrictionObj)
deleteRestrictionsHourly = function(id)

http://docs.rainmachine.apiary.io/#reference/restrictions

getPrograms = function(id)
getProgramsNextRun = function()
setProgram = function(id, programProperties)
newProgram = function(programProperties)
deleteProgram = function(id)
startProgram = function(id)
stopProgram = function(id)

http://docs.rainmachine.apiary.io/#reference/programs

getZones = function(id)
startZone = function(id, duration)
stopZone = function(id)
getZonesProperties = function(id)
setZonesProperties = function(id, properties, advancedProperties)

http://docs.rainmachine.apiary.io/#reference/zones

getWateringLog = function(simulated, details, startDate, days)
getWateringQueue = function()
stopAll = function()

http://docs.rainmachine.apiary.io/#reference/watering

getParsers = function(id)
setParserEnable = function(id, enable)
setParserParams = function(id, params)
resetParserParams = function(id)
getParserData = function(id, startDate, days)
runParser = function(id, withParser, withMixer, withSimulator)
deleteParser = function(id)

http://docs.rainmachine.apiary.io/#reference/parsers

getMixer = function(startDate, days)

http://docs.rainmachine.apiary.io/#reference/mixer

getDiag = function()
getDiagUpload = function()
getDiagLog = function()
sendDiag = function()

http://docs.rainmachine.apiary.io/#reference/diagnostics

setLogLevel = function(level)
checkUpdate = function()
getUpdate = function()
startUpdate = function()
getDateTime = function()
setDateTime = function(dateStr) //dateStr: '%Y-%m-%d %H:%M'
setSSH = function(isEnabled)
setTouch = function(isEnabled)
setLeds = function(isOn)
reboot = function()
getTimeZoneDB = function()
uploadParser = function(fileName, fileType, binData)
getBeta = function()
setBeta = function(enabled)

http://docs.rainmachine.apiary.io/#reference/machine