Show Posts
Pages: 1 2 3 [4] 5
46  Using Arduino / Networking, Protocols, and Devices / Re: Xbee Api connection on: March 20, 2012, 02:42:50 am
Hi,

Paul or someone else, does anybody could help me, please??

I don't understand why xbee-library from google project doesn't work. The modules are associated, and I swear that router sends right the message, but coordinator can't read anything.

Regards.
47  Using Arduino / Networking, Protocols, and Devices / Re: Xbee Api connection on: March 15, 2012, 09:51:26 am
Uppsss, sorry!

I'll tell you my xbee configuration.

COORDINATOR - Receive data
PAN ID: 0  [coordinator assigns an Operating PAN-ID]
Scan Channel:  1FFE
Node Time: FF
Channel: x  [coordinator assigns the Operating channel]
API Mode: 2
Baud Rate: 6  [57600]


ROUTER - Send data
PAN ID: 0  [assigned by coordinator]
Scan Channel: 3FFE
Channel Verification: 1
Channel: x  [assigned by coordinator]
API Mode: 2
Baud Rate: 6  [57600]


The Operating PAN-ID and @PAN [MY] are assigned by the coordinator, and they are right, the modules have the same Operating PAN-ID, channel, and their @PAN are OK (coordinator has '0'@ and the router a different one).
This is why I said that network are correctly established. I checked them several times, and I think they are OK.

I'm trying to learn about it, so I will be pleased if someone could help me.

* I think these are all the necessary parameters to explain my problem, but if it will be more necessary, don't hesitate to ask them.
48  Using Arduino / Networking, Protocols, and Devices / Re: Xbee Api connection on: March 15, 2012, 03:01:58 am
Ok,

I modified a bit my code, but it doesn't work yet. I need to send and receive a simple message, but I want to use API mode to check (ACK, like TCP) the receivement of the message, so sender can re-send the message in case the message will be loose.

I write my code below, so if somebody could check it and tell me a tip, it would be great.

SEND:
Code:
#include <XBee.h>

XBee xbee = XBee();

uint8_t payload[] = { "OK" };
int pin = 13;
//char sendMsg[] = "OK";

XBeeAddress64 addr64 = XBeeAddress64(0x0013A200, 0x10101010);    //@MAC coordinator
ZBTxRequest zbTx = ZBTxRequest(addr64, payload, sizeof(payload));
ZBTxStatusResponse txStatus = ZBTxStatusResponse();

void setup() {
  pinMode(pin, OUTPUT);

  xbee.begin(57600);
}

void loop() {   
  digitalWrite(pin, HIGH);
 
//  payload = (uint8_t)sendMsg;
//  Serial.print("Send Message: [");
//  Serial.print(payload);
//  Serial.println("]");
 
  xbee.send(zbTx);
  Serial.println("Sending TX packets.");

  if (xbee.readPacket(5000)) {
    Serial.println("\tHaving Response.");
   
    if (xbee.getResponse().getApiId() == ZB_TX_STATUS_RESPONSE) {
      xbee.getResponse().getZBTxStatusResponse(txStatus);
      Serial.println("\t\tTX STATUS");
     
      if (txStatus.getDeliveryStatus() == SUCCESS) {
        Serial.println("\t\t\tSUCCESS");
      }
    }
  }

  Serial.flush();
  delay(500);
  digitalWrite(pin, LOW);
  delay(5000);
}

RECEIVE:
Code:
#include <XBee.h>

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

ZBRxResponse rx = ZBRxResponse();

int pin = 13;
uint8_t *data;

void setup() {
  pinMode(pin, OUTPUT);

  xbee.begin(57600);
}

void loop() {
  digitalWrite(pin, HIGH);

  xbee.readPacket();
  Serial.println("Checking RX packets.");

  if (xbee.getResponse().isAvailable()) {
    Serial.println("There's some RX.");

    if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE) {
      Serial.println("\tThere's RX packet.");
      xbee.getResponse().getZBRxResponse(rx);
      data = rx.getData();
    }
  }
 
  Serial.flush();
  delay(500);
  digitalWrite(pin, LOW);
  delay(5000);
}
49  Using Arduino / Networking, Protocols, and Devices / Re: Can't configure S2B modules with x-ctu on: March 15, 2012, 02:48:20 am
Problem Fixed!!
50  Using Arduino / Networking, Protocols, and Devices / Re: Xbee Api connection on: March 13, 2012, 04:11:51 am
Thanks!!

But this isn't the case, it isn't calling a function, it's just a cast. For example, if it works, I'll do "uint8_t mSG = (uint8_t) char data".

It won't work. The cast I'm trying to do didn't work because the compiler doesn't know how to convert them. That's the conclusion I get.

