Hi,
I'm trying to connect some wireless sensors Iris Crossbow to read light and 
temperature.
I must realize these three things:
1) I have to sample the light 
and the temperature with two different times and I have to send the strings 
everytime the signal is sampled. These things have to happen on the same node 
and at the same time.
2) I have to sample only the light and I have to send the 
packet.
3) I have to sample only the temperature and I have to send the packet.


1) and 2) are completed and the trasmission is correct, instead in 3) there is 
a problem to read the value. The temperature reading is correct only in the 
first sampling then is sampled a wrong value.
This is my code:

#include 
"appFeatures.h"
includes XCommand;

includes sensorboard;
#include "vettore.h"


module XMDA100M {
  provides {
    interface StdControl;
  }
  uses {
  
        
interface Leds;
        interface MhopSend as Send_Temp;
        interface MhopSend as 
Send_Light;
        interface RouteControl;
// Battery    
    interface ADC as 
ADCBATT;
    interface StdControl as BattControl;
//Temp
    interface 
StdControl as TempControl;
    interface ADC as Temperature;
//Light
    
interface StdControl as PhotoControl;
    interface ADC as Light;
    interface 
ADCControl;    
        interface HPLUART;
        interface Receive as Receive_Temp;
        
interface Receive as Receive_Light;     
    interface Timer as Timer_Temp;
        
interface Timer as Timer_Light;
    command void health_packet(bool enable, 
uint16_t intv);
    command HealthMsg* HealthMsgGet();
  }
}

