Post a new topicPost a reply Page 1 of 1   [ 8 posts ]
Author Message
 Post subject: Time stamp and xbee packet
PostPosted: Fri Mar 09, 2012 7:38 pm 

Joined: Thu Feb 23, 2012 4:32 pm
Posts: 32
Which is the correct way to include a timestamp in the xbee packets i send?
I get garbage in the serial monitor whenever i use getTime() or getTimestamp() like this

Quote:
~ h }3Ά @†‰BŒΏR# }3Ά @†‰B-mac:0013A20040868958 -Time:12/03/09 - 18:59.36 -temp:-18.7 -RH:-25.8% -SM:21811λ~ + }3Ά @†‰BŒΏR }3Ά @†‰B -Lum:1023.0 -bat:41F


Top
 Profile  
 
 Post subject: Re: Time stamp and xbee packet
PostPosted: Mon Mar 12, 2012 9:30 am 

Joined: Mon Sep 28, 2009 1:06 pm
Posts: 7440
aggelos,

Strange characters you see are communication between Waspmote and Xbee. You can see a lot of examples in this forum.

On the other hand, When you use RTC.getTime(), there are some variables updated with time values, like year, date, month. Please take a look into RTC programming guide

Any other questions please feel free to ask.

Regards.


Top
 Profile  
 
 Post subject: Re: Time stamp and xbee packet
PostPosted: Tue Mar 20, 2012 6:31 pm 

Joined: Thu Feb 23, 2012 4:32 pm
Posts: 32
Dear libelium,

thank you for your answer, i have read the RTC guide and i already know their meaning, however i was referring to the second set of these characters, right after the -SM reading. I get a copy a second copy as your see and i don't know why.


Top
 Profile  
 
 Post subject: Re: Time stamp and xbee packet
PostPosted: Wed Mar 21, 2012 3:17 pm 

Joined: Mon Sep 28, 2009 1:06 pm
Posts: 7440
aggelos,

Can you post the code you are using? Just to see if there is something wrong.

Strange characters are always due to Xbee communication and they are rubbish.

Regards.


Top
 Profile  
 
 Post subject: Re: Time stamp and xbee packet
PostPosted: Thu Mar 22, 2012 5:24 pm 

Joined: Thu Feb 23, 2012 4:32 pm
Posts: 32
Sure here is the code im using,another thing is that each packet is appended at the end of the previous one, and not in a newline, in the serial monitor. Im assuming therefore that '\r' '\n' are
not reaching the serial monitor. So it has to be a buffer issue.

Any help would be appreciated, sorry for the long post btw.
Quote:
/*
* Adiaforos Reading Code
*/

packetXBee* paq_sent; 
int8_t state=0; 
long previous=0;
char buffer[250];
char* macHigh="0013A200";
char* macLow="40868958";

#define key_access "LIBELIUM"
//BROADCAST
uint8_t direccion[8]={0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF};

//UNICAST -- MAC address of the gateway "0013A200406983E4"
//uint8_t direccion[8]={0x00,0x13,0xA2,0x00,0x40,0x69,0x83,0xE4};

//---------------------------------------------------
//global
float temp=0,RH=0,light=0;
uint16_t soilmoist=0;
//strings suitable for sending
char tempArray[10],RHArray[20],lightArray[20],timeStamp[40];
//char soilmoistArray[20]; ignore this one
char* auxtime;

//---------------------------------------------------
void setup(){
  
  // Checks if we come from a normal reset or an hibernate reset
  PWR.ifHibernate();
  
  // Store key access in EEPROM
  for(int i=0;i<8;i++){
    Utils.writeEEPROM(i+107,key_access[i]);
  }
  
  XBee.setMode(XBEE_ON);
  XBee.begin(9600);
  delay(1000);
  XBee.print("+++");
  delay(2000);
  XBee.println("ATBD5,AP2,WR,CN");
  delay(150);
  
  XBee.setMode(XBEE_OFF);
  XBee.close();
  
  // Inits the XBee XSC library
  xbeeZB.init(ZIGBEE,FREQ2_4G,NORMAL); 
  
  // Powers XBee
  xbeeZB.ON();
    
  /*
  Utils.setLED(LED0, LED_ON);
  Utils.setLED(LED1, LED_ON);
  delay(5000);
  Utils.setLED(LED0, LED_OFF);
  Utils.setLED(LED1, LED_OFF); 
  for (int i=0;i<24;i++){
    Utils.blinkLEDs(125);
  }
  */
  
}//endof setup
//------------------------------------------------------

void loop(){
  // If Hibernate has been captured, execute associated functions
  if( intFlag & HIB_INT )
  {  
    
    delay(2000); //wait to power on properly
    
    //debugging blink
    for (int i=0;i<20;i++){
    Utils.blinkLEDs(125);
  }
    takeReadings();
    transmitReadings();
    intFlag &= ~(HIB_INT);
  }
  
  // Set Waspmote to Hibernate, waking up after 10 seconds
  PWR.hibernate("00:00:00:10",RTC_OFFSET,RTC_ALM1_MODE2);
}

