Bonjour a tous,
L'objectif est d'etablir un mesh de xbees serie2 , j'en suis a la phase de test des engins et pour l'instant j'ai configuré avec XCTU deux xbees, en Digimesh 2.4, mode API1. Un est est en cooordinateur et l'autre en router.
Les tests sur XCTU se passent a merveille, je recupere bien les trames et bytes envoyés de l'un a l'autre.
J'avais l'intention de me servir de la lib conseillée par digi, j'ai donc modifié les exemples fournis avec, et la, c'est moins merveilleux.
Les messages passent correctement en broadcast (avec DH a 0x0 et DL à 0xFFFF), mais avec les adresses des xbee , rien n'est recu, et ce, que j'emmette avec le router ou avec le coordinateur...
Le code de l'emetteur:
#include <XBee.h>
#include <SoftwareSerial.h>
#define RX_PIN 2
#define TX_PIN 3
SoftwareSerial softSerial(RX_PIN, TX_PIN); // RX, TX
XBee xbee = XBee();
uint8_t payload[] = { 0, 0 };
uint8_t n = 0;
// SH + SL Address of receiving XBee
//XBeeAddress64 addr64 = XBeeAddress64(0x13a200, 0x4199F16A); // premier node (coordinateur)
//XBeeAddress64 addr64 = XBeeAddress64(0x13a200, 0x41928b7c); // deuxieme node (router)
XBeeAddress64 addr64 = XBeeAddress64(0x0, 0xFFFF); // broadCast
ZBTxRequest zbTx = ZBTxRequest(addr64, payload, sizeof(payload));
ZBTxStatusResponse txStatus = ZBTxStatusResponse();
void setup() {
Serial.begin(9600);
softSerial.begin(9600);
xbee.begin(softSerial);
}
void loop() {
n++;
payload[0] = payload[1];
payload[1] = n;
xbee.send(zbTx);
// flash TX indicator
Serial.println(F("Sending.."));
// after sending a tx request, we expect a status response
// wait up to half second for the status response
if (xbee.readPacket(500)) {
// got a response!
// should be a znet tx status
if (xbee.getResponse().getApiId() == ZB_TX_STATUS_RESPONSE) {
xbee.getResponse().getZBTxStatusResponse(txStatus);
// get the delivery status, the fifth byte
if (txStatus.getDeliveryStatus() == SUCCESS) {
// success. time to celebrate
Serial.println(F("Succès"));
} else {
// the remote XBee did not receive our packet. is it powered on?
Serial.println(F("Packet non recu"));
}
}
} else if (xbee.getResponse().isError()) {
Serial.print("Error reading packet. Error code: ");
Serial.println(xbee.getResponse().getErrorCode());
} else {
// local XBee did not provide a timely TX Status Response -- should not happen
Serial.println(F("Packet non transmit"));
}
delay(1000);
}
pour le recepteur:
#include <XBee.h>
#include <SoftwareSerial.h>
#define RX_PIN 2
#define TX_PIN 3
SoftwareSerial softSerial(RX_PIN, TX_PIN); // RX, TX
XBee xbee = XBee();
XBeeResponse response = XBeeResponse();
// create reusable response objects for responses we expect to handle
ZBRxResponse rx = ZBRxResponse();
ModemStatusResponse msr = ModemStatusResponse();
void setup() {
Serial.begin(9600);
softSerial.begin(9600);
xbee.begin(softSerial);
}
// continuously reads packets, looking for ZB Receive or Modem Status
void loop() {
xbee.readPacket();
if (xbee.getResponse().isAvailable()) {
// got something
if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE) {
// got a zb rx packet
// now fill our zb rx class
xbee.getResponse().getZBRxResponse(rx);
Serial.println(F("Received "));
uint8_t sizeOfData = rx.getDataLength();
for (uint8_t i = 0; i < sizeOfData; i++) {
Serial.print(rx.getData(i), HEX);
Serial.print("-");
}
Serial.println();
if (rx.getOption() == ZB_PACKET_ACKNOWLEDGED) {
// the sender got an ACK
Serial.println(F("Sender got an ACK"));
} else {
// we got it (obviously) but sender didn't get an ACK
Serial.println(F("Sender Didn't got an ACK"));
}
} else if (xbee.getResponse().getApiId() == MODEM_STATUS_RESPONSE) {
xbee.getResponse().getModemStatusResponse(msr);
// the local XBee sends this response on certain events, like association/dissociation
if (msr.getStatus() == ASSOCIATED) {
// yay this is great.
Serial.println(F("Association..."));
} else if (msr.getStatus() == DISASSOCIATED) {
// this is awful.. flash led to show our discontent
Serial.println(F("DéAssociation..."));
} else {
// another status
Serial.println(F("Autre message..."));
}
} else {
// not something we were expecting
Serial.println(F("Message non attendu..."));
}
} else if (xbee.getResponse().isError()) {
Serial.println(F("En erreur..."));
}
}
C'est mon premier projet a base de Xbee, je me doute bien que j'ai raté quelque chose quelque part, si qqelqu'un voit ce que c'est, j'arrette de me rendre fou....