GregEigsti wrote:...I refactored the WebClient code - removing the "twitter" goop and making it more web page generic. ...
Thank you Greg so much for these two files, but I am not sure how I would modify them to work with my server.
One problem I have is that my server does not have a static IP address. However, it changes so rarely, that I don't mind hard-coding it's current IP address for now. I just hope someday we get DNS. Also, it's not the only domain on that IP address (I think that is called "virtual hosting"). Will your above code still work?
Anyway, I have put a temporary test server up at http://deepwaveenergy.com/arduino/adder.cgi?5,800,10
It's an adder, it just adds numbers together. The C++ source is:
- Code: Select all
/////////////////////////////////////
//
// This is a cgi program that runs on a server waiting to add up numbers.
// To activate it, hit it's URL and put numbers (separated by commas) after a "?" like this:
//
// http://deepwaveenergy.com/arduino/adder.cgi?5,800,10
//
// It should return:
// +--------------------------+
// | Content-type: text/html |
// | |
// | <html> |
// | <body> |
// | sum = 815<br> |
// | </body> |
// | </html> |
// +--------------------------+
//
#include <iostream>
#include <fstream>
#include <string>
#include <cstdio>
using namespace std;
int main( int argc, char* argv[], char* envp[] )
{
cout << "Content-type: text/html" << endl << endl;
cout << "<html>" << endl;
cout << "<body>" << endl;
// Get the stuff past the "?" in the URL.
char* str = getenv( "QUERY_STRING" );
int val = 0;
int sum = 0;
while( str != NULL && *str != '\0' )
{
if( *str >= '0' && *str <= '9' )
val = (val * 10) + ((int)(*str) - (int)'0');
else
{
sum += val;
val = 0;
}
str++;
}
sum += val;
cout << "sum = " << sum << "<br>" << endl;
cout << "</body>" << endl;
cout << "</html>" << endl;
return 0;
}
I figure my "const prog_char webpage[] PROGMEM should be:
- Code: Select all
GET /arduino/adder.cgi?5,800,10 uIP/1.0
Host: deepwaveenergy.com
As you suggested, I tried: telnet 66.147.240.154 80
and successfully got back
- Code: Select all
HTTP/1.1 200 OK
Date: Thu, 14 Jan 2010 01:58:42 GMT
Server: Apache/2.2.14 (Unix) mod_ssl/2.2.14 OpenSSL/0.9.8l DAV/2 mod_auth_passthrough/2.1 FrontPage/5.0.2.2635
Vary: Accept-Encoding
Connection: close
Content-Type: text/html
<html>
<body>
sum = 815<br>
</body>
</html>
I'm using a Boarduino (328), so I should have enough memory to do this, right? Other than changing the usual stuff (local_ip, gateway_ip, subnet, ssid, etc.) and PROGMEM, what else do I need to change? If I can get my Arduino to add 2 numbers together using this server, then I will be able to do what I really want to do.
Greg, you did such a great job helping Kevin; if you don't mind, can you help me too?