Show Posts
|
|
Pages: [1] 2 3 4
|
|
1
|
Using Arduino / Networking, Protocols, and Devices / Re: Simple Web Server and Chrome
|
on: May 14, 2013, 08:11:06 pm
|
You guys have been very helpful to me with your replies. What I did to handle the GET /favicon.ico was just to check for the character 'f' after the first '/', and when I found it, just DEcrement my page counter by one, so when it got incremented later, it ended up unchanged. Just a few extra lines of code. Page counter works well now with all five major browsers (IE, FF, Chrome, Safari, Opera). Thanks again ! BobW I should have seen that. It was the "GET /favicon.ico HTTP/1.1" that I was missing. Thanks. I'll be good to go now ! BobW It is the web browser request for favicon.ico that adds to the count. Chrome requests it every reload. Firefox and IE don't.
Check for the request for "GET /favicon.ico HTTP/1.1" and ignore that count.
|
|
|
|
|
2
|
Using Arduino / Networking, Protocols, and Devices / Re: Simple Web Server and Chrome
|
on: May 14, 2013, 07:12:55 pm
|
I should have seen that. It was the "GET /favicon.ico HTTP/1.1" that I was missing. Thanks. I'll be good to go now ! BobW It is the web browser request for favicon.ico that adds to the count. Chrome requests it every reload. Firefox and IE don't.
Check for the request for "GET /favicon.ico HTTP/1.1" and ignore that count.
|
|
|
|
|
3
|
Using Arduino / Networking, Protocols, and Devices / Simple Web Server and Chrome
|
on: May 13, 2013, 08:11:01 pm
|
I modified the "Simple Web Server" example to display a page counter. See below. Question: Why does the counter advance by 2 when I reload the page with Chrome, but only by one with Internet Explorer 8. Firefox advance by two on first load, one thereafter. I think. Do you see a workaround to make a functional page counter that will work with all browsers ?? /* Simple Web Server */
#include <SPI.h> #include <Ethernet.h>
// Enter a MAC address and IP address for your controller below. // The IP address will be dependent on your local network: byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; IPAddress ip(192,168,1,78); EthernetServer server(8248);
int iPageCounter = 1;
void setup() { // Open serial communications and wait for port to open: Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only }
// start the Ethernet connection and the server: Ethernet.begin(mac, ip); server.begin(); Serial.print("server is at "); Serial.println(Ethernet.localIP()); }
void loop() { // listen for incoming clients EthernetClient client = server.available(); if (client) { Serial.println("new client"); // an http request ends with a blank line boolean currentLineIsBlank = true; while (client.connected()) { if (client.available()) { char c = client.read(); Serial.write(c); // if you've gotten to the end of the line (received a newline // character) and the line is blank, the http request has ended, // so you can send a reply if (c == '\n' && currentLineIsBlank) { // send a standard http response header client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println("Connnection: close"); client.println(); client.println("<!DOCTYPE HTML>"); client.println("<html>"); client.print("<h1>Page Count: "); client.println(iPageCounter++); // THIS IS THE PAGE COUNTER LINE client.print("</h2>"); client.println("</html>"); break; } if (c == '\n') { // you're starting a new line currentLineIsBlank = true; } else if (c != '\r') { // you've gotten a character on the current line currentLineIsBlank = false; } } } // give the web browser time to receive the data delay(1); // close the connection: client.stop(); Serial.println("client disconnected"); } }
|
|
|
|
|
4
|
Using Arduino / Programming Questions / Re: P macro
|
on: March 31, 2013, 10:07:42 am
|
I just inferred that the P was something special because the IDE makes the "P" in the define line of the sketch RED in color, as if it were a keyword. I got suckered by this. This does not happen if I change name of macro to "Q", or "R". Why would this be ? Bob PS: What I am trying to accomplish is to send a big block of HTML to my Arduino Web Server, without using many individual client.print("html code") lines. P is a macro, defined at the top of your sketch #define P(name) static const prog_uchar name[] PROGMEM
P gets replaced by whatever it is defined as, so P(signMessage) = "This is some text . . . ";
gets changed to static const prog_uchar signMessage[] PROGMEM = "This is some text . . . ";
|
|
|
|
|
5
|
Using Arduino / Programming Questions / P macro
|
on: March 30, 2013, 01:18:00 pm
|
The code below produces this for output: This is some text . . . This is some more text.The "P Macro" seems to be an integral part of the Arduino "language". Note that no libraries are included in this sketch. I'm not exacly sure why this sketch works (i.e. the P part) Where can I learn more about "P" ? All I know came from studying the Webduino library. A basic web seach has not produced any useful results for me. As usual, sorry if this question is too basic. Thanks, Bob W #define P(name) static const prog_uchar name[] PROGMEM
P(signMessage) = "This is some text . . . ";
void setup() { Serial.begin(9600); printP(signMessage); printCRLF(); P(signMessage) = "This is some more text."; printP(signMessage); }
void loop() { }
void printP(const prog_uchar *str) { // copy data out of program memory into local storage, write out in // chunks of 32 bytes to avoid extra short TCP/IP packets uint8_t buffer[32]; size_t bufferEnd = 0;
while (buffer[bufferEnd++] = pgm_read_byte(str++)) { if (bufferEnd == 32) { Serial.write(buffer, 32); bufferEnd = 0; } }
// write out everything left but trailing NUL if (bufferEnd > 1) Serial.write(buffer, bufferEnd - 1); }
void printCRLF() { Serial.write((const uint8_t *)"\r\n", 2); }
|
|
|
|
|
7
|
Using Arduino / Programming Questions / (char)n vs char(n)
|
on: March 10, 2013, 10:01:12 am
|
What is the difference (if any) between (char)n and char(n) ? The test code below produces: 88 X 88 X 88 No apparant difference between lines 3 and 5. Thanks. Bob W. int n = 88; Serial.println( n ); Serial.println( char(n) ); Serial.println( n ); Serial.println( (char)n ); Serial.println( n );
|
|
|
|
|
10
|
Using Arduino / Networking, Protocols, and Devices / Re: Make Ethernet Shield report its MAC
|
on: March 08, 2013, 01:28:51 pm
|
SurferTim: Re your sketch for loading MAC etc from SD card. I am also trying to load the server port from the card. I am able to retrieve this datum from the card with code similar to yours in the setup() module. BUT - the line: EthernetServer server(port number); seems to need to be at the top of the sketch, BEEORE the port number has been retrieved. When I put the line EthernetServer server(8248); at the end of setup(), I (naturally) get the error " 'server' was not declared in this scope" at the line client = server.available(); in loop(). I don't see a way to make the variable "client" be global from within the setup() module. Do you see a workaround for this ? Am I supposed to be declaring "client" in the loop? That instruction will be repeating with every loop cycle then. Is that OK ? Bob All routers I have show all devices they have dealt with in the arp table. Localnet traffic may not go through the router, so if the device never contacts the router with an WAN (non-localnet) request, it is possible the device mac address may not end up in the arp table. I have the ability to ping from my router. That almost guarantees an entry in the arp table. What is your concern about the mac address? If you want to know if it is assigning the correct mac address from the SD, then Serial.print() the mac address when you get it from the SD card before assigning it to the w5100. edit: If you use dhcp to get an ip, you should be able to find the mac address in the dhcp lease records in the router. Here is a post that shows my code for using the SD card to store network settings. http://arduino.cc/forum/index.php/topic,128763.msg976118.html#msg976118
|
|
|
|
|
14
|
Using Arduino / Installation & Troubleshooting / Serial Monitor and Reboot
|
on: March 02, 2013, 11:06:23 am
|
Why does the Arduino reboot when I access its serial output with Serial Monitor or HyperTerminal, but not with Termite ? (see http://www.compuphase.com/software_termite.htm) I haven't tried any other terminal programs. If some command from the HyperTerminal (but not Termite) is making the Arduino reboot, then does that not suggest that there should be some way of making the Arduino reboot programatically (from within a sketch) ? I have not seen how to do this. Some of my Arduinos run continuously over very long periods, and it might be nice it they could reboot themselves periodically. Thank you. Bob W
|
|
|
|
|
15
|
Using Arduino / Programming Questions / Re: Changing Case of char Array
|
on: February 27, 2013, 06:49:56 pm
|
Mr. "Smoke": Below is how I tested your suggestion to UpCase a string. Works good. Doesn't look very good. Can you suggest how I can get rid of the for loop and replace it with a while (myString != NULL) ? I don't see how to step through the buffer without an index like "i". Thanks. Bob W. char myString[] = "Hello";
void setup() { Serial.begin(9600); for (int i = 0; i < 100; i++ ) // 100 set arbitrarily and excessively large { if ( myString[i] == NULL ) break; myString[i] = myString[i] & 0b11011111; }
Serial.print( &myString[0] ); For the ASCII alphas, bit 5 is the difference in case.
1 loop the length of the buffer with break on NULL, if the ASCII is not alpha-only then with a range check ( data & 0xDF >= 'A' ) && ( data & 0xDF <= 'Z' ) and either set or clear bit 5.... make the state an arg and 1 function could do both change to upper or lower case.
And you don't need string.h to do that.
|
|
|
|
|