hello everyone,
I am now doing a project with Xbee S2C and arduino Uno.
Main Objective of the project is to transmit sound sensor data to coordinator node from 4 sound sensors. Sensor will be distributed around the room and they will send data to coordinator for monitoring.
Coordinator need to receive all data from router. The router has to inform their number like <high,router1> , <low,router2>.
My XBEE configuration
For Coordinator
Firmware - ZIGBEE TH Reg 4060
Pan ID - 1997
DH - 13A200
DL - FFFF
API - enabled
For Router
Firmware - ZIGBEE TH Reg 4060
Pan ID - 1997
DH - 13A200
DL - FFFF
API - enabled
XBee library file that i am using (GitHub - andrewrapp/xbee-arduino: Arduino library for communicating with XBee radios in API mode)
My Transmitter Code
include <SoftwareSerial.h>
#include <Printers.h>
#include <XBee.h>
#include<time.h>
#include<stdlib.h>
#define SOP '<' // start of packet
#define EOP '>' // end of packet
int sensorValue = analogRead(A0);
int soundthreshold = 500;
int data[1];
XBee xbee = XBee();
XBeeAddress64 addr64 = XBeeAddress64(0x0013A200,0xFFFFFFFF);
uint8_t input = 0;
SoftwareSerial XBee(2,3); //Rx,Tx
void setup() {
Serial.begin(9600);
pinMode(sensorValue,OUTPUT);
XBee.begin(9600);
Serial.println("starting");
srand((unsigned)time(NULL));
}
void loop() {
uint8_t i = 0;
uint8_t data[1];
uint8_t receivedChar = '0';
boolean newData = false;
int sensorValue = analogRead(sensorValue);
if(sensorValue > 500)
{
Serial.println("high1"); //change in high1 2 3
}
else if(sensorValue < 500)
{
Serial.println("low1");
}
data[0]= sensorValue;
ZBTxRequest zbTx1 = ZBTxRequest(addr64, data, sizeof(data));
delay(500);
Serial.println("starting Tx");
Serial.print("Data sent: \t");
Serial.println(data[0]);
delay(500);
xbee.send(zbTx1);
Serial.println("broadcasting");
delay(500);
}
My Coordianator Code
#include <Printers.h>
#include <XBee.h>
#include <SoftwareSerial.h>
int data[5];
XBee xbee = XBee();
XBeeResponse response = XBeeResponse();
ZBRxResponse rx = ZBRxResponse();
SoftwareSerial XBee(2,3); //Rx,Tx
uint8_t count = 0;
String sample = "";
void setup()
{
Serial.begin(9600);
XBee.begin(9600);
}
void loop()
{
uint8_t receivedData[4];
byte* dataPointer;
xbee.readPacket();
Serial.println("Reading for Packet");
delay(500);
if(xbee.getResponse().isAvailable())
{
Serial.print("Packet Available: ");
Serial.println(count);
delay(500);
if(xbee.getResponse().getApiId() == ZB_RX_RESPONSE)
{
xbee.getResponse().getZBRxResponse(rx);
delay(300);
dataPointer = reinterpret_cast<byte *>(receivedData);
for(int n =0; n < rx.getDataLength(); n++)
{
*dataPointer = rx.getData(n);
dataPointer += 1;
}
Serial.print("Packet Received: ");
for (byte n = 0; n < 4; n++)
{
Serial.println(receivedData[n]);
}
Serial.print("count: ");
count++;
Serial.println(count);
delay(1500);
}
}
else if(xbee.getResponse().isError())
{
Serial.print("Error Reading Packet. Error Code: ");
Serial.println(xbee.getResponse().getErrorCode());
delay(500);
}
else
{
Serial.println("Packet Not Found");
delay(500);
}
}
I am sorry for that there are so many unnecessary stuffs in code because I take this code from other people. I think both the coordinator and router is not working and show not output. I really have no idea what to do , I am new to this XBee stuff and noob at programming.
Coordinator Wiring
Router wiring
Note : I am now trying to read Building Wireless Sensor Networks Using Arduino and trying to use code from that book but it is not working.
I really hope that somebody could help me. If there is more information need , I can provide.