Post a new topicPost a reply Page 1 of 1   [ 9 posts ]
Author Message
 Post subject: Sending structure data with Xbee
PostPosted: Thu Jun 28, 2012 10:56 am 

Joined: Tue Jun 26, 2012 11:48 pm
Posts: 7
Hello again,
I'm try to send in one point of my waspmote program the data I receive unicast from the gateway to node1 to node 2 so what I did is just set the destination parameters to:
xbeeZB.setDestinationParams(paq_sent, node2, (xbeeZB.packet_finished[xbeeZB.pos-1]->data), MAC_TYPE, DATA_ABSOLUTE);

where xbeeZB.packet_finished[xbeeZB.pos-1]->data is the data I receive but this is not working, the waspmote only sends the first byte of the data. I have also played with structures because the variables are not all the same in the packet. Any clues or any suggestion on how to send the exact data I receive to another node, I don't want to use any ready solution from zigbee I want to do this programmable inside waspmote.

Thanks!


Top
 Profile  
 
 Post subject: Re: Sending structure data with Xbee
PostPosted: Thu Jun 28, 2012 11:22 am 

Joined: Mon Sep 28, 2009 1:06 pm
Posts: 7479
Hi constantinos123,

that won't work, you should copy the data received into a string and add the '/0' character at the end, and use that string in your setDestinationParams function. something like this:

Code:
strncpy(data, xbeeDM.packet_finished[xbeeDM.pos-1]->data, xbeeDM.packet_finished[xbeeDM.pos-1]->data_length);
data[xbeeDM.packet_finished[xbeeDM.pos-1]->data_length] = '/0';
xbeeZB.setDestinationParams(paq_sent, node2, data, MAC_TYPE, DATA_ABSOLUTE);


Anyway, if I understood correctly you are trying to program your own network solution, including network addressing, hopping, etc. If this is the case, XBee ZB is not the best election, since it is already implemented in the self module, you should better use XBee 802.15.4.

Regards.


Top
 Profile  
 
 Post subject: Re: Sending structure data with Xbee
PostPosted: Thu Jun 28, 2012 12:25 pm 

Joined: Tue Jun 26, 2012 11:48 pm
Posts: 7
Thanks for the reply I will try this and let you know, but that is not a solution to my biggest problem which is sending structure data. To make it more clear lets say I have define the structure Settings as shown below
Code:
typedef struct Settings {
  uint16_t MSG_to_Send;
  uint32_t MSG_Rate;
  uint8_t Payload_Size;
}__attribute__ ((packed)) Settings;


and then associating this structure with a pointer looking at a data array with enough space like this:

Code:
Settings *settingsTX
char dataTX[10] = {};
settingsTX=(Settings*)&(dataTX);
settingsTX->MSG_to_Send = 10;
settingsTX->MSG_Rate = 1000;
settingsTX->Payload_Size = 10;
dataTX[sizeof(Settings)] = '\0';  also tried '/0'


while I can print the dataTX over the USB and see that it has the correct values (A 0 E8 3 0 0 A)
Code:
for(int i=0; i<sizeof(Settings); i++) {
USB.print(dataTX[i], HEX);
USB.print(" ");
}


when I try to send it over the ratio using:
Code:
xbeeZB.setDestinationParams(paq_sent, node2, dataTX, MAC_TYPE, DATA_ABSOLUTE)

I only get one byte of data (0A)
Any suggestion on this problem?
Thank you!


Top
 Profile  
 
 Post subject: Re: Sending structure data with Xbee
PostPosted: Thu Jun 28, 2012 1:57 pm 

Joined: Tue Jun 26, 2012 11:48 pm
Posts: 7
I have also tried the solution with strncpy

Code:
char *dataTX = (char*)calloc(1,xbeeZB.packet_finished[xbeeZB.pos-1]->data_length+1);
strncpy(dataTX, xbeeZB.packet_finished[xbeeZB.pos-1]->data, xbeeZB.packet_finished[xbeeZB.pos-1]->data_length);
dataTX[xbeeZB.packet_finished[xbeeZB.pos-1]->data_length] = '/0';

And still getting the same result, in fact when I print to USB the dataTX:
Code:
for(int i=0; i<xbeeZB.packet_finished[xbeeZB.pos-1]->data_length; i++) {
      USB.print(dataTX[i], HEX);
      USB.print(" ");
    }

I only get [A 0 0 0 0 0 0]
while the xbeeZB.packet_finished[xbeeZB.pos-1]->data has [A 0 E8 3 0 0 A]


Top
 Profile  
 
 Post subject: Re: Sending structure data with Xbee
PostPosted: Thu Jun 28, 2012 3:01 pm 

Joined: Mon Apr 04, 2011 6:19 am
Posts: 49
Hi constantinos123,

It looks to me that you are trying to send binary data and the function for sending the data will stop as soon as it receives a HEX 0 or '\0'. As you stated your data is HEX(A 0 E8 3 0 0 A), so it would make sense that it stopped at the first A. What I did to get around this is add a new function to the WaspXbeeCore:
Quote:
/* FUnction: Sets to 'paq' the destination address and binary data
 */