void takeReadings(void){
  //power on agriboard
  SensorAgr.setBoardMode(SENS_ON);
  delay(1000);
  //------TEMP------
  //power up sensor
  SensorAgr.setSensorMode(SENS_ON, SENS_AGR_TEMPERATURE);
  delay(200);
  temp=SensorAgr.readValue(SENS_AGR_TEMPERATURE);
  //poweroff sensor
  SensorAgr.setSensorMode(SENS_OFF, SENS_AGR_TEMPERATURE);
  //------HUMIDITY------
  //powerup sensor
  SensorAgr.setSensorMode(SENS_ON, SENS_AGR_HUMIDITY);
  delay(400);
  RH=SensorAgr.readValue(SENS_AGR_HUMIDITY);
  //poweroff sensor
  SensorAgr.setSensorMode(SENS_OFF, SENS_AGR_HUMIDITY);
  //------SOILMOISTURE------
  //powerup sensor
  SensorAgr.setSensorMode(SENS_ON, SENS_AGR_WATERMARK_1);
  delay(300);
  soilmoist=SoilMoisture_readValue();
  //poweroff sensor
  SensorAgr.setSensorMode(SENS_OFF, SENS_AGR_WATERMARK_1);
  //------LUMINOSITY------
  //powerup sensor
  LightSensor_setSensorMode(SENS_ON);
  light=LightSensor_readValue();
  //power off sensor
  LightSensor_setSensorMode(SENS_OFF);
  
  //power off agriboard
  SensorAgr.setBoardMode(SENS_OFF);
  
  //convert float values to string - suitable for sending
  Utils.float2String(temp,tempArray,1);
  Utils.float2String(RH,RHArray,1);
  //Utils.float2String(soilmoist,soilmoistArray,2); ignore this one
  Utils.float2String(light,lightArray,1);
  
  RTC.ON();
  delay(20);
  auxtime=RTC.getTime();
  strcpy(timeStamp,auxtime+8);
  //store values to buffer
  sprintf(buffer,"-mac:%s%s -Time:%s -temp:%s -RH:%s%c -SM:%d -Lum:%s -bat:%d%c%c%c",
                  macHigh,macLow,timeStamp,tempArray,RHArray,'%',soilmoist,lightArray,PWR.getBatteryLevel(),'%','\r','\n');
}//endof takeReadings



void transmitReadings(void){
 
  paq_sent=(packetXBee*) calloc(1,sizeof(packetXBee));
  paq_sent->mode=BROADCAST;
  paq_sent->MY_known=0; 
  paq_sent->packetID=0x52; 
  paq_sent->opt=0;
  xbeeZB.hops=0; 
  xbeeZB.setOriginParams(paq_sent,MAC_TYPE);
  xbeeZB.setDestinationParams(paq_sent, direccion, buffer, MAC_TYPE, DATA_ABSOLUTE);
  xbeeZB.sendXBee(paq_sent);
 
  free(paq_sent);
  paq_sent = NULL; 
}//endof transmitReadings

//get soilmoist reading and convert to cb
uint16_t SoilMoisture_readValue(void){
  uint16_t freq=0;
  //get the frequency reading
  freq=SensorAgr.readValue(SENS_AGR_WATERMARK_1);
  //USB.println("frequency: ");
  //USB.print(freq);
  //USB.println("");
  //convert frequency to centibar
  uint16_t cb=0;
  cb=(150940 - 19.74*freq)/(2.8875*freq - 137.5);
  return cb;
}

//set lum sensor on/off
void LightSensor_setSensorMode(uint8_t mode)
{
  if(mode==SENS_ON) digitalWrite(SENS_SWITCH_4, HIGH);
  if(mode==SENS_OFF) digitalWrite(SENS_SWITCH_4, LOW);
}

//get lum reading
uint16_t LightSensor_readValue(void)
{
   uint16_t aux=0;
   digitalWrite(SENS_MUX_SEL, HIGH); // Volts
   aux=analogRead(ANALOG6);
   digitalWrite(SENS_MUX_SEL, LOW);
   return aux;
}




Top
 Profile  
 
 Post subject: Re: Time stamp and xbee packet
PostPosted: Thu Mar 22, 2012 7:20 pm 

Joined: Mon Sep 28, 2009 1:06 pm
Posts: 7440
aggelos,

Do not worry about your large code, it is well structured and clear.

So, you do not have communication problems due to your are receiving data, and also you are able to read the right sensor values, Don't you?

Then, what happens if you print your buffer just after doing sprintf function? Is it correct?

You can try putting \r \n characters like this way, which is also valid:
Quote:
 //store values to buffer
  sprintf(buffer,"-mac:%s%s -Time:%s -temp:%s -RH:%s%c -SM:%d -Lum:%s -bat:%d%c/r/n",
                  macHigh,macLow,timeStamp,tempArray,RHArray,'%',soilmoist,lightArray,PWR.getBatteryLevel(),'%');


Moreover, pay attention to maximum frame payloads.

Let us know what you see.

Regards.


Top
 Profile  
 
 Post subject: Re: Time stamp and xbee packet
PostPosted: Tue Mar 27, 2012 12:43 pm 

Joined: Thu Feb 23, 2012 4:32 pm
Posts: 32
It was a maximum frame payload issue after all, this happens when you send too much characters with every packet.
I changed the sprint to
Quote:
  sprintf(buffer,"-mac:%s -ts:%s -tm:%s -RH:%s -SM:%d -b:%d%c%c",
                  macLow,timeStamp,tempArray,RHArray,soilmoist,PWR.getBatteryLevel(),'\r','\n');


and now im getting this per line which is what i want.
Quote:
΄~[00]_[00]}3Ά[00]@†‰XZ/[02]R[01]#[01][00]}3Ά[00]@†‰X-mac:40868958 -ts:09/10/25 - 08:32.19 -tm:22.9 -RH:19.12 -SM:33 -b:47


Top
 Profile  
 
 Post subject: Re: Time stamp and xbee packet
PostPosted: Tue Apr 17, 2012 9:16 am 

Joined: Mon Sep 28, 2009 1:06 pm
Posts: 7440
aggelos,

Glad to hear that your code is working.

Regards


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 1   [ 8 posts ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Libelium theme based on 610nm Style by Daniel St. Jules of http://www.gamexe.net


© Libelium Comunicaciones Distribuidas S.L. | Terms of use