Cloud Scripting for Devices
by Exosite, on January 17, 2013
Wouldn't it be powerful to move your device application and processing to the device's 'cloud instance'? Now you can. We released our script application interface several months ago with selected customers and we've now made it available publicly to all accounts.
What does this mean? In Exosite's One Platform, clients (which represent devices and users and accounts, anything that has data and/or ownership) may have Lua application scripts inserted that can access all of that client's data and resources. So, in a simple example, if you were sending raw sensor data (let's say it is an analog value 0 to 1023) you could run a script that waited on new values and then converted that analog value to degrees Fahrenheit and store it into a different data source, or keep a running average in another data source. You could insert a function call to one of our dispatches (SMS, Email, HTTP, Twitter, etc) to push the data to someone or something that may need it.
These scripts can be as complex as required and multiple scripts can be inserted for every platform client. Algorithms can be written to process data, advanced escalation functions could be created to handle alert conditions, and simple parsing routines could take a package of data and parse it out. For product vendors, scripts will be cloned for Model Types, so as every new device is enabled you can kick-off a script that provisions with a cellular provider(set plan, activate), writes data into a manufacturing database (who, when, where, etc), and even tweets about it (yes we support a twitter API in scripts).
To learn more, you can check out our script documentation and examples repository. In Portals, you will find the 'Scripts' link on the manage menu. All scripts provide the status (stopped, running, etc) and have a debug function to print out debug information which is useful for development.
Here is a simple example that converts an analog voltage to degrees F from a Thermistor.
Example
[sourcecode language="python"]
local analog = alias['analogTemp']
local temp = alias['temp']
local B = 4450.0 --K
local R25 = 100000.0 -- Ohms
local function ntcTherm (rMeasured, beta, r25)
local To = 298.15
local r_inf = r25 * math.exp(-beta / To)
return beta / math.log(rMeasured / r_inf)
end
local function celsius (tempK)
return tempK - 273.15
end
local function fahrenheit (tempK)
return (celsius(tempK) * 9.0/5) + 32
end
debug("starting")
while true do
local ts1 = analog.wait()
debug("Got a new value!")
local analogvalue = analog[ts1]
-- Convert Analog Voltage to Resistance
local rPullup = 100000.0
local adcScale = 1023
local Rmeasured = rPullup * analogvalue / (adcScale - analogvalue)
local tempK = ntcTherm(Rmeasured,B,R25)
local tempF = fahrenheit(tempK)
temp.value = tempF
email("person@example.com","New Data",string.format("New Temperature is %d", tempF))
end
[/sourcecode]