int8_t WaspXBeeCore::setDestinationParams(packetXBee* paq, const char* address, const char* data, uint8_t type, uint8_t off_type, uint8_t binary_data_size)
{
uint8_t* destination = (uint8_t*) calloc(8,sizeof(uint8_t));
    if( destination==NULL ) return -1;
    uint8_t i=0;
    uint8_t j=0;
    char aux[2];

    if( off_type==DATA_ABSOLUTE )
    {
        if( type==MAC_TYPE )
        {
            while(j<8)
            {
                aux[i-j*2]=address[i];
                aux[(i-j*2)+1]=address[i+1];
                destination[j]=Utils.str2hex(aux);
                i+=2;
                j++;
            }
            for(uint8_t a=0;a<4;a++)
            {
                paq->macDH[a]=destination[a];
            }
            for(uint8_t b=0;b<4;b++)
            {
                paq->macDL[b]=destination[b+4];
            }
            paq->address_type=_64B;
        }
        if( type==MY_TYPE )
        {
            while(j<2)
            {
                aux[i-j*2]=address[i];
                aux[(i-j*2)+1]=address[i+1];
                destination[j]=Utils.str2hex(aux);
                i+=2;
                j++;
            }
            paq->naD[0]=destination[0];
            paq->naD[1]=destination[1];
            paq->address_type=_16B;
        }
        data_ind=0;
    }
//Send Binary Data
    while(data_ind < binary_data_size)
    {
        paq->data[data_ind]=*data++;
        data_ind++;
        if( data_ind>=MAX_DATA ) break;
    }
    paq->data_length=data_ind;
    free(destination);
    return 1;

}


where binary_data_size is the size of your data packet. It would be nice if libelium would add a function like this to it's next api for sending binary data.

Hope this helps,

duff


Top
 Profile  
 
 Post subject: Re: Sending structure data with Xbee
PostPosted: Fri Jun 29, 2012 1:00 am 

Joined: Tue Jun 26, 2012 11:48 pm
Posts: 7
THANK YOU so much this is what was the problem, I'm still new with these motes and I didn't went that far to the core files but I have good TinyOS background and I was sure that the structure and pointers where correct. Ok you need to add some additional references to WaspXBeeCore.h and WaspXBeeCore.cpp to make the program to compile but it works fine with my first approach without any additional variables:
Code:
xbeeZB.setDestinationParams(paq_sent, node2, xbeeZB.packet_finished[xbeeZB.pos-1]->data, MAC_TYPE, DATA_ABSOLUTE,xbeeZB.packet_finished[xbeeZB.pos-1]->data_length);

I think that they definitely need to add a function like this to deal with binary data since sending only strings for an advance WSN is not a good way, you need to much space for something simple and maybe extra packets and also extra code and processing to get the values you want back. Hopefully they can include something like this next time.
Again thank you, you saved me big time!


Top
 Profile  
 
 Post subject: Re: Sending structure data with Xbee
PostPosted: Fri Jun 29, 2012 11:00 am 

Joined: Mon Sep 28, 2009 1:06 pm
Posts: 7479
Hi all,

thank you very much for your help, cmduffy, that is a weakness of our library that we are working to solve for the next version, your advice is very helpful.

Great to see your problem is solved for now, constantinos123, if you have more questions please do not hesitate to ask.

Best regards.


Top
 Profile  
 
 Post subject: Re: Sending structure data with Xbee
PostPosted: Fri Jun 29, 2012 4:54 pm 

Joined: Mon Apr 04, 2011 6:19 am
Posts: 49
Thanks All,

I agree it is beneficial for the waspmotes to send binary data!

Kind off this topic but another function that i added was setting up the deepSleep function with integers like:
Quote:
PWR.deepSleep(0,0,0,10,RTC_OFFSET,RTC_ALM1_MODE5,ALL_OFF);

If you want to do variable sleep rates this makes it alot easier to work with in my opinion. This is what I added to the WaspPWR:
Quote:
void WaspPWR::deepSleep(uint8_t day_date, uint8_t _hour, uint8_t _minute, uint8_t _second, uint8_t offset, uint8_t mode, uint8_t option)
{
  // Set RTC alarme to wake up from Sleep Power Down Mode
  RTC.setAlarm1(day_date,_hour,_minute,_second,offset,mode);
  RTC.close();
  switchesOFF(option);
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  sleep_enable();
  sleep_mode();
  sleep_disable();
  switchesON(option);
  RTC.ON();
  RTC.clearAlarmFlag();
  if( option & RTC_OFF ) RTC.OFF();
}



Anyways, just thought I would post this case anyone might think it could be useful.

duff


Top
 Profile  
 
 Post subject: Re: Sending structure data with Xbee
PostPosted: Tue Jul 03, 2012 4:24 pm 

Joined: Mon Sep 28, 2009 1:06 pm
Posts: 7479
cmduffy,

That is another interesting way for deep-sleep function usage.

Thanks for share it with us!!

Regards.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 1   [ 9 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