Two ether.browseUrl(), only second in order works.

Hi there, Im working on etherCard module programming and got a problem... Have two functions:

static void relay_status(byte status, word off, word len) {
   char * aaa;
   char updown;
   Ethernet::buffer[off+100] = 0;
   aaa = strtok((char*) Ethernet::buffer + off, "#");
   updown = printf(aaa);
   digitalWrite(3, updown);
} 

static void my_callback(byte status, word off, word len) {
   char * pch;
   Ethernet::buffer[off+300] = 0;
   pch = strtok((char*) Ethernet::buffer + off, "#");
   pch = strtok (NULL, "#");
   Serial.write(0x0C);
  
   while (pch != NULL) {
       Serial.write(0x01);
       Serial.write(pch);
       Serial.write(0x0D);
       pch = strtok (NULL, "#");
   } 
}

and call em lie this:

if (millis() > timer) {
   timer = millis() + 120000; // kas dvi minutes

    sprintf(buffer_relay, "Relay=%d", relay);   
    ether.browseUrl(PSTR("/relay.php?"), buffer_relay, website, [b]relay_status[/b]);

    sprintf(buffer_data, "ID=1&Key=123456&Status=OK&V1=%d&V2=%d&I1=%d&Vall=%d", V1, V2, I1, Vall);
    ether.browseUrl(PSTR("/push_data.php?"), buffer_data, website, [b]my_callback[/b]);

  }

it doesnt matter witch function I call first, but its only last one being performed. i've never came accross with this kind of problem. I bet, its something with Ethernet::buffer... Any advices?

Thanks!

You NULL terminate the buffer at two different positions in the two functions. Is that intentional?

Printing what is in the buffer after accessing the two different URLs would be useful. Printing a message at the top of each function, to assure that it is indeed called would be useful.

where do you call the functions giving them parameters?

Just a guess: they are callbacks? You don't wait for the callbacks to run, so the first one doesn't get called before you overwrite it with the second. After a request you must wait for the result - typically you'd poll a variable that the callback sets (and check for timeout too).

MarkT, I beleve You are right… How can I make it work? Just delaying doesnt seem to work…
Sorry, I’m not good in programming…

How can I make it work?

At the top of the code, define a flag:

volatile bool working;

Before the calls to ether.browseURL, set the flag:

working = true;

At the end of the callback, clear the flag:

working = false;

After each of the two calls to ether.browseURL(), put a while loop:

while(working)
{
   // Do nothing
}

Brilliant!!! program gets stuck in first while loop, regardless which one is first of these two..

Any ideas?

ok, it seems that it just dont call this ether.browseUrl(PSTR("/relay.php?"), buffer, website, relay_callback);

if I put something in any place in relay_callback, it is not performed.

Anyone had similar problem with EtherCard?

Ignacas:
ok, it seems that it just dont call this
ether.browseUrl(PSTR("/relay.php?"), buffer, website, relay_callback);

if I put something in any place in relay_callback, it is not performed.

You need to wait for the callback to complete OR FOR A TIMEOUT. If it times out then clearly the request failed in some manner.
Something like

request_time = millis () ;
while (working && (millis () - request_time < TIMEOUT))
{
   // Do nothing
}
if (working) // we know a timeout happened
{
    // handle timeout
}

You can then start to see what’s happened server-side to see if the request got through, whether a response was sent. Then start to
narrow down the issue (there are many possible failure modes for an HTTP request alas.

Got some ideas here http://forum.jeelabs.net/node/1477#comment-9615 but still no luck.

I think its bug in library.

Up.