Regards.
51  Using Arduino / Networking, Protocols, and Devices / Re: Xbee Api connection on: March 12, 2012, 05:44:58 am
Hi,

I'm trying to use the XBEE library to work in API mode, but even programming my arduinos (plus xbee shield) with these api examples, it doesn't work.

I'm reading the library but I've looked that I can only send uint8_t data, and what if I want to send a string? How can I do this??

If I only want send and receive a packet with some data, how can I do this more simply??

52  Using Arduino / Project Guidance / Re: Arduino Mega2560 + GPS ublox LEA-5H on: March 12, 2012, 03:03:22 am
Hi again,

I tried it with Arduino UNO without library code, and it works fine!!

So I think the problem is serial, there has to be a way to connect GPS with Arduino MEGA that works correctly.

I'll try to find it.

Regards.
53  Using Arduino / Networking, Protocols, and Devices / Re: Problem sending data in api mode on: March 07, 2012, 09:45:19 am
Hi,

I'm trying to use the xbee library to make a communication between some ZB S2B modules.

I configured them in API mode (2, with escape character), at 57600 bps, and let them to associate themselves. It seems like all is OK. But I can't see any transmitting message between them, even when I use the library's examples.

I modified these examples, only to print message in serial, to try watching more info. I put them below.

Could you help me, please??

Code:
#include <XBee.h>

/*
This example is for Series 2 XBee
 Sends a ZB TX request with the value of analogRead(pin5) and checks the status response for success
 */

// create the XBee object
XBee xbee = XBee();

uint8_t payload[] = {
  0, 0 };

// SH + SL Address of receiving XBee
XBeeAddress64 addr64 = XBeeAddress64(0x0013a200, 0x408615d9);    //@MAC coordinator
ZBTxRequest zbTx = ZBTxRequest(addr64, payload, sizeof(payload));
ZBTxStatusResponse txStatus = ZBTxStatusResponse();

int pin5 = 0;

int statusLed = 13;
int errorLed = 13;

unsigned long start = millis();
//___________________________________________________________________________________________

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);

  Serial.begin(57600);
  Serial.println("\n\t... XBee - ZB ...\n");

  xbee.begin(57600);

  flashLed(statusLed, 1, 500);
}
//___________________________________________________________________________________________

void loop() {   
  Serial.flush();

  // break down 10-bit reading into two bytes and place in payload
  pin5 = 135;    //analogRead(5);
  Serial.print("pin5 value: [");
  Serial.print(pin5);
  Serial.println("]");
  payload[0] = pin5 >> 8 & 0xff;
  payload[1] = pin5 & 0xff;

  xbee.send(zbTx);
    Serial.println("Sending TX packets.");

  // flash TX indicator
  flashLed(statusLed, 1, 100);

  // after sending a tx request, we expect a status response
  // wait up to 5 seconds for the status response
  if (xbee.readPacket(5000)) {
    // got a response!
    Serial.println("\tHaving Response.");

    // should be a znet tx status           
    if (xbee.getResponse().getApiId() == ZB_TX_STATUS_RESPONSE) {
      xbee.getResponse().getZBTxStatusResponse(txStatus);
      Serial.println("\t\tTX STATUS");

      // get the delivery status, the fifth byte
      if (txStatus.getDeliveryStatus() == SUCCESS) {
        // success.  time to celebrate
        flashLed(statusLed, 5, 500);
        Serial.println("\t\t\tSUCCESS");
      }
      else {
        // the remote XBee did not receive our packet. is it powered on?
        flashLed(errorLed, 3, 500);
        Serial.println("\t\t\tERROR");
      }
    }
  }
  else if (xbee.getResponse().isError()) {
    //nss.print("Error reading packet.  Error code: "); 
    //nss.println(xbee.getResponse().getErrorCode());
    Serial.println("\tWrong Response.\n");
  }
  else {
    // local XBee did not provide a timely TX Status Response -- should not happen
    flashLed(errorLed, 2, 500);
    Serial.println("\tNo Response.");
  }

  Serial.flush();
  delay(5000);
}

Code:
#include <XBee.h>

/*
This example is for Series 2 XBee
 Receives a ZB RX packet and sets a PWM value based on packet data.
 Error led is flashed if an unexpected packet is received
 */

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;
//___________________________________________________________________________________________

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);
  pinMode(dataLed,  OUTPUT);
 
  Serial.begin(57600);
  Serial.println("\n\t... XBee - ZB ...\n");

  // start serial
  xbee.begin(57600);

  flashLed(statusLed, 1, 500);
}
//___________________________________________________________________________________________

// continuously reads packets, looking for ZB Receive or Modem Status
void loop() {

  xbee.readPacket();
  Serial.println("Checking RX packets.");

  if (xbee.getResponse().isAvailable()) {
    // got something
    Serial.println("There's some RX.");

    if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE) {
      // got a zb rx packet
      Serial.println("\tThere's RX packet.");

      // now fill our zb rx class
      xbee.getResponse().getZBRxResponse(rx);

      if (rx.getOption() == ZB_PACKET_ACKNOWLEDGED) {
        // the sender got an ACK
        flashLed(statusLed, 10, 100);
        Serial.println("\t\tACK");
        Serial.print("\n\tData: ");
        Serial.println(rx.getData(0));
      }
      else {
        // we got it (obviously) but sender didn't get an ACK
        flashLed(errorLed, 2, 200);
        Serial.println("\t\tACK ERROR");
      }
      // set dataLed PWM to value of the first byte in the data
//      analogWrite(dataLed, rx.getData(0));
    }
    else if (xbee.getResponse().getApiId() == MODEM_STATUS_RESPONSE) {
      xbee.getResponse().getModemStatusResponse(msr);
      // the local XBee sends this response on certain events, like association/dissociation
      Serial.println("\tThere's Status Rx.");

      if (msr.getStatus() == ASSOCIATED) {
        // yay this is great.  flash led
        flashLed(statusLed, 10, 100);
        Serial.println("\t\tASSOCIATED\n");
      }
      else if (msr.getStatus() == DISASSOCIATED) {
        // this is awful.. flash led to show our discontent
        flashLed(errorLed, 10, 100);
        Serial.println("\t\tDISASSOCIATED\n");
      }
      else {
        // another status
        flashLed(statusLed, 5, 100);
        Serial.println("\t\tOTHER STATUS\n");
      }
    }
    else {
      // not something we were expecting
      flashLed(errorLed, 1, 25);
      Serial.println("\tUnexpected Response\n");   
    }
  }
  else if (xbee.getResponse().isError()) {
    //nss.print("Error reading packet.  Error code: "); 
    //nss.println(xbee.getResponse().getErrorCode());
    Serial.println("There's no RX packets.\n");
  }
 
  delay(5000);
}
54  Using Arduino / Project Guidance / Arduino Mega2560 + GPS ublox LEA-5H on: March 06, 2012, 08:49:27 am
Hi,

I'm trying to develop a software to manage the GPS, but it never return any value. I'm using an arduino mega2560 plus a GPS shield with uBlox LEA5-H.

It seems like it was a halt when microcontroller try to access to GPS address (0x42).

I tried reading directly from wire ports, and then using a library, but it doesn't matters, it didn't work yet.

Could someone help me about??

PD: I have attached the sketchs I used for, also the library.
55  Using Arduino / Networking, Protocols, and Devices / Can't configure S2B modules with x-ctu on: February 28, 2012, 09:27:33 am
Hi,

I'm trying to configure several modules so I can create a mesh network. But, first of all, I'm only trying with two modules (one coordinator and one router) in API mode (2).

First, with x-ctu, I changed modules function set to coordinator and router API, respectively. It works fine, I can read all default params perfectly.

But, then I want to change some parameters as:

- Router:
    JV: 0 to 1
    JN: 0 to 1
    NI: ROUTER
    BD: 3 to 6
    AP: 1 to 2

- Coordinator:
    NI: COORDINATOR
    BD: 3 to 6
    AP: 1 to 2

So, I write this parameters, with ot without, mark 'Always update firmware', it doesn't care, but when I reset the module and read again the parameters, all of them seem erased.

How can I configure these parameters in a right way?? Which is the problem that makes it doesn't write memory correctly?

Because of this, I can't establish communication between modules without doing this first.

Thanks in advance!!
56  International / Español / Re: XBEE Packet Structure on: February 27, 2012, 09:14:48 am
Gracias!!

Lo pruebo y te comento, porque estoy teniendo problemillas previos con la comunicación, así que vamos paso a paso.

57  Using Arduino / Storage / Re: New line on file Issue on: February 10, 2012, 03:05:08 am
Hi,

thanks!!

I'had to use 'File' type to fit the behaviour, but I don't like so much this way beacuse now I'm adding redundance to it.

I'm going to try finish my program and then I'll try to optimize my code.
58  Using Arduino / Storage / New line on file Issue on: February 08, 2012, 09:50:14 am
Hi,

I'm using an ethernet shield 05 on an arduino mega, and I have the nest issue, could someone help me with, please?

- I make a program with a web server which makes some measurements and write one by one in a file, so a client could read these values from a browser. But when I'm trying to write to a file continously, I mean: I opened a file, write on it, close it, and after a while, I repeat the operation. I want it adds lines, one after one. But even using the example, I could make it right. It always overwrite the file and only shows the last measurements done. How can I solve this?
Code:
[i]
#include <SD.h>
#include <SPI.h>
#include <Ethernet.h>

#define BUFSIZ 100

byte mac[] = { 0xAB, 0xCD, 0xEF, 0xFE, 0xDC, 0xBA };
byte ip[] = { 192,168,1, 2 };
byte gateway[] = {  192,168,1, 1 };
byte subnet[] = { 255, 255, 252, 0 };

Server server(80);

Sd2Card card;
SdVolume volume;
SdFile root, file;

void setup() {
  Serial.begin(9600);

  pinMode(53, OUTPUT);
  digitalWrite(53, HIGH);

 card.init(SPI_HALF_SPEED, 4);
 volume.init(&card);
 root.openRoot(&volume);

  Ethernet.begin(mac, ip);
  server.begin();
}

void loop() {
  ClientController();
  delay(10);
  
  PrintFile();
  delay(2000);
}

void PrintFile() {
  if (file.open(&root, "Probes.txt", FILE_WRITE)) {
    file.println("Trying to write several sentences...");
    file.close();
  }
}

void ClientController() {
  char clientline[BUFSIZ];
  int index = 0;

  Client client = server.available();
  if (client) {
    boolean current_line_is_blank = true;
    index = 0;

    while (client.connected()) {
      if (client.available()) {
        char c = client.read();

        if (c != '\n' && c != '\r') {
          clientline[index] = c;
          index++;
          if (index >= BUFSIZ)
            index = BUFSIZ -1;

          continue;
        }
        clientline[index] = 0;
        Serial.println(clientline);

        if (strstr(clientline, "GET / ") != 0) {
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();

          client.println("<h2>Files:</h2>");
          ListFiles(client, LS_SIZE);
        }
        else if (strstr(clientline, "GET /") != 0) {
          char *filename;

          filename = clientline + 5; // look after the "GET /" (5 chars)
          (strstr(clientline, " HTTP"))[0] = 0;
          Serial.println(filename);

          if (! (file.open(&root, filename, O_READ))) {
            client.println("HTTP/1.1 404 Not Found");
            client.println("Content-Type: text/html");  
            client.println();
            client.println("<h2>File Not Found!</h2>");
            break;
          }

          Serial.println("Opened!");

          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/plain");
          client.println();

          int16_t c;
          while ((c = file.read()) > 0) {
            client.print((char)c);
          }
          file.close();
        }
        else {
          client.println("HTTP/1.1 404 Not Found");
          client.println("Content-Type: text/html");
          client.println();
          client.println("<h2>File Not Found!</h2>");
        }
        break;
      }
    }
    delay(1);
    client.stop();
  }
}

void ListFiles(Client client, uint8_t flags) {
  dir_t p;
 
  root.rewind();
  client.println("<ul>");
  while (root.readDir(p) > 0) {
    if (p.name[0] == DIR_NAME_FREE) break;
    if (p.name[0] == DIR_NAME_DELETED || p.name[0] == '.') continue;
    if (!DIR_IS_FILE_OR_SUBDIR(&p)) continue;
 
    client.print("<li><a href=\"");
    for (uint8_t i = 0; i < 11; i++) {
      if (p.name[i] == ' ') continue;
      if ( i == 8 ) {
        client.print('.');
      }
      client.print(p.name[i]);
    }
    client.print("\">");
 
    for (uint8_t i = 0; i < 11; i++) {
      if (p.name[i] == ' ') continue;
      if ( i == 8 ) {
        client.print('.');
      }
      client.print(p.name[i]);
    }
 
    client.print("</a>");
 
    if (DIR_IS_SUBDIR(&p)) {
      client.print('/');
    }

    if (flags & LS_DATE) {
       root.printFatDate(p.lastWriteDate);
       client.print(' ');
       root.printFatTime(p.lastWriteTime);
    }
    if (!DIR_IS_SUBDIR(&p) && (flags & LS_SIZE)) {
      client.print(' ');
      client.print(p.fileSize);
    }
    client.println("</li>");
  }
  client.println("</ul>");
}
[/i]
  code tags added by moderator
59  Using Arduino / Installation & Troubleshooting / Re: Arduino Mega & Ethernet+SD Shield Problems on: February 08, 2012, 09:30:25 am
Ok, thanks!!

I'll try it on that way!!
60  Using Arduino / Installation & Troubleshooting / Re: Arduino Mega & Ethernet+SD Shield Problems on: February 08, 2012, 08:45:34 am
Thanks SurferTim. It's an Ethernet Shield 05. The first and third question are solved!!

The first formatting microSD again. And the third because those pins are used to microSD adapter.

But the second one, I'm still trying to solve it, I think it might be because of the type I'm using for files (SDfile instead of file), but I don't know why.

Regards.
Pages: 1 2 3 [4] 5