1

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

too honest for this site
  • 12,050
  • 4
  • 30
  • 52
Jeff Host
  • 39
  • 2
  • "Due to the fact my sensors are placed on a moving platform , during rotation, the data packets are lost" - There is no necessary causality between a miving sensor and data loss as you imply. – too honest for this site Mar 23 '16 at 23:29
  • i am sorry for confusion. i found when the sensors are rotataed with high speed, i dont get all the packets (all the sensordatas). Hence, i assumed there are some packetlos occuring or may be the antenna is not functioning at some angles of rotation. – Jeff Host Mar 23 '16 at 23:32
  • It still does not imply this cannot be changed (that's what your text implies). Anyway It is not clear what you are asking. I suspect this might not be the best place to ask such questions. Maybe you checking the FAQs for electronics? – too honest for this site Mar 23 '16 at 23:45
  • I am asking how to concate all the sensor datas (strings) to only one string ? I have written this in my question! – Jeff Host Mar 24 '16 at 00:32
  • What do you mean by "I am unable to do it"? What's the error/problem? Anyway I have problems with Strings; I always try to use fixed size. Declare a `char sendBuffer[BUFFLEN];`, with `BUFFLEN` set to a large enough value. Your longest string is more or less 100chars, so put something around 200). Then you can either 1) use `sprintf` function to write the buffer, 2) fill it a piece at a time, maybe writing directly to the end of the string by using `&sendBuffer[count]`, where `count` is the number of chars already written (you will have to keep track of it or use the `strlen` function) – frarugi87 Mar 24 '16 at 10:36

2 Answers2

0

There's no need to put all of the data into a single buffer and send it with Serial.write(). Making multiple calls to the function is fine, and the XBee module's packetization settings will determine when data is sent over the air. Unless you're using API mode, you really shouldn't count on the XBee grouping your data in any particular way -- think of it as sending in a stream to the remote device. You may receive the data in one or more chunks, and you'll need to stitch it back together on the remote end to make use of it.

And you can use Serial.print() to format your integers and floats:

Serial.print("URT*");
Serial.print(rawX_ADXL337);
Serial.print('*');
Serial.print(rawY_ADXL337);
Serial.print('*');
Serial.print(rawZ_ADXL337);
Serial.print('*');
Serial.print(rawX_ADXL377);
Serial.print('*');
Serial.print(rawY_ADXL377);
Serial.print('*');
Serial.print(rawZ_ADXL377);
Serial.print('*');
Serial.print(ax);
Serial.print('*');
Serial.print(ay);
Serial.print('*');
Serial.print(az);
Serial.print('*');
Serial.print(gx);
Serial.print('*');
Serial.print(gy);
Serial.print('*');
Serial.print(gz);
Serial.print('*');
Serial.print(mx);
Serial.print('*');
Serial.print(my);
Serial.print('*');
Serial.print(mz);
Serial.print('*');
Serial.print(wHighNow);
Serial.print('*');
Serial.print(wLowNow);
Serial.print('\n');
tomlogic
  • 11,489
  • 3
  • 33
  • 59
  • Does this method also allows the floating points to be sent directly, for example 3999.99. Due to this reason i was sending as a string and at the receiver side, i am converting it back to floating point number, – Jeff Host Mar 29 '16 at 22:20
  • Try it and find out. `Serial.print()` formats floats. – tomlogic Mar 30 '16 at 00:19
0

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

bsnayak
  • 58
  • 7