Skip to content

Instantly share code, notes, and snippets.

@electricimp
Last active August 29, 2015 14:08
Show Gist options
  • Save electricimp/aad83baedd76a3bb8558 to your computer and use it in GitHub Desktop.
Save electricimp/aad83baedd76a3bb8558 to your computer and use it in GitHub Desktop.
Agent-Device Communications
// Device Globals
dummyValue <- 0
function updateWeatherDisplay(forecast)
{
// This function, omitted for clarity, takes the supplied
// forecast value and uses it to present a weather icon
// on the device's display
}
// Register message handlers
// On receipt of the 'get.networks' message, return the results of a WiFi scan
// Note: this uses an inline function
agent.on("get.networks", function(unused){agent.send("set.location", imp.scanwifinetworks())})
// On receipt of the 'set.forecast' message, use the passed data to update the display
// Note: this uses an pre-defined function
agent.on("set.forecast", updateWeatherDisplay)
// Send first message, requesting the device's location
agent.send("get.forecast", dummyValue)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment