I am trying to configure the payload values for the xbee-arduino library, to send a 0 or 1 via xbee.
This is the code TX:
#include <XBee.h>
XBee xbee = XBee();
uint8_t payload[] = { 0, 0, 0, 0 };
XBeeAddress64 addr64 = XBeeAddress64(0x0, 0xFFFF);
ZBTxRequest zbTx = ZBTxRequest(addr64, payload, sizeof(payload));
ZBTxStatusResponse txStatus = ZBTxStatusResponse();
int pin3 = 0;
void setup() {
Serial.begin(9600);
xbee.setSerial(Serial);
}
void loop() {
pin3 = analogRead(3);
payload[0] = 1 >> 8 & 0xff; ///<----this is the value I need to send via xbee. See the 1!
payload[1] = 1 & 0xff;///<----this is the value I need to send via xbee. See the 1!
payload[2] = pin3 >> 8 & 0xff;
payload[3] = pin3 & 0xff;
xbee.send(zbTx);
if (xbee.readPacket(500)) {
if (xbee.getResponse().getApiId() == ZB_TX_STATUS_RESPONSE) {
xbee.getResponse().getZBTxStatusResponse(txStatus);
if (txStatus.getDeliveryStatus() == SUCCESS) {
} else {
}
}
} else if (xbee.getResponse().isError()) {
} else {
}
delay(1000);
}
I don´t recive this values (1 o 0) in the xbee RX, ...what am I doing wrong?
Thanks and regards
Hi,
Thank you for your response!
Coordinator XBee recive this packet in HEX:
7E,0,12,92,0,13,A2,0,40,B5,99,B7,4D,BE,41,1,0,0,8,1,47,D6,
...the pair values 1 and 47 (near at the end)is the value returned for the pin conected in my xbee TX...
....i need recive a number 1( or number 0) values, in some place (I think near 8 ), for make a 2 differents packets (I need 2 differents packets in my code...one with an number "1", and another with an number "0")
Thank you very much!
Whatever else is going on I don't understand these 2 lines
payload[0] = 1 >> 8 & 0xff; ///<----this is the value I need to send via xbee. See the 1!
payload[1] = 1 & 0xff;///<----this is the value I need to send via xbee. See the 1!
If you want to send either a 1 or a 0 why not just do it rather than messing around with bit shifting and applying bitwise operators ?
Sorry, I´m newbie.. ...I not really understand the solution you propose me. ¿You refers to I need to use in my code something like this? You mean this would work?
payload[0] = 1;
payload[1] = 1;
Thanks for your time
EDIT: I tried but does not work (I do not get the values (1 or 0) in the package)
Where did you get the code from ?
...I got from the examples coming with the xbee-arduino library (in IDE).
I tried to increase the number of elements in the array "payload", but the xbee receiving the same amount of HEX (23). ¿It should not send more number of values with more elements in the array?
I've also tried changing the values to the array (payload[0] = 1; or payload[0] = 0;), but I get the same packages in reciver xbee.
I do not understand, sorry if it's a very obvious thing, I am extremely novice...
EDIT: I use pair xbee´s Pro S2B. Reciver is conected in a arduino board with a shield. The other(transmiter) with a shield adapter (adafruit), atmega328p and a PIR sensor.
Omg !, I think I begin to understand the root of my problem. I connected xbee pins atmega series with the series this way:
RX-RX
TX-TX
I have swapped, i seem to now receive every X packets, the array values "payload" !! what a fool I am! Sorry to make you waste your time with such a basic thing. My apologies.
I guess I get bad packets (without the array data "payload") comes from the configuration of xbee where DIO3 have it configured as Digital Input to capture the state of a battery. The DIO is configured to receive data every second ... so I suppose there are the packages without the array information "payload". This I have not checked.
1000!thanks UKHeliBob and regards!
How are you reading a voltage with a digital input unless it is just reading either above or below a set value ?
I disabled the digital input / analog of xbee to only use the xbee-arduino library to compose packages. I will read the voltage PIR (activity or not) with atmega, and I will create a package to send with the library. Then I send differents packets (1 or 0) in IF sentence depending another values (hour of the day).
Thanks for helping!