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 181: Line 181:
 
* Once the application is loaded, it will begin to run. The imp device waits to receive data from Arduino through the serial connection. When it receives a temperature reading, it forwards it to the agent on the ElectricImp server and also post a new message in the Log window of the IDE. On receiving this new reading, the agent forwards it to Carriots server and posts a new message in the Log window registering the result of this submission
 
* Once the application is loaded, it will begin to run. The imp device waits to receive data from Arduino through the serial connection. When it receives a temperature reading, it forwards it to the agent on the ElectricImp server and also post a new message in the Log window of the IDE. On receiving this new reading, the agent forwards it to Carriots server and posts a new message in the Log window registering the result of this submission
  
===== Detailed explanation of the imp device code  =====
+
===== Detailed explanation of the 'imp' device code  =====
  
In the previous tutorial we explained that the imp code is executed sequentially starting from the first line (functions are identified with the <code>function</code> key word and are skipped from the sequential flow).
+
In the previous tutorial we explained that the 'imp' code is executed sequnetially starting from the first line (functions are identified with the <code>function</code> key word and are skipped from the sequential flow).
  
 
Disclaimer: I am not an expert in squirrel, the programming language used by electricImp. I apologise for the poor quality of the code
 
Disclaimer: I am not an expert in squirrel, the programming language used by electricImp. I apologise for the poor quality of the code
Line 193: Line 193:
 
  arduino <- hardware.uart57;
 
  arduino <- hardware.uart57;
  
This variable is initialised further down in the code. On top of defining the technical parameters of the serial connection, we also indicate the function (''arduinoData()'') that the imp device will call every time that it receives new data over the connection:
+
This variable is initialises further down in the code. On top of defining the technical parameters of the serial connectiom, we also indicate the function (''arduinoData()'') that the 'imp' device will call every time that it receives new data over the connection:
  
 
  arduino.configure(9600, 8, PARITY_NONE, 1, NO_CTSRTS, arduinoData);
 
  arduino.configure(9600, 8, PARITY_NONE, 1, NO_CTSRTS, arduinoData);
 
   
 
   
The electricImp docummentation has more information about how to manage serial connections in imp [http://www.electricimp.com/docs/api/hardware/uart/]
+
The electricImp docummentation has more information about how to manage serial connections in 'imp' [http://www.electricimp.com/docs/api/hardware/uart/]
  
The  ''arduinoData()'' function is responsible for listening to the Arduino serial connection. When a byte is received, the imp device calls this function. ''arduinoData()'' reads the input bytes and stores them as a char string in ''s''. This process continues until a byte valued ''0xFC'' is received. This value is the same one defined in the Arduino sketch to identify the end of a data transmission. If more than 10 bytes are received without receiving an end code, the function assumes that the data is corrupt and it resets variable ''s''.
+
The  ''arduinoData()'' function is responsible for listening to the Arduino serial connection. When a byte is received, the 'imp' device calls this function. ''arduinoData()'' reads the input bytes and stores them as a char string in ''s''. This process continues until a byte valued ''0xFC'' is received. This value is the same one defined in the Arduino sketch to identify the end of a data transmission. If more than 10 bytes are received without receiving an end code, the function assumes that the data is corrupt and it resets variable ''s''.
 +
 
 +
When the code to send the function receives arduinoData () sends the string stored in the variable s (the data received from Arduino) the agent is running on the server in the cloud ElectricImp:
  
 
When an end code ''0xFC'' is received, ''arduinoData()'' sends the string stored in variable ''s'' to the electrcImp agent that is running in the cloud:
 
When an end code ''0xFC'' is received, ''arduinoData()'' sends the string stored in variable ''s'' to the electrcImp agent that is running in the cloud:
Line 205: Line 207:
 
  agent.send("sendTemperature", s);
 
  agent.send("sendTemperature", s);
  
Function ''agent.send()'' has two parameters. The first one is the name of the message that will be received by the agent in the server (''sendTemperature'' in our code). The second parameter is  the object that will be passed as a parameter to the agent function that will receive the message. More information can be found in the API docummentation of electricImp ([http://www.electricimp.com/docs/api/agent/send/] , [http://www.electricimp.com/docs/api/agent/] )
+
Function ''agent.send()'' has two parameters. The first one is the name of the message that will be recived by the sgent in the server (''sendTemperature'' in our code). The second parameter is  the object that will be passed as a parameter to the agent function that will receive the message. ore information can be found in the API docummentatio of electricImp ([http://www.electricimp.com/docs/api/agent/send/] , [http://www.electricimp.com/docs/api/agent/] )
  
 
===== Detailed explanation of the agent code on ElectricImp server =====
 
===== Detailed explanation of the agent code on ElectricImp server =====

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)