Show Posts
Pages: [1] 2 3 4
1  Using Arduino / Networking, Protocols, and Devices / Have Arduino Delete Tweet on: June 01, 2013, 08:33:13 pm
I have a working Arduino sketch that posts a tweet each time my garage door goes up or down.
(See: http://www.allmytweets.net/?screen_name=@whatta_nerd )


Question:  What would it take to make Arduino delete the oldest tweet prior to posting a new one ?
               Modify (add to) Twitter Library ?
               I don't see any "delete" capability in it, as it is.

I don't really know where to start.
This sounds like something that someone might have investigated before.

BobW

2  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.

3  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.

4  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 ??



Code:
/*  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");
  }
}
5  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

Code:
#define P(name)   static const prog_uchar name[] PROGMEM

P gets replaced by whatever it is defined as, so
Code:
P(signMessage) = "This is some text . . . ";
gets changed to
Code:
static const prog_uchar signMessage[] PROGMEM = "This is some text . . . ";
6  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


Code:
#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 / Re: (char)n vs char(n) on: March 10, 2013, 10:11:13 am
Thank you Jos !
Bob W

'(char)n' is the old C notation; 'char(n)' is C++s functional cast notation; both do exactly the same thing.

kind regards,

Jos
8  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.

Code:
int n = 88;
Serial.println( n );
Serial.println( char(n) );
Serial.println( n );
Serial.println( (char)n );
Serial.println( n );
9  Using Arduino / Networking, Protocols, and Devices / Re: Make Ethernet Shield report its MAC on: March 08, 2013, 02:14:53 pm
Tim:

That worked.
Thanks !
10  Using Arduino / Networking, Protocols, and Devices / Re: Make Ethernet Shield report its MAC on: March 08, 2013, 02:05:07 pm
Thanks.
I'll try it.
11  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:

Code:
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

Code:
EthernetServer server(8248);

at the end of setup(), I (naturally) get the error " 'server' was not declared in this scope" at the line   

Code:
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

12  Using Arduino / Networking, Protocols, and Devices / Re: Make Ethernet Shield report its MAC on: March 08, 2013, 09:29:13 am
Thanks Tim.  And thanks for sharing your code.
I don't have a "concern".
I'm just doing what I call "expanding my brain" - i.e. trying to learn something new.
I'm good to go.
Thanks again.

Bob
13  Using Arduino / Networking, Protocols, and Devices / Re: Make Ethernet Shield report its MAC on: March 07, 2013, 09:02:22 pm
My Linksys E4200 shows me the dynamically assigned IP addresses, but I don't see where static IP addresses are displayed.  Do all routers show the ARP table?
14  Using Arduino / Networking, Protocols, and Devices / Make Ethernet Shield report its MAC on: March 07, 2013, 08:21:06 pm
Is there a way to make my Ethernet Shield report what MAC address has been assigned to it ?

I'm giving it its MAC address from a text file on an SD card, and I'd like to give myself some feedback so that I know the proper MAC was installed.

Thanks.

Bob W
15  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
Pages: [1] 2 3 4