Go Down

Topic: Arduino HTTP server sending malformed packets (Read 3928 times) previous topic - next topic



Code: [Select]
/* Print a string from Program Memory directly to save RAM */
void printProgStr (__FlashStringHelper * str)
  char * p = (char *) str;
  if (!p) return;  // no string, uh oh!

  char buf [strlen_P (p) + 1];  // dynamic allocation ;)
  byte i = 0;
  char c;
  while ((c = pgm_read_byte(p++)))
    buf [i++] = c;
  buf [i] = 0;
  Serial.println (buf);
} // end of printProgStr

void setup ()
  Serial.begin (115200);
  printProgStr (F("but does it get goat's blood out?"));
  Serial.println ();
}  // end of setup

void loop () {}

That buffers up the string so you can then do a single write on it (instead of the Serial.println that I have).
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics


Thanks, with a little bit of tweaking, that did it! I didn't realize there was a "pgm_read_byte()" function, that really helped.

Go Up