Hi everyone,
I got problems when I tried to send temp and humid from dht11 to xbee coordinator via arduino ide. I am not receiving the data packet containing the temperature data from xbee end device sending data to coordinator. When Arduino is uploaded code, serial monitor displays some weird characters. I guess that the result was in incorrect format or sth .... Pls help me.
This is electronic components I use:
- Xbee S2C
- Arduino UNO
- Xbee Shield Arduino
- DHT11 sensor
- Xbee USB Adapter Ft232rl
Configure Xbee in XCTU:
Coordinator:
Function: ZIGBEE TH Reg
ID PAN ID: 1234
SC Scan Channels: 7FFF
JV Channel Verification: Disabled
CE Coordinator Enable: Enabled
AP API Enable: API enabled [1]
Router:
Function: ZIGBEE TH Reg
ID PAN ID: 1234
SC Scan Channels: 7FFF
JV Channel Verification: Enabled
CE Coordinator Enable: Disabled
AP API Enable: API enabled with Escaping [2]
Code Arduino:
#include <DHT.h>
#include <DHT_U.h>
#include <XBee.h>
#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT11
//Initialize XBee ZB client
XBee xbee = XBee();
//Payload byte array
uint8_t payload[8];
//Send to coordinator
XBeeAddress64 addr64 = XBeeAddress64(0, 0);
//Create request for XBee ZB
ZBTxRequest zbTx = ZBTxRequest(addr64, payload, sizeof(payload));
//Initialize DHT sensor module
DHT dht(DHTPIN, DHTTYPE);
void set_float_to_payload(float value, int index) {
uint8_t *value_array;
value_array = reinterpret_cast<uint8_t*>(&value);
for(int i=0; i<sizeof(value); i++){
payload[i+index] = value_array;
}
}
void setup() {
Serial.begin(9600);
xbee.setSerial(Serial);
dht.begin();
}
void loop() {
delay(3000);
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
set_float_to_payload(temperature, 0);
set_float_to_payload(humidity, 4);
xbee.send(zbTx);
}