Posts a message from the agent to the device
The name of the message
The data to be passed to the device
This method works in partnership with agent.on() to allow messages and data to be sent from the agent to its imp. For example, if the agent calls:
and the device has already called:
then on receipt of the message
setspeed from the agent, the device’s messageHandler() function will be called and be passed the contents of the variable data, which can be any serializable Squirrel table, array, string, integer, float or boolean. See the Developer Guide ‘Serializable Squirrel’ for Squirrel’s data serialization rules. The message handler function will always be called with exactly one parameter: the data passed to device.send(). The data parameter in both messageHandler() and device.send() is not optional. You must include a value, even if you do not plan to use it in the handler.
For a more in-depth look at the imp’s use of events and event triggers, please see the Developer Guide ‘Event-Driven Programming’.
For more information on agent-device and device-agent messaging, see the guide ‘Effective Internet-agent-device Communication’.
For sample code that can be used to manage messaging between agent and device, see the imp API Cookbook recipe ‘Agent-Device Communications’.
The following agent code’s startTime() function uses device.send() to issue a ‘pong’ message to the device in response to the arrival of a ‘ping’ message from the device.