Modifications

Sauter à la navigation Sauter à la recherche
954 octets ajoutés ,  29 octobre 2018 à 21:09
Ligne 198 : Ligne 198 :  
</syntaxhighlight>
 
</syntaxhighlight>
    +
Now, we can focus on the main loop.
    +
The first step is to send the header if not done yet.
 +
 +
Then we reads the sensors (as we have tested them, this should not be a surprise). We also capture the time with the function {{fname|millis()}}, so the {{fname|ms}} variable contains the number of milliseconds since the last reset.
 +
 +
Finally, we do increment the {{fname|packetnum}} variable. This would allows to track lost packets on the receiver side. 
 +
 +
{{fname|packet_str}} is the message to send via radio. It is composed with {{fname|String}} objects and concatenation operations. {{fname|String}} are welcome to transform '''float''' into string representation since most common float to string C standard functions would fail to work properly onto Arduino alike plateforms.
 +
 +
The key function to transform the '''String object''' into a '''C buffer'' is {{fname|packet_str.c_str()}} which offer an access to the underlying array of bytes (exactly what we would need for the radio module library).
 +
 
<syntaxhighlight lang="c">  
 
<syntaxhighlight lang="c">  
 
bool header_send = false; // if header has not been send yet...  
 
bool header_send = false; // if header has not been send yet...  
 
int16_t packetnum = 0; // packet number increment at each data emission
 
int16_t packetnum = 0; // packet number increment at each data emission
 
void loop() {
 
void loop() {
     // send columns header
+
     // --- SEND COLUMNS HEADER -------------------
 
     if( !(header_send) ){
 
     if( !(header_send) ){
 
         send_header();
 
         send_header();
Ligne 209 : Ligne 220 :  
     }  
 
     }  
 
      
 
      
     // read the voltage of TMP36
+
     // --- READ SENSORS ---------------------------
 
     float voltage = getVoltage(temperaturePin);
 
     float voltage = getVoltage(temperaturePin);
    // convert voltage to temperature
  −
    //  Degrees = (voltage - 500mV) multiplied by 100
   
     float temperature = (voltage - .5) *100;
 
     float temperature = (voltage - .5) *100;
   Ligne 221 : Ligne 230 :  
     packetnum += 1; // increment  
 
     packetnum += 1; // increment  
   −
     // char radiopacket[40] = "Hello World #";
+
     // --- Compose the Message to send ------------
 
     String packet_str = String( ":"+String(packetnum,DEC)+"|" );
 
     String packet_str = String( ":"+String(packetnum,DEC)+"|" );
 
     packet_str.concat( String(ms,DEC)+"|" );
 
     packet_str.concat( String(ms,DEC)+"|" );
29 861

modifications

Menu de navigation