xbee send data to pc doesn't work

hello all, I would like to send from my arduino throught my xbee wifi a code over the network. when I use the serial.println the string is pass over the network but my recv or recvfrom doesn't catch the string broadcast over the network. A second xbee wifi plug onto a pc does.

What do I do wrong ?

ounet.

What do I do wrong ?

No code. No links to the hardware. No serial output. No proof. Therefore, you must not really have a problem, or want an answer.

sorry …
arduino code with xbee wifi plug on Rx TX:

#include <stdio.h>
#include <string.h>

#define ledPin 13

int count = 0;
int val = 0;
char indata[254];

void setup()
{
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}

void loop()
{
while (Serial.available() > 0)
{
char incomingByte = Serial.read ();
//Serial.println(Serial.read());
if(incomingByte != ‘\0’)
{
//Serial.println(“Boucle reception”);
indata[count] = incomingByte;
count ++;
indata[count] = ‘\0’;
}
}

/* fin boucle while */

if(atoi(indata)==1)
{
digitalWrite(ledPin, HIGH);
Serial.println(indata);
}
if (atoi(indata)==2)
{
digitalWrite(ledPin, LOW);
Serial.println(indata);
}
if (atoi(indata)==3)
{

//delay(50);
Serial.println(“blablabla”);
// Serial.flush();
}

count=0;
indata[count] = ‘\0’;
}

Xcode prog :

msg1 =recvfrom(s,buf,sizeof(buf),0,(struct sockaddr *)&ounet_in, sizeof(ounet_in));

the recfrom doesn’t receive anything but when I use wireshark the broadcast is ok.

So if you can help me.

ounet

You need to read this thread (at least the first posts explaining things like posting your code in code tags) at the top of this part of the forum: Thread title: ** Read this before posting a programming question ...**

This code will probably NOT get a whole number before the outer while is done.

  while (Serial.available() > 0)
  {
    char incomingByte = Serial.read ();
    //Serial.println(Serial.read());
    if(incomingByte != '\0')       
    {
      //Serial.println("Boucle reception");
      indata[count] = incomingByte;
      count ++;
      indata[count] = '\0';    //  if(incomingByte != '\0')  then you store '\0' anyway?
    }
  }

The Arduino is -so much faster than Serial data- that a character will not be available before it gets to that first while().

You might try something like this. It is untested and may need more work.

  byte flag = 1;
  while ( flag )  // 0 is false, non 0 is true
  {
    if (Serial.available())  // 0 is false, non 0 is true
    {
      char incomingByte = Serial.read ();
      //Serial.println(Serial.read());
      if(incomingByte != '\0')       
      {
        //Serial.println("Boucle reception");
        indata[count] = incomingByte;
        count ++;
        indata[count] = incomingByte; 
        if ( count == whatever variable has the length of the char array )
        {
          flag = 0;  
        }
      }
      else
      {
        indata[ count ] = 0; // same thing as '\0', char -is- a signed 8 bit number
        flag = 0;
      }
    }
  }

ok maybe i do a wrong explanation. when I send from my xcode programe to the xbee-arduino, that works like a charme. When I use the Serial.println over a network that also work like a charme because I can see with wireshark and a second xbee wifi that the Serial.print works.

I thinks that the clue is to program the xbee as we programe a arduino ethershield. As I can open a socket and send to my computer. But I do not know if it possible with xbee or I do not know how to do it.

ounet

char incomingByte = Serial.read ();
    //Serial.println(Serial.read());
    if(incomingByte != '\0')

The value read from the serial port should never be NULL. Silly to test for it.

arduino code with xbee wifi plug on Rx TX:

Why? Why not use some other pins, if possible, and leave RX and TX for debugging?

PaulS: char incomingByte = Serial.read ();     //Serial.println(Serial.read());     if(incomingByte != '\0')

The value read from the serial port should never be NULL. Silly to test for it.

arduino code with xbee wifi plug on Rx TX:

Why? Why not use some other pins, if possible, and leave RX and TX for debugging?

I should have caught both of those.

Why? Why not use some other pins, if possible, and leave RX and TX for debugging?

Because I do not know how to do that.

Software Serial Library on UNO, MEGA has 3 hardware serial ports.

http://arduino.cc/en/Reference/SoftwareSerial

doesn’t catch the string broadcast over the network. A second xbee wifi plug onto a pc does.

What do I do wrong ?

XBees do not talk to WiFi they talk to other Xbees

What are you doing wrong. your not reading the documentation!!!

Mark

What are you doing wrong. your not reading the documentation!!!!!

ok maybe but if xbee only talk each ohter, how can you explan that I was able to send from my imac to xbee wifi without having 2 xbees.

anyway will find a solution. I sure...

XBee uses standard IEEE 802.15.4 networking protocol. It is not inconceivable that other wireless devices do as well. Can they communicate with bluetooth?

what do I wrong.....forget to use in my programe the bind option. if (bind(s, (struct sockaddr*)&ounet_in, sizeof ounet_in) == -1) { perror("bind"); exit(1); }

and the recvfrom is : if (recvfrom(s,buf,sizeof(buf),0,(struct sockaddr *)&ounet_in, &addrLen)==-1) { printf("ErroR reception"); } else printf("msg1 : %s\n",buf); return buf;