implementation {
        

  enum { START, BUSY, BATT_DONE, TEMP_DONE, LIGHT_DONE};
  
  #define MSG_LEN 
29
  #define N 296
  #define VAL 7

        uint16_t temperature[N] = {TABLE};
        int8_t 
stringa_tempo[VAL];
        int8_t stringa_luce[VAL];

   TOS_Msg msg_buf1;
   TOS_Msg 
msg_buf2;   
   TOS_MsgPtr msg_ptr1;
   TOS_MsgPtr msg_ptr2;   
   HealthMsg 
*h_msg;

   norace bool sending_packet_temp, sending_packet_light,
sensinginsession;

   norace uint8_t state;
   XDataMsg_1 pack1;
   XDataMsg_2 
pack2; 
   XPacketSensor1 *data3;
   XPacketSensor2 *data4;      
   uint16_t 
result_index, value, result1, result2, value_battery, result_light;
   uint32_t 
V_ref,result_l, tempo, luce;
    
   bool       sleeping;        // application 
command state

  static void initialize() 
    {
      atomic 
      {
        
sleeping = FALSE;
                sending_packet_temp = FALSE;              
                sending_packet_light 
= FALSE;          
                sensinginsession=FALSE;
      }
    }

    task void stop()

    {
        call StdControl.stop();
    }       
        task void battstop()
    {
        call 
BattControl.stop();
    }
    task void tempstop()
    {
        call TempControl.
stop();
    }
    task void photostop()
    {
        call PhotoControl.stop();
    
}
/****************************************************************************

 * Task to xmit radio message *
 
****************************************************************************/

   task void send_radio_msg1(){
    uint16_t  len1;     
        XDataMsg_1 *data1;      
    
uint8_t i;      
        
    if(sending_packet_temp) return;     
    atomic 
sending_packet_temp=TRUE;  

    data1 = (XDataMsg_1*)call Send_Temp.getBuffer
(msg_ptr1, &len1);      
        for (i=0; i<= sizeof(XDataMsg_1)-1; i++)                        
                ((uint8_t*) 
data1)[i] = ((uint8_t*)&pack1)[i];      
    data1->xMeshHeader_1.board_id = 
SENSOR_BOARD_ID;
    data1->xMeshHeader_1.packet_id = 1;         
    data1-
>xMeshHeader_1.parent    = call RouteControl.getParent();
    data1-
>xMeshHeader_1.packet_id = data1->xMeshHeader_1.packet_id | 0x80;
        
        //per 
visualizzare la stringa contenente la temperatura
                        strncpy(data1-
>xMeshHeader_1.thermistor, "Temp", MAX_TEMP);                   
                        strncpy(data1->xData_1.
datap1.point, ".", POINT);
                        strncpy(data1->xData_1.datap1.unit1, "Celsius", 
MAX_UNIT_TEMP);
        // Send the RF packet!
        if (call Send_Temp.send
(BASE_STATION_ADDRESS,MODE_UPSTREAM,msg_ptr1, sizeof(XDataMsg_1)) != SUCCESS) {

                atomic sending_packet_temp = FALSE;                     
        }       
    return;
  }
  

task void send_radio_msg2(){
    uint16_t  len2;
        XDataMsg_2 *data2;
    
uint8_t j;
        
    if(sending_packet_light) return;     
    atomic 
sending_packet_light=TRUE;  

    data2 = (XDataMsg_2*)call Send_Light.getBuffer
(msg_ptr2, &len2);
        for (j=0; j<= sizeof(XDataMsg_2)-1; j++)                        
                ((uint8_t*) 
data2)[j] = ((uint8_t*)&pack2)[j];
    
        data2->xMeshHeader_2.board_id = 
SENSOR_BOARD_ID;
    data2->xMeshHeader_2.packet_id = 1;         
    data2-
>xMeshHeader_2.parent    = call RouteControl.getParent();
    data2-
>xMeshHeader_2.packet_id = data2->xMeshHeader_2.packet_id | 0x80;               
        //per 
visualizzare la stringa contenente la luce
                        strncpy(data2->xMeshHeader_2.
photo, "Light", MAX_PHOTO);                     
                        strncpy(data2->xData_2.datap2.unit2, "mV", 
MAX_UNIT_LIGHT);
    // Send the RF packet!
        if (call Send_Light.send
(BASE_STATION_ADDRESS,MODE_UPSTREAM,msg_ptr2, sizeof(XDataMsg_2)) != SUCCESS) {

                atomic sending_packet_light = FALSE;    
        }
    return;
  }
  
 
/****************************************************************************
 
* Initialize the component. Initialize ADCControl, Leds *
 
****************************************************************************/
  
command result_t StdControl.init() {    
        atomic {
    msg_ptr1 = &msg_buf1;
        
msg_ptr2 = &msg_buf2;   
    }
// usart1 is also connected to external serial 
flash
// set usart1 lines to correct state
    TOSH_MAKE_FLASH_OUT_OUTPUT();
             //tx output
    TOSH_MAKE_FLASH_CLK_OUTPUT();             //usart 
clk
        sending_packet_temp=FALSE;
        sending_packet_light=FALSE;
        
        call 
HPLUART.init();    
    call BattControl.init(); 
    call Leds.init();
    
call TempControl.init();
    call PhotoControl.init();   
    call ADCControl.
init(); 
    initialize();
        return SUCCESS;
  }
 
/****************************************************************************
 
* Start the component. Start the clock. *
 
****************************************************************************/
  
command result_t StdControl.start(){
    call StdControl.stop();
    h_msg = 
call HealthMsgGet();
    h_msg->rsvd_app_type = SENSOR_BOARD_ID;     
    call 
health_packet(TRUE,TOS_HEALTH_UPDATE);
    return SUCCESS;     
  }
 
/****************************************************************************
 
* Stop the component. *
 
****************************************************************************/
  
command result_t StdControl.stop() {
    call BattControl.stop();    
    call 
TempControl.stop();  
    call PhotoControl.stop();
        call HPLUART.stop();
    
return SUCCESS;    
  }

/****************************************************************************
 
* Measure Temp, Light   *
 
****************************************************************************/ 

event result_t Timer_Temp.fired(){      
        if ( !sending_packet_temp) {
        atomic state 
= START;        
        call TempControl.start();
        call Leds.greenToggle();
        call 
Temperature.getData();     
        return SUCCESS;
        }
}

  async event result_t 
Temperature.dataReady(uint16_t data) {  
        //atomic state = START; 
        atomic{         
                
result_index = data - 0x0163;
                value = temperature[result_index];
                result1 = 
value/100;
                result2 = value%100;            
                itoa(result1,pack1.xData_1.datap1.temp1,
10);
                itoa(result2,pack1.xData_1.datap1.temp2,10);                    
                if(data==0)
                        call 
Leds.redToggle();
        }    
           post tempstop();
           TOSH_uwait(100);
           post 
send_radio_msg1();     
       TOSH_uwait(100);
                post stop();        
       
return SUCCESS;
  }  

event result_t Timer_Light.fired(){     
        if ( !
sending_packet_light) {
        atomic state = START;
        call BattControl.start();
        call 
PhotoControl.start();
        call ADCBATT.getData();
        return SUCCESS;
        }
}

  async 
event result_t ADCBATT.dataReady(uint16_t data) {
         atomic value_battery = 
data;     
      post battstop();    
      call Light.getData();
      return 
SUCCESS;
  }
   
 async event result_t Light.dataReady(uint16_t data) {       

        atomic state = START;                    
        atomic{         
                V_ref = value_battery * 
(0x00000006);
                result_l = V_ref * data;
                result_light = (data * V_ref)/1024;             
                
                itoa(result_light,pack2.xData_2.datap2.light,10);
        }       
       post 
photostop();           
        TOSH_uwait(100);
                post send_radio_msg2();      

       TOSH_uwait(100);
                post stop();         
       return SUCCESS;
  }
  
 
/**
  * Handle completion of sent RF packet. 
  */
  
  event result_t 
Send_Temp.sendDone(TOS_MsgPtr msg, result_t success){   
      atomic {
          
msg_ptr1 = msg;   
          sending_packet_temp = FALSE;
      }
      return 
SUCCESS;
  }
  
  event result_t Send_Light.sendDone(TOS_MsgPtr msg, result_t 
success){
         atomic {
          msg_ptr2 = msg;         
          sending_packet_light = FALSE;
    
}   
      return SUCCESS;
  }

        async event result_t HPLUART.putDone(){
                
return SUCCESS;
        }
        
        async event result_t HPLUART.get(uint8_t data){
                return 
SUCCESS;
        }

The reception code there isn't here but I start the Timer (with 
call Leds.start) in the reception.
Can someone resolve my problem?
Thanks a 
lot...

_______________________________________________
Tinyos-help mailing list
Tinyos-help@millennium.berkeley.edu
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to