[EtherCard.h] Arduino as a client - Reading GET/POST data

Hello Guys :slight_smile:

Do you know how can I efficiently read the data from other web server when using EtherCard.h library?

I need to have information from other web server (raspberry pi) passed via network to arduino. Raspberry will tell arduino which pin should be enabled.

Sending GET data is simple when using EtherCard.h, I’m just using:

ether.browseUrl(PSTR("/test.php"), “?var1=3&var2=10”, website, my_callback);

For getting the variables from other web server also I can use:
ether.browseUrl(PSTR("/getVars.php"), “”, website, my_callback);

Based on above command I got raw HTML page in response, but processing all page efficiently and extracting values from i.e below code could be difficult:



TEST

PIN_NUMBER=2
isEnabled=false

I’ve found some solutions with help of other libraries and other shields, but I need to use EtherCard.h, do you have a proposition on that?

Thank you in advance!

Sending GET data is simple when using EtherCard.h, I'm just using:

ether.browseUrl(PSTR("/test.php"), "?var1=3&var2=10", website, my_callback);

The callback function gets called, when the server responds. What does YOUR (stupidly named) callback function do?

Hello PaulS,

Indeed the name of the function is not good enough, but it’s still in testing phase. Just used the template from imported example, that’s why it is stupid… but let’s leave the naming convention on a side.

Here is the code of the callback function:

void my_callback (byte status, word off, word len) {

  • Serial.println(">>>");*
  • Ethernet::buffer[off+500] = 0;*
    _ Serial.print((const char*) Ethernet::buffer + off);_
    }

Basically it’s reading response of the server and downloading the raw HTML page, which could be:


TEST

PIN_NUMBER=2
isEnabled=false

The issue is how to take out this variables:
PIN_NUMBER and isEnabled

and assign it to String/char table/integer

The issue is how to take out this variables

The data being printed is in a char array. Use strstr() to find the location of “”. Increment the pointer by the length of “”, so you point to the first character of the body.

Use strstr() to locate the = sign after PIN_NUMBER. Use strstr() to locate the carriage return after the value. Replace the carriage return with a NULL, and use atoi() to extract the numeric value from the = sign on.

Locate the next = sign, and the carriage return that follows it. Replace the carriage return with a NULL, and strncpy() the data from the position after the = sign to the NULL to another char array.