|
2476
|
Using Arduino / Networking, Protocols, and Devices / Re: Web server with two input boxes
|
on: March 04, 2012, 05:49:16 am
|
Some day I will try to get my stuff on the playground. But until then, here is a section of code I use. The variables are 'r' and 't'. Change the network settings to yours. #include <SPI.h> #include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; IPAddress ip( 192,168,0,2 ); IPAddress gateway( 192,168,0,1 ); IPAddress subnet( 255,255,255,0 ); IPAddress dns( 192,168,0,1 );
EthernetServer server(80);
void setup() { Serial.begin(9600); pinMode(4,OUTPUT); digitalWrite(4,HIGH); Ethernet.begin(mac, ip, dns, gateway, subnet); delay(2000); server.begin(); Serial.println("Ready"); }
void loop() { EthernetClient client = server.available(); if(client) { boolean currentLineIsBlank = true; boolean currentLineIsGet = true; int tCount = 0; char tBuf[64]; int r,t; char *pch; Serial.print("Client request: "); while (client.connected()) { while(client.available()) { char c = client.read();
if(currentLineIsGet && tCount < 63) { tBuf[tCount] = c; tCount++; tBuf[tCount] = 0; }
if (c == '\n' && currentLineIsBlank) { // send a standard http response while(client.available()) client.read(); Serial.println(tBuf); pch = strtok(tBuf,"?");
while(pch != NULL) { if(strncmp(pch,"t=",2) == 0) { t = atoi(pch+2); Serial.print("t="); Serial.println(t,DEC); }
if(strncmp(pch,"r=",2) == 0) { r = atoi(pch+2); Serial.print("r="); Serial.println(r,DEC); }
pch = strtok(NULL,"& "); } Serial.println("Sending response"); client.write("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n<html><body><H1>TEST</H1>");
client.write("<form method=GET>T: <input type=text name=t><br>"); client.write("R: <input type=text name=r><br><input type=submit></form>"); client.write("</body></html>\r\n\r\n"); client.stop(); } else if (c == '\n') { currentLineIsBlank = true; currentLineIsGet = false; } else if (c != '\r') { currentLineIsBlank = false; } } } Serial.println("done"); } } I had to edit the network settings, so my apology in advance for typos.
|
|
|
|
|
2477
|
Using Arduino / Installation & Troubleshooting / Re: Arduino Mega 2560 bug with uploading
|
on: March 04, 2012, 05:31:06 am
|
|
Some versions of the bootloader apparently do not like three exclamation points (!!!). It causes them to enter some type of debug mode or something. Unless you feel like the statement is so important (like the sky is falling), try using two instead. Or if the sky is falling, put some other character between them.
|
|
|
|
|
2478
|
Using Arduino / Networking, Protocols, and Devices / Re: Arduino Ethernet Shield GET Help
|
on: March 03, 2012, 01:32:21 pm
|
That code will work in Arduino IDE v1.0. I recommend upgrading to IDE v1.0. I use Ubuntu v11.10 and I can run both versions. I hear you can do that with Windows also. If the php code is hidden, then I guess I am seeing exactly what the page displays. Nothing but the webhost-inserted javascript. Your "other directory" file displayed ok.  Add: Got busy with the "work" thing.  Just some advice. You really should turn off your directory browsing feature on your site. I can't navigate outside your "/PUBLIC_HTML/" folder, but I can navigate around in that directory and all subdirectories there. That might prove to be a security hazard someday.
|
|
|
|
|
2479
|
Using Arduino / Networking, Protocols, and Devices / Re: Arduino Ethernet Shield GET Help
|
on: March 03, 2012, 11:35:17 am
|
Here is what I used. I had to edit the network settings, so if there are typos in those settings, that is why. This is for IDE v1.0 only. #include <SPI.h> #include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; IPAddress ip(192,168,1,117); IPAddress gateway(192,168,1,1); IPAddress subnet(255,255,255,0);
IPAddress server(31,170,163,17); // Chris
EthernetClient client;
void setup() { Serial.begin(9600); Ethernet.begin(mac,ip,gateway,gateway,subnet); delay(2000); Serial.println("connecting...");
if (client.connect(server, 80)) { Serial.println("connected"); // Make a HTTP request:
client.println("GET /prowl/example.php HTTP/1.0"); client.println("Host: www.chriscosma.co.cc"); client.println(); } else { // kf you didn't get a connection to the server: Serial.println("connection failed"); } }
void loop() { while(client.connected()) { while(client.available()) { char c = client.read(); Serial.print(c); } } Serial.println("disconnecting."); client.stop();
// do nothing forevermore: for(;;) ; }
edit: I just checked that page with my web browser, and the analytics javascript is all that is there.
|
|
|
|
|
2482
|
Using Arduino / Networking, Protocols, and Devices / Re: Uploading file from SD card to remote server?
|
on: March 03, 2012, 08:15:27 am
|
|
I had not even considered the "no request send" on the data connection. Maybe it is best I went with the client end code instead.
The router routing challenge is the reason I use client passive mode. Client active mode requires the ftp (edit: client) to contact the (edit: server) on a port specified from a port specified by the client (through my firewall/masquerade). edit: You would have to know what port the Arduino is being masqueraded as to send to the server for that. Very complex to determine.
I can route my stuff no problem, but explaining that to someone who is not familiar with routing can be challenging.
If you want to access the Arduino from the internet in server active mode, you only need port 21 routed to the localnet ip of the Arduino. Port 20 will contact the client in client mode on the port specified in the cmd channels PORT send. In server passive mode, you need to route port 21 and the data channel port through the router to the Arduino.
Then there is the user/password thing. If you are going to have an ftp server that allows writing, I highly suggest you use at least some form of hack prevention. If you leave it open on the internet, you will amazed at how quickly those files will either disappear or get filled with junk.
edit: My typing got ahead of my brain in ftp active mode explanation. I'll blame it on "logic reversal".
|
|
|
|
|
2484
|
Using Arduino / Networking, Protocols, and Devices / Re: Uploading file from SD card to remote server?
|
on: March 03, 2012, 07:21:29 am
|
|
@michael635: I took a look at your code. Looks ok, but I have not run it yet.
Why do you need to modify the Ethernet library? I did not look at the code that closely, but is that how you listen on two separate ports? That is the part I couldn't figure out with my ftp server code, besides the router masquerade (can't reach it from the internet without some internal routing).
|
|
|
|
|
2485
|
Using Arduino / Networking, Protocols, and Devices / Re: Arduino Ethernet Shield GET Help
|
on: March 03, 2012, 06:35:11 am
|
HTTP 1.1 details in RFC2616. Its a good idea to familiarise yourself a bit with the standard.
That is a good idea, but I think that doc is a bit too technical for the OP. You could have been more specific. Maybe a correction to the OP's code or an example of your own? I'm waiting on the edge of my seat! 
|
|
|
|
|
2486
|
Using Arduino / Networking, Protocols, and Devices / Re: Arduino Ethernet Shield GET Help
|
on: March 03, 2012, 05:54:51 am
|
You web hosting company uses virtual hosting. The response you are getting is from your web host's domain, not yours. If you want to access your domain files, you need to add a "Host:" to the GET header. Replace " www.mydomain.com" with your domain name. // Make a HTTP request: client.println("GET /prowl/example.php HTTP/1.0"); client.println("Host: www.mydomain.com"); client.println(); edit: I also added the HTTP/1.0 to the GET.
|
|
|
|
|
2487
|
Using Arduino / Installation & Troubleshooting / Re: SD issue on EthernetShield + MEGA2560
|
on: March 02, 2012, 11:22:48 am
|
Try disabling the w5100 SPI interface. That will sometimes interfere with the SD reader functions. I would stick to the library code for initializing the SD reader also. pinMode(10,OUTPUT); digitalWrite(10,HIGH); if(SD.begin(4) == 0) { Serial.println("SD init fail"); }; edit: Added error checking on the SD.begin() call.
|
|
|
|
|
2489
|
Using Arduino / Networking, Protocols, and Devices / Re: W5200 Module
|
on: March 01, 2012, 11:55:48 am
|
The W5100 does not use the interrupt pin with the Arduino. The Arduino software polls the device instead. I presume you would want to use the same interface protocol on the W5200. But then, the person who writes the initial code gets to decide stuff like that.  Are there w5200.h and w5200.cpp files available from Wiznet?
|
|
|
|
|
2490
|
Using Arduino / Networking, Protocols, and Devices / Re: W5200 Module
|
on: March 01, 2012, 11:11:14 am
|
|
The Wiznet 5200 is 5v tolerant on the input pins.
You should be able to select a digital pin, connect it to pin 45 on the W5200, and set the pin to OUTPUT. Set the pin LOW to enable the W5200. High powers down.
I have not used that IC, but I presume the IC will need to be reinitialized after a power-up.
Eight sockets! WOW!
|
|
|
|
|