Pages: [1]   Go Down
Author Topic: Ethernet Shield - output buffer overrided  (Read 685 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello

I have a gateway which interface a server with a zigbee network. I am an experiemented C- python programmer but sometimes there are pieces of code which blow your head, well this time I have a global variable which contains an array with the processed set of bytes which will be delivered to the server.

I print the variable just before to be sent and just after to be sent and are both the same, but in the other side (twisted python server) and sniffing with wireshark (also with tcpflow) show a different set of bytes, this occurs not always, but sometimes and is very annoying and I've been looking in my code for another piece of codes interfering and nothing at simple sight, I've had to put some log even in client.cpp and w5100.cpp to check the variable just before and after to be sent and msteriously are the same.


In my sketch I have no interruptions which can access to this array.

Here are some codes.
main.pde
Code:
uint8_t PacketToSendToServer[PACKET_TO_SEND_TO_SERVER_MAX]={
  0};
void setup() {
   //this is not important
}
void loop() {
  // other functions and declarations

  Serial1.print("\t(TCP)ToSend-client-bef:");printuint8ArrayasDEC(PacketToSendToServer,len_PacketToSendToServer);
  client.write(PacketToSendToServer,len_PacketToSendToServer); // sending PacketToSendToServer, waiting for response an parse
  Serial1.print("\t(TCP)ToSend-client-aft:");printuint8ArrayasDEC(PacketToSendToServer,len_PacketToSendToServer);
}

void printuint8ArrayasDEC(byte* cadena,int len) {
  for (int j=0;j<len-1;j++) {
    Serial1.print(cadena[j],DEC);Serial1.print(", ");
  }
  Serial1.print(cadena[len-1],DEC);
  Serial1.println("");
}

the console arduino output:
Code:
(TCP)ToSend-client-bef:15, 16, 0, 0, 82, 80, 0, 0, 20
(TCP)ToSend-client-aft:15, 16, 0, 0, 82, 80, 0, 0, 20

// The server console (a python twisted application)
Code:
2011-03-27 20:29:06-0400 [arduinoRPC,17,200.104.82.179] 32,76,111,99,97,108,0,0,106

The bytes above printed in ascci format are quite similar (in some parts) to some packets previously sent (2 or three pacets before) sent to server from arduino using the same functions. Well my code are quite structured almost 1500 lines of code and is not convenient for you to check it (bored). My question is which is the conditions that could be causing this variable overriding.

The clever guys, any help is well received.
JR





Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 551
Posts: 46224
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Both the Serial class and the Client class are derived from the Print class. The Print class provides the print() and write() methods.

Quote
I print the variable just before to be sent and just after to be sent and are both the same, but in the other side (twisted python server) and sniffing with wireshark (also with tcpflow) show a different set of bytes
In one case, you are using the print() method. In the other case, you are using the write() method. Why? Why are you not using print() or write() in both cases? Specifically, why are you using the write() method at all? The client to server communication is supposed to be entirely ASCII based (i.e. using the print() method).
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think I explanied myself in a bad way. When I tal about server I mean a linux box with a server based on twisted-python. To clarify, when I print from arduino to the server (linux) I use
Code:
client.write(array_to_send, len_array_to_send)

any suggestion?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 551
Posts: 46224
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
To clarify, when I print from arduino to the server (linux) I use
Quote
client.write(array_to_send, len_array_to_send)
Quote
any suggestion?
I made one, already.
The client to server communication is supposed to be entirely ASCII based (i.e. using the print() method).
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

client::write can be used to send pure byte raw data to the server, client::print will print ascci until a byte='\0' is found, check the function definitions in client.cpp

Logged

Georgina Ontario
Offline Offline
Sr. Member
****
Karma: 5
Posts: 437
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you are saying that the Ethernet board does not always send or receive the correct bytes I agree.

Sometimes the data appears to be completely scrambled -- other times it is "similar" to what was sent/received.

Even the demos that come with the compiler exhibit the problems -- for example the simple one that serves some analog port data as a simple web page with the ADC Post values.

I do not know if it is the hardware or the software.


Logged

Just another Hacker

Pages: [1]   Go Up
Jump to: