Smart Plug based on Arduino Uno-Wireless SD Shield-Xbee S2 Api mode

Hello everyone !

I want to make a Smart Plug based on the things said in the title. I have one Arduino Uno connected to my Pc with a shield an an xbee and an Arduino with a shield and an xbee connected to my sensors and plug.
I have succesfully measured, sent and recieved tha data that i read from my plug and now i want to add a relay, which will be controlled from the pc. How can i make the coordinator Arduino not only recieve the measured data, but also send a signal to the remote relay to open or close it?

This is the code on the Arduino that is connected to the Pc

#include <XBee.h>

XBee xbee = XBee();
XBeeResponse response = XBeeResponse();
ZBRxResponse zbRx = ZBRxResponse();

  float f;
  byte a[4];    
} realPower, apparentPower, powerFactor, supplyVoltage, Irms;

void setup () {
  Serial.println("starting up yo!");

void loop () {

  // 1. This will read any data that is available:

  // 2. Now, to check if a packet was received: 
  if (xbee.getResponse().isAvailable()) {
    if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE) {
      Serial.println("Got an rx packet!");
      if (zbRx.getOption() == ZB_PACKET_ACKNOWLEDGED) {
          // the sender got an ACK
          Serial.println("packet acknowledged");
                Serial.println("packet not acknowledged");
      Serial.print("checksum is ");
      Serial.println(zbRx.getChecksum(), HEX);
      Serial.print("packet length is ");
      Serial.println(zbRx.getPacketLength(), DEC);
      for (int i = 0; i < zbRx.getDataLength(); i++) {
         Serial.print("payload [");
         Serial.print(i, DEC);
         Serial.print("] is ");
         Serial.print(zbRx.getData()[i], HEX);
     for (int i = 0; i < xbee.getResponse().getFrameDataLength(); i++) {
         Serial.print("frame data [");
         Serial.print(i, DEC);
         Serial.print("] is ");
         Serial.println(xbee.getResponse().getFrameData()[i], HEX);
      realPower.a[0] = zbRx.getData(0);
      realPower.a[1] = zbRx.getData(1);
      realPower.a[2] = zbRx.getData(2);
      realPower.a[3] = zbRx.getData(3);
      apparentPower.a[0] = zbRx.getData(4);
      apparentPower.a[1] = zbRx.getData(5);
      apparentPower.a[2] = zbRx.getData(6);
      apparentPower.a[3] = zbRx.getData(7);
      powerFactor.a[0] = zbRx.getData(8);
      powerFactor.a[1] = zbRx.getData(9);
      powerFactor.a[2] = zbRx.getData(10);
      powerFactor.a[3] = zbRx.getData(11);
      supplyVoltage.a[0] = zbRx.getData(12);
      supplyVoltage.a[1] = zbRx.getData(13);
      supplyVoltage.a[2] = zbRx.getData(14);
      supplyVoltage.a[3] = zbRx.getData(15);
      Irms.a[0] = zbRx.getData(16);
      Irms.a[1] = zbRx.getData(17);
      Irms.a[2] = zbRx.getData(18);
      Irms.a[3] = zbRx.getData(19);
      Serial.print(" , ");
      Serial.print(" , ");
      Serial.print(" , ");
      Serial.print(" , ");
  } else if (xbee.getResponse().isError()){
    Serial.print("Error code:");

And this is the code on the remote Arduino

#include <XBee.h>
#include <EmonLib.h>             // Include Emon Library
EnergyMonitor emon1;             // Create an instance

uint8_t text[20];

XBee xbee = XBee();
XBeeAddress64 remoteAddress = XBeeAddress64(0x0013a200, 0x40ae9cb8);
ZBTxRequest zbTx = ZBTxRequest(remoteAddress, text, sizeof(text));

  float f;
  byte a[4];    
} realPower, apparentPower, powerFactor, supplyVoltage, Irms;

void setup () {
  emon1.voltage(2, 189.94, 1.7);  // Voltage: input pin, calibration, phase_shift
  emon1.current(1, 28.34);       // Current: input pin, calibration.

void loop () {
  //text[0] = pin1 >> 8 & 0xff;
  //text[1] = pin1 & 0xff;
  realPower.f       = emon1.realPower;
  apparentPower.f   = emon1.apparentPower;    //extract Apparent Power into variable
  powerFactor.f     = emon1.powerFactor;      //extract Power Factor into Variable
  supplyVoltage.f   = emon1.Vrms;             //extract Vrms into Variable
  Irms.f            = emon1.Irms;     
  text[0] = realPower.a[0];
  text[1] = realPower.a[1];
  text[2] = realPower.a[2];
  text[3] = realPower.a[3];
  text[4] = apparentPower.a[0];
  text[5] = apparentPower.a[1];
  text[6] = apparentPower.a[2];
  text[7] = apparentPower.a[3];
  text[8] = powerFactor.a[0];
  text[9] = powerFactor.a[1];
  text[10] = powerFactor.a[2];
  text[11] = powerFactor.a[3];
  text[12] = supplyVoltage.a[0];
  text[13] = supplyVoltage.a[1];
  text[14] = supplyVoltage.a[2];
  text[15] = supplyVoltage.a[3];
  text[16] = Irms.a[0];
  text[17] = Irms.a[1];
  text[18] = Irms.a[2];
  text[19] = Irms.a[3];

Hello, I've been trying to do a project using a current clamp, like you! How did you configure the Xbees?

I need to send the readings from Uno to Mega through Xbee.. If I use the ADC from the xbee i can easily send values, but I need to use an arduino to read A0 and do the calcs of power..

Thanks, António