Last active
August 29, 2015 14:08
-
-
Save electricimp/aad83baedd76a3bb8558 to your computer and use it in GitHub Desktop.
Agent-Device Communications
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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