Show Posts
Pages: [1] 2
1  Using Arduino / Networking, Protocols, and Devices / Response is not being receive always in XBEE on: January 16, 2014, 04:44:54 am
Hi
I am trying to know if I have a led On or Off with the XBee.

I am requesting to the router to send a signal to the coordinator to verify this.
My issue is that I'm not always receiving this signal.

This is my arduino code

Code:
#include <XBee.h>
#include <SoftwareSerial.h>
int LED = 11;                //Turn this LED on or off, depending on packet rx'd
int debugLED = 13;           //Flash light to indicate rx
int packet;
int pin=12;

XBee xbee = XBee();
XBeeResponse response = XBeeResponse();
// create reusable response objects for responses we expect to handle
ZBRxResponse rx64 = ZBRxResponse();

XBeeAddress64 addr64 = XBeeAddress64(0x0013a200, 0x408b2e66);
ZBTxStatusResponse txStatus = ZBTxStatusResponse();

uint8_t payload[]={3};
void setup() {
  // start serial
  xbee.begin(9600);
}

void sendCoordinator(){
  ZBTxRequest zbTx = ZBTxRequest(addr64, payload, sizeof(payload));
  xbee.send(zbTx);
}

void loop() {   
    xbee.readPacket();
   
    if (xbee.getResponse().isAvailable()) {
       digitalWrite(debugLED, HIGH);
       delay(1000);
       digitalWrite(debugLED, LOW);
     
      if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE) {
        // got a rx packet
        xbee.getResponse().getRx64Response(rx64);
        packet = rx64.getData(0);
       
       if(packet == 0x01){                  //If a '1' is pressed on keyboard side
         if(digitalRead(pin)== LOW){
           payload[0]=10;
         }
         sendCoordinator();
         if (xbee.readPacket(5000)) {
            xbee.getResponse().getZBTxStatusResponse(txStatus);
             if (txStatus.isSuccess() ) {
               digitalWrite(LED, HIGH);              //turn on red LED
             }
         }
         
       }
       else if(packet == 0x00){            //If a '0' was pressed on keyboard side
         digitalWrite(LED, LOW);               //turn off red LED
       }
       else if(packet == 0x02){
         if(digitalRead(pin)== HIGH){
           payload[0]=10;
         }
         else
         {
           payload[0]=20;
         }
         ZBTxRequest zbTx = ZBTxRequest(addr64, payload, sizeof(payload));
         xbee.send(zbTx);
         
         if (xbee.readPacket(5000)) {
//DEBUG
           digitalWrite(LED, HIGH);
           delay(2000);
           digitalWrite(LED, LOW);
            if (xbee.getResponse().getApiId() == TX_STATUS_RESPONSE) {
               xbee.getResponse().getZBTxStatusResponse(txStatus);
                if (txStatus.isSuccess()) {
//DEBUG
                  digitalWrite(debugLED, HIGH);
                  delay(2000);
                  digitalWrite(debugLED, LOW);
                }
             }
         }
         else
         {//DEBUG
           digitalWrite(debugLED, HIGH);
           delay(2000);
           digitalWrite(debugLED, LOW);
           delay(2000);
           digitalWrite(debugLED, HIGH);
           delay(2000);
           
         }
       }
       else{                               //Little debug flashing incase something other than
         for(int i = 0; i < 10; i++)           //'1' or '0' is rx'd.
         {
           digitalWrite(LED, HIGH);
           delay(1000);
           digitalWrite(LED, LOW);
         }
       }   
    }
    else{
     digitalWrite(LED, HIGH);
     delay(2000);
     digitalWrite(LED, LOW);
    }
   }
}

This is my java code.

My main issue is in this part  ApiId.ZNET_RX_RESPONSE, I'm not always receiving this,

Thanks in advance

