I currently have a network of wireless 6 Zigbee modules sending temperature readings data to a central Zigbee coordinator.
At present these temperatures are being read through serial monitor and as they are coming through very quickly and in vast amount they are difficult to follow.
What I would like is an interface that looks like this
[login to view URL];current=[login to view URL]
basically i need 6 boxes that read the address of the sending zigbee and display the temperature also I would like this temperature saving to an output file.
The zigbees are connected to arduino boards and here is the code that operate them
Arduino code for Coordinator operating in API mode
#include <XBee.h> // include library available at: [login to view URL]
#include <NewSoftSerial.h> // include library available at: [login to view URL]
uint8_t ssRX = 9;
uint8_t ssTX = 10;
NewSoftSerial nss(ssRX, ssTX);
XBee xbee = XBee();
XBeeResponse response = XBeeResponse();
// create reusable response objects for responses we expect to handle
ZBRxResponse rx = ZBRxResponse();
ModemStatusResponse msr = ModemStatusResponse();
int statusLed = 13;
int errorLed = 13;
int dataLed = 13;
int B=4090;
float T1 = 298.15;
float RT1 = 33000;
float RT2 = 0;
float T2 = 0;
void printDouble( double val, unsigned int precision){
/* This function prints val with number of decimal places determine by precision*/
[login to view URL] (int(val)); //prints the int part
[login to view URL]("."); // print the decimal point
unsigned int frac;
if(val >= 0)
frac = (val - int(val)) * precision;
else
frac = (int(val)- val ) * precision;
[login to view URL](frac,DEC) ;
}
void setup() {
pinMode(statusLed, OUTPUT);
pinMode(errorLed, OUTPUT);
pinMode(dataLed, OUTPUT);
// start serial
[login to view URL](9600);
// start soft serial
[login to view URL](9600);
}
void loop() {
// keep on reading until it receives a packet
[login to view URL]();
if ([login to view URL]().isAvailable()) {
// have picked up something
if ([login to view URL]().getApiId() == ZB_RX_RESPONSE) {
// got a zigbee rx packet
// fills the zigbee rx class
[login to view URL]().getZBRxResponse(rx);
[login to view URL]("Received Packet From: ");
//prints source address of the transmitting device
[login to view URL]([login to view URL]().getMsb(), HEX);
[login to view URL]([login to view URL]().getLsb(), HEX);
[login to view URL]("");
}
byte dataByte1 = ([login to view URL]().getFrameData()[11]);
byte dataByte2 = ([login to view URL]().getFrameData()[12]);
unsigned int value = dataByte2;
value = value | (dataByte1 << 8);// uses the endian to rejoin the 2 bytes into 1 float
int Temp = value;//make the value a integer
//same temperature calculations as AT mode
RT2 = (RT1*(1024 - Temp))/Temp;
T2 = (B*T1)/(B-(T1*log(RT1/RT2)));
T2 = T2 - 273.15;
[login to view URL]("Temperature is: ");
printDouble(T2,100);
[login to view URL]("°C");
[login to view URL]("");
[login to view URL]("-------------------------------------");
[login to view URL]("");
// set dataLed PWM to value of the first byte in the data
analogWrite(dataLed, [login to view URL](0));
} else if ([login to view URL]().getApiId() == MODEM_STATUS_RESPONSE) {
[login to view URL]().getModemStatusResponse(msr);
// the local XBee sends this response on certain events, like association/dissociation
}
}
End Device operating in API mode
#include <XBee.h>
// create the XBee object
XBee xbee = XBee();
uint8_t payload[] = { 0, 0 };
// insert SH + SL Address of receiving XBee
XBeeAddress64 addr64 = XBeeAddress64(0x0013a200, 0x40320721);
ZBTxRequest zbTx = ZBTxRequest(addr64, payload, sizeof(payload));
ZBTxStatusResponse txStatus = ZBTxStatusResponse();
int pin5 = 0;
int statusLed = 13;
int errorLed = 13;
void flashLed(int pin, int times, int wait) {
for (int i = 0; i < times; i++) {
digitalWrite(pin, HIGH);
delay(wait);
digitalWrite(pin, LOW);
if (i + 1 < times) {
delay(wait);
}
}
}
void setup() {
pinMode(statusLed, OUTPUT);
pinMode(errorLed, OUTPUT);
[login to view URL](9600);
}
void loop()
{
// break down 10-bit reading into two bytes and place in payload
pin5 = analogRead(5);
payload[0] = pin5 >> 8 & 0xff;
payload[1] = pin5 & 0xff;
[login to view URL](zbTx);
// flash TX indicator
flashLed(statusLed, 1, 100);
// after sending a tx request, we expect a status response
// wait up to half second for the status response
if ([login to view URL](500)) {
// got a response!
// should be a znet tx status
if ([login to view URL]().getApiId() == ZB_TX_STATUS_RESPONSE) {
[login to view URL]().getZBTxStatusResponse(txStatus);
// get the delivery status, the fifth byte
if ([login to view URL]() == SUCCESS) {
// success. time to celebrate
flashLed(statusLed, 5, 50);
} else {
// the remote XBee did not receive our packet. is it powered on?
flashLed(errorLed, 3, 500);
}
}
} else {
// local XBee did not provide a timely TX Status Response -- should not happen
flashLed(errorLed, 2, 50);
}
delay(10000);
}
Dear Sir,
Mentor ICT is an Australian company based in Sydney-Australia
We are specialized in ICT (Information & Communication Technology) services including Custom software, Website development and ICT project Management
We have outstanding experience dealing with Serial/Parallel/LAN and Modem communications
please read your PMB for more details
Regards
George Kerollos PMP
Projects Manager
Mentor ICT