otrcomm:
The HttpClient works fine, it appears that the Ethernet client does not function properly on the YunShield.
Correct. Nothing in the library for the Ethernet Shield will work on the Yun or the Yun Shield. There are a few differences between a Yun and a YunShield, but they are very close to each other. Just like the Yun, networking with a YunShield is also nothing like the Ethernet Shield. The whole networking architecture is completely different. Forget that you ever heard of the Ethernet Shield or anything in Ethernet.h – it will only serve to confuse you with the Yun or YunShield.
Looking at your code… (BTW, please use the CODE tags when posting code: click on the button that looks like a scroll with blue angle brackets, then paste your code between those tags.)
You didn’t post the beginning of your sketch, so we don’t see the setup. But don’t #include Ethernet.h and take out just about everything that has to do with MAC addresses and setting up the Ethernet. All you need is to #include Bridge.h and call Bridge.begin().
Your port 80 code:
if (client.connect(server, 80)) {
#ifdef DEBUG
Serial.println(F("Client request 10.11.20.123:port 80: "));
#endif
/**********************************************************************************************/
// // Make a HTTP request:
// // Will need different scripts to read different sensors in various locations, so
// // could have various "add_data.php" scripts in different directories off /var/www/
client.print( "GET http://10.11.20.123/septic_houses/add_septic_house_D_data.php?");
#ifdef DEBUG
Serial.print( "GET http://10.11.20.123/septic_houses/add_septic_house_D_data.php?");
#endif
client.print("datastring"); // print: datastring=
client.print("=");
client.print(datastring);
#ifdef DEBUG
Serial.print("datastring"); // print: datastring=
Serial.print("=");
Serial.println(datastring);
#endif
This will be replaced with a call to HttpClient.get(). Rather than print() each segment of the URL to the client, you will need to build a string, and then pass that full string to HttpClient.get().
// Not exactly sure what this code does yet, but it is necessary :)
client.println( " HTTP/1.1");
client.println( "Host: 10.11.20.123" );
client.print(" Host: ");
client.println(server);
client.println( "Connection: close" );
client.println();
client.println();
client.stop();
} // End if (client.connect(server, 80))
You won’t need this section. This is sending the HTTP headers to the server, and HttpClient takes care of that for you.
Now for the port 8080 part. You don’t show the portion where you are opening the connection, but I assume that you are re-using client for this. This part is a little more complicated because of the different port number, and because you’re doing a POST, not a get. But I think it can be done.
HttpClient is really just a wrapper for curl. To do a POST with curl, the easiest way is to use the --data option. So the parameter would be something like http://myserver.com:8080/my/page/url --data <datastring>
You will basically have to pre-pend your server name, port, URL, and " --data " to the beginning of datastring, and then send the whole string in the HttpClient.get() call. Or at least that’s the theory: I’ve not tried it, and I’m not an expert in using curl. If you can come up with a string that works for curl, you should be able to get it to work with HttpClient. If all else fails, you can always create a Process object and make the curl call directly.
Now, with all of that said and done… is this all that the sketch does, get data from one server and send it to another? If so, it might be easier and more efficient to do everything on the Linux side. You will have a lot more power and flexibility there. You really only NEED to use a sketch to access the shield header pins, just about everything else (especially networking) may be easier or at least more efficient doing on the Linux processor.