Go Down

Topic: Arduino HTTP server sending malformed packets (Read 1 time) previous topic - next topic

Nick Gammon

Here:

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

rtadams89

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
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy