Show Posts
Pages: 1 [2] 3 4
16  Using Arduino / Networking, Protocols, and Devices / Re: xbee + ethernet shield + arduino uno r2 on: October 30, 2012, 12:00:43 pm
Hi again,

I have an Arduino Ethernet, working with Arduino IDE v1.0.1, Xbee library (   XBee Arduino Library Version 0.3 - Supports Arduino 1.0) The code is practically the same, but I´m going to paste. Well, I tried the program only with the ethernet and it works. The web page is printed and the get and post request from the internet are answered. The problem appeared when I introduced this:

XBee xbee = XBee();
XBeeResponse response = XBeeResponse();  // paquete tipo respuesta
Rx16Response rx16 = Rx16Response();      // direccion de 16 bits, se puede usar la de 64
TxStatusResponse txStatus = TxStatusResponse();

so even if I don´t inilialize the module it doesn´t work. What I mean is including xbee.begin(9600), including or not the problem appears.

What is it the problem? With Serial.begin if I tried to know what´s happened on the monitor you could see this:


strange symbols GET / HTTP/1.1
strange symbols GET / HTTP/1.1
strange symbols GET / HTTP/1.1
strange symbols GET / HTTP/1.1
.... forever and ever

And in the browser instead of print the web page sometimes appears this over all the window:

and sometimes do nothing like if the page starts to load but at the end nothing happens. In the meantime on the monitor you can see like a GET frame came again and again in a infinite cycle as I showed you.

TEST 2. If I don´t use the serial to print on the monitor ....then I can´t check anything on the monitor and the web page is loading, nothing is charge ... I used CHROME so If I push F12 it allow to see the http frames, the code of the page... and I see that a GET is sent but ... it remains as pending and the code is never charged.

so is there conflicts between the libraries? Have I that respects some ports, change its maybe? Have I to enable the pin 10 as HIGH always I need to read from the SD? Maybe I forgetting basic tips or maybe just looking at the code you realize whats my problem.

thank you!
17  Using Arduino / Programming Questions / Re: webServer Example on: October 30, 2012, 06:12:05 am
Now It works!

Thank you!! And sorry for this, because at the end It was a version of the IDE problem.

18  Using Arduino / Programming Questions / Re: webServer Example on: October 30, 2012, 05:48:06 am
No. The example doesn't use mySerial and it doesn't print the value of

If you are going to modify the example, feel free to do a good job.

I was answering to your question about if there were something connecting to the ports.
I thought that maybe it could be a conflict using the Serial for that reason I prove with the SoftwareSerial library. But if I use the normal serial instructions it happens the same.

Arduino Ethernet, the FTDI board and the usb cable using just
char c = client.print() ;
Serial.print(" ");
it prints the strange symbols. Or if I change it for
char c = client.print() ;
Serial.print(" ");
it prints the numbers as you said with a space between then.

The strage thing is that when I tried this before no matter with which board it prints the http frame-
User-Agent:Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.19 (KHTML, like Gecko) Ubuntu/11.10 Chromium/18.0.1025.168 Chrome/18.0.1025.168 Safari/535.19

or something as this.

19  Using Arduino / Programming Questions / Re: webServer Example on: October 30, 2012, 05:22:54 am
Hi again,

more information:
*the IP address is not used. I've tried with a ping.
*I change the ethernet cable.
*when I connect the board I ping it and it responds.
*My operating system is Ubuntu 11 and since a week I 'm using arduino 1.0 IDE. So I erase the 022 ide version. I thought that maybe the libraries were causing some conflits...

I do not know what is the problem. Maybe you know basic tips I didn't realize.

Thank you!
20  Using Arduino / Programming Questions / Re: webServer Example on: October 30, 2012, 05:06:24 am
What is connected to pins 2 and 3? Where is this data supposed to go?

I use a FTDI Basic Breakout - 3.3V I only connect the tx y rx ports to pins 2 y 3. But I've just said the same happens if I used a Serial.print.

Do you have something connected to these pins? Or is this just garbage?
No, anything is connected to them.

Why can't you be bothered to separate the values being printed?

I've just used the example. When I've tried in other occasions It print out the values of these ports on the browser.

The expected answer is a http frame, but instead it shows the extrange symbols or the numbers.
21  Using Arduino / Programming Questions / webServer Example on: October 30, 2012, 04:27:48 am
Hi everyone,

I've recently had some errors on my program so I've changed the board, and I tried to use a reduced the code to find the error.
Right now I am testing the WebServer Example of the Ethernet Library. Well, I've used Serial.print and even mySerial.print (SoftwareSerial.h) to detect the error. Anyway with an Arduino Ethernet board (Arduino 1.0 IDE) when I write on a browser the IP address of the board nothing happens. Trying to understand what happens I added a print instruction to see where the program stops.
#include <SPI.h>
#include <Ethernet.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3);
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x5E, 0xF4 };
IPAddress ip(192,168,112, 31);

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);

void setup()
  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);

void loop()
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c =;
        mySerial.print(c); <<<<<----------------
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");

          // output the value of each analog input pin
          for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
            client.print("analog input ");
            client.print(" is ");
            client.println("<br />");
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
    // give the web browser time to receive the data
    // close the connection:

As you can see I introduce mySerial.print(c) and c is a char... It doesn't matter if it is mySerial.print (using SoftwareSerial library) or just using a Serial.print the result is this:

Uµ* „˜„65øÓ

or if I change the instruction to mySerial.print(;


numbers! and I imagine when it tries to print the correspondient character the result are extrange symbols

I don't understand what happens. Please help!

thank you!

22  Using Arduino / Networking, Protocols, and Devices / Re: xbee + ethernet shield + arduino uno r2 on: October 25, 2012, 09:50:46 am
It´s hard to explain to me in English ... but I could try.

This code belongs to a coordinator in a 802.15.4 network. It recolects the information of its remote nodes.

This information as you can see it treated by two functions, first it listens (readRequest) if there is a frame it save the information in the microSD as a file (generateJson).

Besides, It listens to incoming request from the internet, there are only 3 GET /HTTP1.1. GET /fioList HTTP1.1 and POST /changes. So as you can see there are functions that answer to them.

The microSD have as files as remote nodes are, and the html code of the webpage in html. So when you receive a GET /HTTP1.1 The board print to the client the page that reads from the microSD card.

The same  when a GET /fioList arrives ....

and when a POST message arrives the coordinator just pick up the two variables and send to nodes or save it for doing later.

Please ask me everything you don´t get. I know ... this is too much ... sorry and thank you.
23  Using Arduino / Networking, Protocols, and Devices / Re: xbee + ethernet shield + arduino uno r2 on: October 25, 2012, 09:42:18 am
void checkNewAddress ( uint8_t address) { // fioNumber, fioList variables globales
  for (int i = 0; i <= fioNumber; i++) {
      fioList[i] = address;
      fioNumber = 1;
      i = fioNumber +1;
    else{  // La lista no está vacía, chequea elemento a elemento
      if ( fioList[i] == address) {
        i = fioNumber +1;
      else { 
        if (i == fioNumber) {  // Luego de chequear toda la lista, si no coincide es un elemento nuevo
          fioList[i] = address;
          i = fioNumber +1;
      }  // end else2
    }  // end else1
  }  // end for   

} // end checkNewAddress

boolean sendRequest(uint8_t address, uint8_t data[], uint8_t length, uint8_t frameId) {
  uint16_t fio_address = 0x0000;
  uint8_t ack, option = 0, i = 0, timeWait;

  if (address == 0xFF) {
    fio_address = 0xFFFF;
    timeWait = 100;
  else {
    fio_address = 0x0000 + address;
    timeWait = 1000;
  Tx16Request tx = Tx16Request(fio_address, option, data, length, frameId);
  do {
    // Tx16Request (uint16_t addr16, uint8_t option, uint8_t *payload, uint8_t payloadLength, uint8_t frameId) (OBLIGATORIO PONERLOS TODOS!!)
    // Tx16Request (uint16_t addr16, uint8_t *payload, uint8_t payloadLength) Creates a Unicast Tx16Request with the ACK option and DEFAULT_FRAME_ID.
    if (xbee.readPacket(timeWait)) {  // got a response!
      if (xbee.getResponse().getApiId() == TX_STATUS_RESPONSE) {  // should be a znet tx status
        // get the delivery status, the fifth byte
        ack = txStatus.getStatus();
      }  // STATUS:  0 = success, 1 = when all retries are expered and no ACK is received
    i += 1;
  }while( (i < 3) && (ack != SUCCESS) );

  if (ack == SUCCESS) {
    return true;
  else {
    return false;

void listenForClient() {
  Client client = server.available(); // espera a que haya datos disponilbles
  if ( client )

void waitForRequest(Client client) {
  boolean currentLineIsBlank = true, flag = true;
  char c;
  bufferSize = 0;
  while (client.connected()) {
    while (client.available()) {     
      c =; //mySerial.print(c);
      if (c == '\n' && currentLineIsBlank) {
        // Here is where the POST data is. 
        while(client.available()) { // sino hay datos, no entra solo si hay datos
          c =;
          bufferData[bufferSize++] = c;
        bufferData[bufferSize] = 0;
        //Serial.print("\nDatos del Post: ");
        flag = true;
      else if (c == '\n') { // NEW LINE
        if (flag) {
          buffer[bufferSize] = 0;  // no me pinta salto de linea si bufferSize+1
          bufferSize = 0;
          flag = false;
        currentLineIsBlank = true;
      else if (c != '\r') { // you've gotten a character on the current line
        currentLineIsBlank = false;
        if ( bufferSize < bufferMax && flag )
          buffer[bufferSize++] = c;
    } // client.available
  } // client.connected
} // end void

void parseReceivedRequest(Client client) { // Petición recibida del tipo: "GET / HTTP/1.1"
  if ( strstr(buffer, "GET / HTTP/1.1") ) {  //  Serial.print("pinta la web");
  else if ( strstr(buffer, "GET /fioList HTTP/1.1") ) { //  Serial.println("respuesta fioList");
  else if ( strstr(buffer, "POST /changes HTTP/1.1") ) {  //  Serial.println("respuesta a un POST");
         client.println("HTTP/1.1 200 OK");


/*void sendPostResponse ( Client client) {
    client.println("HTTP/1.1 200 OK");

void sendGetResponse(Client client) {
  char filename[9];
  client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: application/json");
  client.println("Connection: close");
  for (int k = 0; k < fioNumber; k++) {
    sprintf (filename, "F%d.JS", fioList[k]); // si Fx.js guardado en la microSd como Fx.JS
    filePrint(filename, client);
    if ( (k+1) != fioNumber)

void webPrint (Client client) { 
  filePrint("SRV_2.txt", client);
// fuente:
void filePrint (char filename[9], Client client){
  if (myFile =, FILE_READ)) { 
    while ( myFile.available() ) {
      client.print( (char) );
    myFile.close();                 // CERRAR FICHERO
    mySerial.print("no leido");
  // OFF modo pregunta ( SIEMPRE DESPIERTO )
  // PERIODO modo envio de informacion periodica ( CON CICLOS DE SUEÑO )
  // ASINCRONO modo solo envio de info si es que hay cambios ( SIEMPRE DESPIERTO )
  // ASINCRONO + PERIODO modo envio de info si hay cambio ( CON CICLO DE SUEÑO )

void generateJson (uint8_t address, uint8_t temperature, uint8_t humidity, uint8_t sleepCycle, uint8_t asynchronus, uint8_t uid[]) {
  char filename[9];
  sprintf (filename, "F%d.JS", address);
  // String jsonString; Usando string no lo escribe correctamente
  if ( SD.exists(filename) ) {
  if (myFile) {  // si esta abierto ...
   myFile.print( address, DEC);
   myFile.print(address, DEC);
   myFile.print(temperature, DEC);
   myFile.print(humidity, DEC);
   myFile.print(asynchronus, DEC);
   myFile.print(sleepCycle, DEC);
   for ( int k = 0; k < 4; k++ ) {
     myFile.print(uid[k], HEX);
   myFile.close();// CERRAR FICHERO 

void createRequest(char buffer[]) {
  uint8_t frameId = millis()*0x00FF;
  char *asyn, *slpC, *equal;
  char sleepCycle[3], asynchronus[2];
  sleepCycle[0] = 0;
  asynchronus[0] = 0;
  equal = strstr(buffer, "=") + 1;
  slpC = strstr(equal, "&");
  strncat(sleepCycle, equal, slpC-equal);
  equal = strstr(slpC, "=") + 1;
  asyn = strstr(equal, "&");
  strncat(asynchronus, equal, asyn-equal);
  int asynchronus2 = atoi(asynchronus);
  int sleepCycle2  = atoi(sleepCycle);
  uint8_t data[] = {CONFIGURATION,2,sleepCycle2, asynchronus2};  // Configuration request: [0,2,SLEEP_CYCLE,ASYNCHRONUS]
  uint8_t length = sizeof(data);
  if ( sendRequest( 0xFF, data, length, frameId) == false ) {
    Serial.print("envio fallido");
    saveRequest(0xFF, data, length, frameId);
    flag2 = true; // al no ser enviada se levanta la bandera de pendientes
  else {  // se consiguió enviar
    sleepCycleCoord = sleepCycle2;
    asynchronusCoord = asynchronus2;
    if (flag1 == true){ // solo vale true la primera vez que se envía el cambio de ciclo.
      flag1 == false;
      time1 = millis(); // time 1 toma su primer valor

void saveRequest(uint8_t address, uint8_t data[], uint8_t length, uint8_t frameId) {
  char filename[9];
  int k = 0;
  sprintf (filename, "%d.txt", 1);
  myFile =, FILE_WRITE); 
  if (myFile) {  // si esta abierto ...
    myFile.print(address, HEX); myFile.print('\n');
    myFile.print(frameId, HEX); myFile.print('\n');
    while (k < length) { 
      myFile.print(data[k], HEX); myFile.print('\n');

void sendPendingRequest() { 
  uint8_t frameId, address, k = 0, data[] = {};
  char filename[6];
  sprintf (filename, "%d.txt", "1");
  if ( SD.exists(filename) ) {
    myFile =; 
    if (myFile) {  // si esta abierto ...
      address =;
      frameId =;
      while ( myFile.available() ){
        data[k] =;
      myFile.close();  // CERRAR FICHERO
      if ( sendRequest( address, data, sizeof(data), frameId ) == true ){
        flag2 = false;  // baja la bandera de pendientes
    }  // myFile
  } // SD.exists(filename)

void eraseRequest(char filename[9]) {
24  Using Arduino / Networking, Protocols, and Devices / Re: xbee + ethernet shield + arduino uno r2 on: October 25, 2012, 09:41:31 am
#include <XBee.h>
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>  // ocupa 5KB  
#include <NewSoftSerial.h>

#define PACKET_TYPE    0  // data[0]
#define PACKET_LENGTH  1  // data[1]
#define DATA_TYPE      2  // data[2]
#define REQUEST        1
#define RESPONSE       2
#define INFO           3
#define INIT           4

#define CONFIGURATION     0
#define HUMIDITY_FIELD    5
#define UID_FIELD        11
#define fioMax  30

XBee xbee = XBee();
XBeeResponse response = XBeeResponse();  // paquete tipo respuesta
Rx16Response rx16 = Rx16Response();      // direccion de 16 bits, se puede usar la de 64
TxStatusResponse txStatus = TxStatusResponse();

NewSoftSerial mySerial(2, 3);

byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x09, 0xF1 };
byte ip[]  = {192, 168, 112, 31 };
Server server(80);


uint8_t fioList[fioMax] = {};
uint8_t fioNumber = 0;
uint8_t uid[] = {0,0,0,0};
uint8_t initFrame[] = {REQUEST,1,INIT};

// Ethernet Shield uses pins 10,11,12,13.
#define bufferMax 128
int bufferSize;
char buffer[bufferMax], bufferData[bufferMax];;

// SD
File myFile;
#define ssPin       10
#define chipSelect   4

unsigned long time1, time2;
int sleepCycleCoord = 0, asynchronusCoord = 0;
boolean flag1 = true, flag2 = false;

void setup() {

  Ethernet.begin(mac, ip);
  if (!SD.begin(chipSelect)) {  
    mySerial.println("initialization failed!");
  fioNumber = 0;
  sendRequest(0xFF, initFrame, 3, millis()*0xFF);

void loop() {
  readRequest(); // lee paquetes de entrada continuamente
  time2 = millis();
  if (flag2 == true) { // si hay pendiente por hacer...
    if (time1-time2 >= sleepCycleCoord)
      time1 = millis(); // una vez alcanzado el tiempo de sueño se tiene que renovar

void readRequest() {
  uint8_t packetType, fioAddress; // variables locales
  if (xbee.readPacket(10)){
    if (xbee.getResponse().isAvailable()) {
      if (xbee.getResponse().getApiId() == RX_16_RESPONSE) { // se trata de un paquete RX
        xbee.getResponse().getRx16Response(rx16);            // almacena el paquete recibido en el objeto rx16
        packetType = rx16.getData(PACKET_TYPE);            // TIPO TRAMA data[0]          
        switch (packetType) {                                
          case INFO:      // TRAMA INFO
            digitalWrite(8, HIGH);      
            fioAddress = rx16.getRemoteAddress16();
            for ( int k = 0; k < 4; k++ ) {
              uid[k] = rx16.getData(UID_FIELD + k);}
              generateJson( fioAddress, rx16.getData(TEMPERATURE_FIELD), rx16.getData(HUMIDITY_FIELD), rx16.getData(SLEEPCYCLE_FIELD), rx16.getData(ASYNCHRONUS_FIELD), uid );  // Renueva los datos de la fio en concreto
              digitalWrite(8, LOW);
        }  // switch
      }  // getApiId
    }  // available
  }  // readPacket
}  // readRequest

25  Using Arduino / Networking, Protocols, and Devices / Re: xbee + ethernet shield + arduino uno r2 on: October 25, 2012, 09:38:40 am
Hi thank you for your fast answer.

The XBee Shield is It is almost the same mine is ArduinoXBee v1.1

The Ethernet Shield is "shield model Ethernet R3"

Over a Arduino UNO R2. I know that the Ethernet Shield R3 have more pins but my Ethernet Shield that fits perfectly on ARduino UNO R2.
But this shield don´t read the microSD.

I copy my code ... It could be a mess sorry. Thank you.

26  Using Arduino / Networking, Protocols, and Devices / xbee + ethernet shield + arduino uno r2 on: October 25, 2012, 06:45:45 am
Hi everyone,

I hope I don´t be wrong posting here. Well, I have a little doubt... I attached a xbee shield an ethernet shield over an arduino UNO. So when I try to just listenig through the XBee, when an http message comes from the net the arduino UNO resets.

I don't know if they are sharing ports, D0 and D1? Is there a conflict? As the serial use it, I added the newsoftserial library.

Maybe you know what are the tips that I should follow  when you use these two shield at the same time.

Thank you for your time and sorry for my English.
27  International / Proyectos / Ethernet + XBee + Arduino UNO auto reinicio de la placa on: October 25, 2012, 02:28:26 am
Buenos días,

no sé si estoy escribiendo en el lugar correcto. Cuento un poco un mi caso a ver si me podéis echar un cable.
Veréis tengo apilado sobre una arduino UNO, un escudo ethernet más otro XBee. Además tengo cargada una página web en html usando jquery mu sencilla, que lo que hace es hacer una petición cada x tiempo a la placa  tipo GET de manera cuando llega a la placa lee de la tarjeta microSD y responde. Además tengo la posibilidad de hacer un POST, un formulario. De manera que envío datos desde la página web, dos números nada más. A veces llega a la placa, responde y va bien. Pero otras no sé si llegará o no pero la placa se reinicia. Y a partir de llegar ese POST, cuando llega un GET se resetea. Y no sé porqué.

No sé si me podéis dar una pista de por qué se puede resetear la placa. Si queréis pongo código.

He comprobado que utilizar el puerto serie, cualquier instrucción Serial.print como que se vuelve loca la placa.

Pero a parte de eso, ya no sé si es que hay un buffer que se llena, o que dejo alguna instrucción colgando y no sabe que hacer ... no sé ya que puede ser.

gracias de antemano.
28  Community / Bar Sport / Re: Another Plataforms as Arduino on: June 14, 2012, 10:52:42 am
Hi Fkeel,

Thank you for the intel. I appreciated it. Well I´m going to add this two marks you´ve told me.

And I want to ask a question, on my project I´m using Xbee modules from Digi, mainly because we have them on the laboratory... but as I know threre are some others modules perfectly suitable. But, I don´t know why could be a reason to use them and why don´t use another ones... I was reading the specifications and they are practically the same ... so maybe you could give me a hand.

Sorry for my English.

29  Community / Bar Sport / Re: Another Plataforms as Arduino on: June 13, 2012, 11:32:42 am
Hi everyone,

thank you for your answers. I want to share some information, maybe it could be useful to someone.

Besides, picaxe, pinguino and raspberry, I found different sort of motes as iSense, Waspmote, iMote, MicaZ, Telos, ... those are platforms composed of a microcontroller, a A/D conversor, some sensons, ... some of them are programmable through C...

By now, my new question is : Do you know another radio devices as Xbee from digi? I made a reseach, wikipedia is very useful.  I selected :

• RP-M100, FirmTech.
•ProBee-ZE10 & ProBee-ZE20S, Sena Technologies.
•ProFLEX01 & SiFLEX02 de LS Research

I listed them because maybe there are other more importants than these ones that you could know.

Thank you all

30  Community / Bar Sport / Re: Another Plataforms as Arduino on: May 25, 2012, 05:36:27 am

I add two more alternatives:

raspberry is cheaper than arduino
picaxe sell microcontrollers

I suppose that before arduino existed you should buy a microcontroller, and programme it. Arduino allows you change the bootloader, change the function of the chip. But others does not, you have to work with it and you can't change it.
Please, if I am wrong I would appreciate if you tell to me.

thanks everyone,

Pages: 1 [2] 3 4