Editing Online Thermometer

Jump to: navigation, search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 210: Line 210:
 
The agent is also coded in squirrel.
 
The agent is also coded in squirrel.
  
In this project, the agent is only triggered when it receives a message from its imp associated device. We have just explained that the imp device calls function ''agent.send()'' to send a message to the agent. On the agent side, you use the function ''device.on()'' to register the function that will process this incoming message:
+
In this project, the agent is only triggered when it receives a message from its 'imp' associated device. We have just explained that the 'imp' device calls function ''agent.send()'' to send a message to the agent. On the agent side, you use the function ''device.on()'' to register the function that will process this incoming message:
  
 
  device.on("sendTemperature", postTemperature);
 
  device.on("sendTemperature", postTemperature);
Line 216: Line 216:
 
This function has two parameters. The first one is the name of the message (''sendTemperature'' in our case) and the second one is the function in the agent that will process this message (''postTemperature()'' in the example). The second parameter that the 'imp' device includes when calling the function  ''agent.send()'' is an object whose value is passed as a parameter to the function indicated by the agent.
 
This function has two parameters. The first one is the name of the message (''sendTemperature'' in our case) and the second one is the function in the agent that will process this message (''postTemperature()'' in the example). The second parameter that the 'imp' device includes when calling the function  ''agent.send()'' is an object whose value is passed as a parameter to the function indicated by the agent.
  
Focusing on our example, the imp device sends the message ''sendTemperature'' and includes the string received from Arduino as the second parameter (i.e. a temperature reading). The agent on the server receives this message and calls the function ''postTemperature()'' passing as parameter the string generated by  the Arduino (temperature reading).
+
Focusing on our example, the 'imp' device sends the message ''sendTemperature'' and includes the string received from Arduino as the second parameter (in fact, a temperature reading). The agent on the server receives this message and calls the function ''postTemperature()'' passing as parameter the string generated by  the Arduino (temperature reading).
  
The ''postTemperature()'' function just formats an http POST request according to the API of Carriots. The request includes in its BODY  a JSON string with the temperature value received from the device. This request creates a new reading in Carriots server.
+
The ''postTemperature()'' function just formats an http POST request according to API of Carriots. The request includes in its BODY  a JSON string with the temperature value received from the device. This request adds a new reading in Carriots server.
  
 
Details on how the http request works are described in the API documentation of eletricImp [http://www.electricimp.com/docs/api/http/ http], [http://www.electricimp.com/docs/api/http/post/ http POST], [http://www.electricimp.com/docs/api/httprequest/ http request].
 
Details on how the http request works are described in the API documentation of eletricImp [http://www.electricimp.com/docs/api/http/ http], [http://www.electricimp.com/docs/api/http/post/ http POST], [http://www.electricimp.com/docs/api/httprequest/ http request].
Line 228: Line 228:
 
To retrieve the API key, go to Carriots console and click on "MySettings" tab and then on "My Account" on the menu at the top of the screen. The API key value is the one named ''Full Privileges Apikey''.
 
To retrieve the API key, go to Carriots console and click on "MySettings" tab and then on "My Account" on the menu at the top of the screen. The API key value is the one named ''Full Privileges Apikey''.
  
Carriots expects a JSON object as the BODY of the http request. Its format is as follows:
+
Carriots expects a JSON object as the BODY of the http request, . Its format is as follows:
  
 
  {
 
  {
Line 240: Line 240:
 
  }
 
  }
  
The timestamp of a reading is  indicated in the parameter ''at''. In the example, we use the string ''now'' . This value tells Carriots to store the received reading with the value of the system time of its server when the message is received.  
+
The timestamp of a reading is  indicated in the parameter ''at''. In the example, we use the string ''now'' . This value indicates the Carriots to store the received reading with the system of Carriots server when the message is received.  
  
 
Replace ''your_device_id'' in the agent code with the actual identity of the device in Carriots (e.g. ''TempMSM@makespacemadrid'').
 
Replace ''your_device_id'' in the agent code with the actual identity of the device in Carriots (e.g. ''TempMSM@makespacemadrid'').

Please note that all contributions to Wiki Makespace Madrid may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see Wiki Makespace Madrid:Copyrights for details). Do not submit copyrighted work without permission!

To protect the wiki against automated edit spam, we kindly ask you to type the two words you see in the box below:

Cancel | Editing help (opens in new window)