Code:
    if (payload[0]==2){
      XBeeResponse resp = xbee.getResponse(500);
        System.out.println("Entro a ver el estatus");
       if(resp.getApiId() == ApiId.ZNET_RX_RESPONSE){

Code:

public class ArduinoXbee {
    public static void main(String[] args) throws XBeeException {
         XBee xbee = new XBee();
       
      try{
        //OPEN SERIAL PORT
            xbee.open("/dev/ttyUSB1", 9600);                 
           
            Scanner input = new Scanner(System.in);
            //XBeeAddress64 address64 = new XBeeAddress64(0, 0x13, 0xa2, 0, 0x40, 0x8b, 0x2e, 0x54); Mi xbee router
            XBeeAddress64 address64 = new XBeeAddress64(0, 0x13, 0xa2, 0, 0x40, 0x89, 0xec, 0x92); //xbee router Douglas
            int[] payload;
            payload = new int[1];
           
            System.out.println("Comando para el LED: 0 para APAGAR EL LED , 1 para ENCENDERLO");
            payload[0] = (int)input.nextByte();
               
            ZNetTxRequest request = new ZNetTxRequest(address64, payload);
           
            System.out.println("\nZB request is: " + request.getXBeePacket());

             while(true){

                try{
                    ZNetTxStatusResponse response = (ZNetTxStatusResponse) xbee.sendSynchronous(request, 100000);
 
                    request.setFrameId(xbee.getNextFrameId());

                    System.out.println("Response received"+ response);
                   
                    if (payload[0]==2){
                       
                        XBeeResponse resp = xbee.getResponse(500);
                        System.out.println("Entro a ver el estatus");
                        if(resp.getApiId() == ApiId.ZNET_RX_RESPONSE){
                            ZNetRxResponse rxResponse = (ZNetRxResponse)resp;
                            System.out.println("Received RX packet, option is " + rxResponse.getOption() + ", sender 64 address is " + ByteUtils.toBase16(rxResponse.getRemoteAddress64().getAddress()) + ", remote 16-bit address is " + ByteUtils.toBase16(rxResponse.getRemoteAddress16().getAddress()) + ", data is " + ByteUtils.toBase16(rxResponse.getData()));
                             int []x;
                             x=rxResponse.getData();
                             if(x[0]==10){
                                System.out.println("El foco se encuentra encendido");
                            }
                            else if (x[0]==20){
                                System.out.println("El foco se encuentra apagado");
                            }
                        else{
                            System.out.println("Hay un error");
                        }
                        }
                    }
                   
                    if(response.getDeliveryStatus() == ZNetTxStatusResponse.DeliveryStatus.SUCCESS){
                        System.out.println("Success!");
                    }else{
                        System.out.println("Packet failed due to" + response.getDeliveryStatus());
                    }
                }catch(XBeeTimeoutException e){
                System.out.println("Me ! Unable to send");
            }
                System.out.println("Enter a new command for LED: 0 to turn the LED OFF, 1 to turn on");
                payload[0] = (int)input.nextByte();
               
                request.setPayload(payload);
            }
      }finally{
          xbee.close();
      }
    }
}

2  International / Documentaci√≥n / Especificaciones de XBEE on: January 16, 2014, 01:26:32 am
Estoy trabajando con los XBEE Series 2.
E logrado hacerlos funcionar con placas arduino uno. Ahorita estoy en el proceso de saber mas sobre su funcionamiento.
Estoy viendo sus descripciones las cuales son las siguientes


Que es lo que quiere decir Outdoor RF line-of-sight Range y RF Data Rate
No entiendo muy bien esos conceptos.

Gracias
3  Topics / Home Automation and Networked Objects / Turning on a light bulb with Arduino and XBee on: April 26, 2013, 10:37:13 am
Hi
I am building a small circuit for turning on a lightbulb with my computer. Besides this the light bulb can be turn on manually by a switch.
For building this, I am using a switch bai ben (Interruptions from two points.) for doing this.

The problems is the following.
The application is working fine, when I send the sign for turning on the lightbulb turnos on, and when I send the sign for turning of, it goes of. But if I manually turn on the switch, and send the sign of turning of from the application, it doesn't work.

This is my arduino code. I have a transformer (converts 110V to 5V) connected to the PIN 12. This way I know when the lightbulb is ON or OFF.

Code:


int LED = 11;               
int debugLED = 13;           
int packet;                 
int analogValue;
int PIN=12;

void setup() {
  pinMode(LED, OUTPUT);
  pinMode(PIN, OUTPUT);
  pinMode(debugLED, OUTPUT);
  Serial.begin(9600);

}

void loop() {
 
 if(Serial.available() >= 16){       
   
   if(Serial.read() == 0x7E){         //Look for starting byte
   
     digitalWrite(debugLED, HIGH);   
     delay(1000);                         
     digitalWrite(debugLED, LOW);
     
     for(int i = 0; i <15; i++){     
       byte discard = Serial.read();
     }
     packet = Serial.read();         
   }
 }
 
 if(packet == 0x01){                  //If a '1' is pressed on keyboard side
   if(digitalRead(PIN)==LOW){
     digitalWrite(LED, HIGH);              //turn on red LED
     Serial.println("Recibi 1 voy a encender");
   }
   else{
     digitalWrite(debugLED, LOW);
   }
 }
 else if(packet == 0x00){            //If a '0' was pressed on keyboard side
   if((digitalRead(PIN)==HIGH)){
     digitalWrite(LED, LOW);      //turn off red LED
     Serial.println("Recibi 0 voy apagar");
   }
   else{
     digitalWrite(debugLED, HIGH);
   }
 }
 else{   //Little debug flashing incase something other than
   Serial.println("Recibi otra cosa: "+packet);
   for(int i = 0; i < 10; i++)           //'1' or '0' is rx'd.
   {
     digitalWrite(LED, HIGH);
     delay(500);
     digitalWrite(LED, LOW);
   }
 }
}




Any idea of this problem?
Thanks
4  Using Arduino / General Electronics / Re: I will like to know how many watts are consumed in a led on: April 19, 2013, 10:14:26 am
Thanks for your answer.
Lets said I want automatize the lights of my house. And I will like my system to tell me how many energy (Watt-hours) has been consumed. How can I do this? I have to calculate this for each light bulb? Or is there anyway to do this? Any idea
5  Using Arduino / General Electronics / I will like to know how many watts are consumed in a led on: April 18, 2013, 05:36:13 pm
Hi
I will like to know if it is possible to know how many watts are consumed in a led when it is turn on.

Lets said I have a led connected to PIN 13 in my arduino. For 3 hours with the following code
Code:
int LED=13;
void setup() {
  pinMode(LED, OUTPUT);
 
}

void loop()
{
 digitalWrite(LED, HIGH);
}

Is there a way to know how many watts where consumed?
6  Using Arduino / LEDs and Multiplexing / Re: How to know if a led is turn on on: April 18, 2013, 05:33:37 pm
Thanks a lot.
7  Using Arduino / LEDs and Multiplexing / How to know if a led is turn on on: April 18, 2013, 05:28:17 pm
Hi
I know the question sounds simple. But
I want to know if it is possible to know when a led is turn on.

Code:
int LED=13;
void setup() {
  pinMode(LED, OUTPUT);
  digitalWrite(LED, HIGH);
}

void loop()
{
 digitalWrite(LED, LOW);   
}

In this example I am turning of the LED. But I will like that this line  digitalWrite(LED, LOW);    only takes place when the led is on.

Any ideas?
8  Using Arduino / Programming Questions / Trying to turn on a led with Arduino and the xBee Api on: April 13, 2013, 01:32:33 am
Hi
I am trying to turn on a led from the pc, and this will make an arduino to do the work
I am completely new with the API. I guess I am having troubles still don't know where.

This is my java code

Code:
xbee.open("/dev/ttyUSB0", 9600);
XBeeAddress16 destino = new XBeeAddress16(0x0013A200, 0x408B2E54);
                        int[] payload = new int[] { 90, 180 };
                        TxRequest16 tx = new TxRequest16(destino,payload);
                        TxStatusResponse status = (TxStatusResponse)xbee.sendSynchronous(tx);
                        if (status.isSuccess()) {
                            System.out.println("Se conecto");
                        }
                        else
                        {
                            System.out.println("No se conecto");
                           
                        }

This is my arduino code

Code:
XBee xbee = XBee();
uint8_t payload[] = { 1, 0 };

XBeeAddress64 address= XBeeAddress64(0x0013A200, 0x408b2E66);
ZBTxRequest tx = ZBTxRequest(address, payload, sizeof(payload));

TxStatusResponse txStatus = TxStatusResponse();
int BELL = 2;
void setup() {
  xbee.begin(9600);
  pinMode(BELL, OUTPUT);
  digitalWrite(BELL, HIGH);
}

void loop()
  {
    int signal;
    xbee.send(tx);
    if (xbee.readPacket(5000)) {                 
        if (xbee.getResponse().getApiId() == TX_STATUS_RESPONSE) {
           xbee.getResponse().getZBTxStatusResponse(txStatus);
             
           if (txStatus.getStatus() == SUCCESS) {
                digitalWrite(BELL, LOW);
                delay(10000);
                digitalWrite(BELL, HIGH);
           } else {
             
           }
        }     
    } else {
   
    }
    delay(5000);
  }
I am getting this error in my Java code. [ERROR] [com.rapplogic.xbee.examples.ApiAtExample] at command failed
java.lang.IllegalArgumentException: input value [1286656] is larger than a byte

Thanks for your time.
9  Topics / Home Automation and Networked Objects / Re: Sending signals to the xBee Transmiter on: March 10, 2013, 02:10:04 am
What I have just read I have to change the mode to the API Mode to make this work the way I want.
10  Topics / Home Automation and Networked Objects / Re: Sending signals to the xBee Transmiter on: March 10, 2013, 12:22:12 am
The code is working perfectly.
The problem is I need a way to send signal to the transmitter. I want to have both way pressing the physical bottom or clicking in a website a bottom to send a signal.
11  Topics / Home Automation and Networked Objects / Re: Sending signals to the xBee Transmiter on: March 09, 2013, 11:28:42 pm
I have then working in transparent mode. I have my coordinator and router. They work perfect.
But right now I want to create a small web app. When I click the bottom on my web application a signal has to been send to the transmitter and the transmitter is going to send the signal to the receiver. (I assume it works that way). But not sure any link for that?
12  Topics / Home Automation and Networked Objects / Sending signals to the xBee Transmiter on: March 09, 2013, 11:11:37 pm
Hi
The title probably sounds strange, but I have two xBees. I use one for transmitting and another for receving. I am turning a led with a button
I want to create a small web application for turning on the led. So my idea is send data to the the transmitter and the transmitter will send data to the receiver. The problem is I am not sure if this is the correct way of doing it. Any idea?

The source code of both is the following

Transmitter Code
 
Code:
int BUTTON = 5;
  void setup()
  {
    pinMode(BUTTON, INPUT);
    Serial.begin(9600);
  }
 
  void loop()
  {
  // send a capital D over the serial port if the button is pressed
    if (digitalRead(BUTTON) == HIGH)
    {
      Serial.print('D');
      delay(10); // prevents overwhelming the serial port
    }
  }

Receiver Code

Code:
int BELL = 13;
  void setup()
  {
    pinMode(BELL, OUTPUT);
    Serial.begin(9600);
  }
 
  void loop()
  {
    // look for a capital D over the serial port and ring the bell if found
    if (Serial.available() > 0)
    {
      if (Serial.read() == 'D')
      {
        //ring the bell briefly
        digitalWrite(BELL, HIGH);
        delay(10);
        digitalWrite(BELL, LOW);
      }
    }
  }
13  Topics / Home Automation and Networked Objects / Re: Zigbee and arduino communications on: December 13, 2012, 10:10:16 pm
Thanks for all of your answers.
I find this website about constructing the wireless sensors. http://www.faludi.com/bwsn/

I think that this will be a great help.

14  Topics / Home Automation and Networked Objects / Re: Zigbee and arduino communications on: December 12, 2012, 11:29:16 pm
Thanks for your answers.

No, I've never heard of anyone controlling zigbee home automation with an arduino.  It may have been done, but I haven't ran across it yet.  I have a number of X10 devices, and I hate all of them.  They are very unreliable.
If you search around this forum though, there are several people that have controlled lights and appliances with various techniques using an Arduino and XBee or other radio device.

Do you have any pictures, videos or something with your x10 devices?

Checking the forum, I found this post http://arduino.cc/forum/index.php/topic,50486.msg360281.html#msg360281

This guys talks  about using x10device. Is this the same idea you were talking about.

Also I found this pdf http://www.houstondad.com/arduino/program_your_home.pdf
They recommend to use x10 Device will that be good or it will be a disadvantage?

XBee can be a solution with normal electric outlets?

15  Topics / Home Automation and Networked Objects / Re: Zigbee and arduino communications on: December 11, 2012, 05:37:48 pm
Forget it.
It was a bit on ebay. FInal Price was 250 $. (It is cheaper than original).

I think the best way for doing my project will be using x10.
Or do you know a way how to control the electric outlets using ZigBee?
Pages: [1] 2