hello friends,
I have a problem with the transmission of data through xbee frames
I am making the measurement of a temperature sensor and hope that this forward through xbee pro s2 configured as API, (I am getting a gateway Libelium) but the plot I manage not require that I send the temperature value which is a type float, (I get the plot but not the value I want), not if someone can guide me on how to structure the program well to make me such action, because I have problems with the types of data handled in arduino .
the program is as follows:
#include <OneWire.h>
#include <XBee.h>
OneWire ds(53);
XBee xbee = XBee();
uint8_t payload[4];
// SH + SL Address of receiving XBee
XBeeAddress64 addr64 = XBeeAddress64(0x0013a200, 0x409e2ef3);
ZBTxRequest zbTx = ZBTxRequest(addr64, payload, sizeof(payload));
void setup(void) {
Serial.begin(9600);
xbee.begin(9600);
}
void loop(void) {
byte i;
byte present = 0;
byte type_s;
byte data[12];
byte addr[8];
float celsius, fahrenheit;
if ( !ds.search(addr)) {
Serial.println();
ds.reset_search();
delay(2500);
return;
}
ds.reset();
ds.select(addr);
ds.write(0x44, 1);
delay(1000);
present = ds.reset();
ds.select(addr);
ds.write(0xBE);
for ( i = 0; i < 9; i++) {
data = ds.read();
}
int16_t raw = (data[1] << 8 )| data[0];
if (type_s) {
raw = raw << 3;
if (data[7] == 0x10) {
raw = (raw & 0xFFF0) + 12 - data[6];
}
} else {
byte cfg = (data[4] & 0x60);
if (cfg == 0x00) raw = raw & ~7;
else if (cfg == 0x20) raw = raw & ~3;
else if (cfg == 0x40) raw = raw & ~1;
}
celsius = (float)raw / 16.0;
Serial.print(celsius); //EN EL SERIAL ME IMPRIME NORMALMENTE LA TEMPERATURA
//REALICE ESTOS PASOS PARA SACAR NUMERO POR NUMERO Y COLOCARLO EN LE PAYLOAD PERO NO LO
//CONSEGUI
int a=0, b=0, c=0, d=0, e=0;
a=celsius*100;
b=a/10;
c=a%10;
b=b/10;
d=b%10;
b=b/10;
e=b%10;
payload[0]=b;
payload[1]=e;
payload[2]='.';
payload[3]=d;
payload[4]=c;
xbee.send(zbTx);
}