Search code examples
stringarduinomicrocontrollerzigbee

concatenate multiple strings to one for Arduino+Xbee


I am having an Arduino with some sensors on it. I am sending the sensor data to one remote PC with Xbee , which is a Xbee pro S1. The Xbee module functions at 38400 baud rate. I have total 15 sensor data and two time information to send over wireless. Due to the fact my sensors are placed on a moving platform , during rotation, the data packets are lost and hence, the complete set of sensor data with time information cannot be received at receiver side.

I have the following code template

Serial.write('U'); Serial.write('R'); Serial.write('T');
            Uint1.ival=rawX_ADXL337;  
            dtostrf(Uint1.ival,4, 2, dtostrfbuffer);
            Serial.write("*"); 
            Serial.write(dtostrfbuffer); 
                  Uint1.ival=rawY_ADXL337; 
                  dtostrf(Uint1.ival,4, 2, dtostrfbuffer);
                  Serial.write("*"); 
                  Serial.write(dtostrfbuffer);
            Uint1.ival=rawZ_ADXL337;
            dtostrf(Uint1.ival,4, 2, dtostrfbuffer);
            Serial.write("*");
            Serial.write(dtostrfbuffer);
                  Uint1.ival=rawX_ADXL377; 
                  dtostrf(Uint1.ival,4, 2, dtostrfbuffer);
                  Serial.write("*"); 
                  Serial.write(dtostrfbuffer);
            Uint1.ival=rawY_ADXL377;  
            dtostrf(Uint1.ival,4, 2, dtostrfbuffer);
            Serial.write("*"); 
            Serial.write(dtostrfbuffer);
                  Uint1.ival=rawZ_ADXL377;  
                   dtostrf(Uint1.ival,4, 2, dtostrfbuffer);
                  Serial.write("*"); 
                  Serial.write(dtostrfbuffer);
                //value after multiplication needed to be less than 2^15=32768
                                      Uint1.ival=ax; 
                                       dtostrf(ax,4, 2, dtostrfbuffer);
                                       Serial.write("*"); 
                                       Serial.write(dtostrfbuffer); 
                               Uint1.ival=ay;  
                               dtostrf(ay,4, 2, dtostrfbuffer);
                               Serial.write("*"); 
                               Serial.write(dtostrfbuffer); 
                                      Uint1.ival=az;  
                                      dtostrf(az,4, 2, dtostrfbuffer);
                                      Serial.write("*"); 
                                      Serial.write(dtostrfbuffer);
                               Uint1.ival=gx;  
                               dtostrf(Uint1.ival,4, 2, dtostrfbuffer);
                               Serial.write("*"); 
                               Serial.write(dtostrfbuffer); 
                                      Uint1.ival=gy;  
                                      dtostrf(gy,4, 2, dtostrfbuffer);
                                      Serial.write("*"); 
                                      Serial.write(dtostrfbuffer); 
                               Uint1.ival=gz;
                               dtostrf(gz,4, 2, dtostrfbuffer);
                               Serial.write("*"); 
                               Serial.write(dtostrfbuffer);
                                      Uint1.ival=mx;
                                      dtostrf(mx,5, 2, dtostrfbuffer);
                                      Serial.write("*"); 
                                      Serial.write(dtostrfbuffer); 
                               Uint1.ival=my;
                               dtostrf(my,4, 2, dtostrfbuffer);
                               Serial.write("*"); 
                               Serial.write(dtostrfbuffer);
                                      Uint1.ival=mz;
                                      dtostrf(mz,4, 2, dtostrfbuffer);
                                      Serial.write("*"); 
                                      Serial.write(dtostrfbuffer); 
                               Uint1.ival=wHighNow;
                               dtostrf(Uint1.ival,4, 2, dtostrfbuffer);
                               Serial.write("*"); 
                               Serial.write(dtostrfbuffer); 
                                      Uint1.ival=wLowNow;
                                      dtostrf(Uint1.ival,4, 2, dtostrfbuffer);
                                      Serial.write("*"); 
                                      Serial.write(dtostrfbuffer);   
                                      Serial.write("\n");
delay(100);

This looks like this

URT*364.00*348.00*432.00*350.00*427.00*357.00*0.22*0.18*0.81*1.00*0.73*-0.37* 0.15*-0.06*-0.19*6.00*17324.00
URT*364.00*348.00*432.00*349.00*428.00*357.00*0.22*0.18*0.81*1.00*0.73*-0.24* 0.16*-0.06*-0.19*8.00*2976.00
URT*361.00*345.00*428.00*345.00*424.00*353.00*0.22*0.18*0.81*1.00*0.73*-0.24* 0.16*-0.06*-0.19*9.00*53812.00
URT*363.00*347.00*430.00*349.00*427.00*356.00*0.23*0.18*0.81*1.00*0.61*-0.12* 0.15*-0.05*-0.19*11.00*39380.00

I have converted them to strings format (static char dtostrfbuffer[15];) and sending them individually. I am trying to form one single string with all the information using the following reference(ArduinoStringConcat) , but I am unable to do it.

How can I form one telegram with all sensor data inside and send it through Xbee? Please provide some demo example or any code snippet on my example.

is it feasible for Xbee pro s1 to send this final big telegram ?

Thanks


Solution

  • This is not a good idea to concatenate strings and send whole telegram.

    Send the same what you are doing but in the receiver side check for packetlos using a time function, comparing with your received packet (as you have time information already inside). You should also check the packetlength, if it contains all the sensor datas you are sending or not.

    idn = fscanf(DUT_port,'%s');
    L = length(idn);
    
    A = sscanf(idn,'%*c%f%*c%f%*c%f%*c%f%*c%f',[1 inf]);
    

    checkpacketloss { //using time comaprision

    //using total length

    }

    It is possible for Xbee to send complete telegram but unnecessary !

    I think, packetloss is occuring due to hardware, as the both antennas are not well oriented in plane