Skip to content

Commit

Permalink
updated examples to put Serial.print strings in flash instead of RAM …
Browse files Browse the repository at this point in the history
…and to declare PROGMEM variables as const
  • Loading branch information
vicatcu committed Jul 16, 2014
1 parent c22c408 commit 7c0dd09
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 41 deletions.
2 changes: 1 addition & 1 deletion examples/JeeUdp/JeeUdp.ino
Expand Up @@ -84,7 +84,7 @@ void setup (){
ether.printIp("IP: ", ether.myip);
}

char okHeader[] PROGMEM =
const char okHeader[] PROGMEM =
"HTTP/1.0 200 OK\r\n"
"Content-Type: text/html\r\n"
"Pragma: no-cache\r\n"
Expand Down
2 changes: 1 addition & 1 deletion examples/etherNode/etherNode.ino
Expand Up @@ -89,7 +89,7 @@ void setup(){
#endif
}

char okHeader[] PROGMEM =
const char okHeader[] PROGMEM =
"HTTP/1.0 200 OK\r\n"
"Content-Type: text/html\r\n"
"Pragma: no-cache\r\n"
Expand Down
4 changes: 2 additions & 2 deletions examples/getDHCPandDNS/getDHCPandDNS.ino
Expand Up @@ -8,7 +8,7 @@
// ethernet interface mac address
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
// remote website name
const char website[] = "google.com";
const char website[] PROGMEM = "google.com";

byte Ethernet::buffer[700];
static long timer;
Expand Down Expand Up @@ -50,6 +50,6 @@ void loop () {
if (millis() > timer + REQUEST_RATE) {
timer = millis();
Serial.println("\n>>> REQ");
ether.browseUrl("/foo/", "bar", website, my_result_cb);
ether.browseUrl(PSTR("/foo/"), "bar", website, my_result_cb);
}
}
34 changes: 17 additions & 17 deletions examples/noipClient/noipClient.ino
Expand Up @@ -51,19 +51,19 @@ Stash stash;
void setup () {

Serial.begin(57600);
Serial.println("NoIP Client Demo");
Serial.println(F("NoIP Client Demo"));
Serial.println();

if (!ether.begin(sizeof Ethernet::buffer, mymac, 10))
Serial.println( "Failed to access Ethernet controller");
Serial.println(F( "Failed to access Ethernet controller"));
else
Serial.println("Ethernet controller initialized");
Serial.println(F("Ethernet controller initialized"));
Serial.println();

if (!ether.dhcpSetup())
Serial.println("Failed to get configuration from DHCP");
Serial.println(F("Failed to get configuration from DHCP"));
else
Serial.println("DHCP configuration done");
Serial.println(F("DHCP configuration done"));

ether.printIp("IP Address:\t", ether.myip);
ether.printIp("Netmask:\t", ether.netmask);
Expand All @@ -76,7 +76,7 @@ void setup () {
// Resolve IP for getIP_web and noIP_web
// and store them into global variables
if (!ether.dnsLookup(getIP_web)) {
Serial.print("Unable to resolve IP for ");
Serial.print(F("Unable to resolve IP for "));
SerialPrint_P(getIP_web);
actual_status = STATUS_ERROR;
} else {
Expand All @@ -85,7 +85,7 @@ void setup () {
ether.printIp(" resolved to:\t", ether.hisip);
}
if (!ether.dnsLookup(noIP_web)) {
Serial.print("Unable to resolve IP for ");
Serial.print(F("Unable to resolve IP for "));
SerialPrint_P(noIP_web);
actual_status = STATUS_ERROR;
} else {
Expand Down Expand Up @@ -116,7 +116,7 @@ void checkPublicIP() {

if(millis() > check_ip_timer) {

Serial.print("Checking public IP... ");
Serial.print(F("Checking public IP... "));

// Create a request for GetIP service,
// set destination IP and send request saving session_id
Expand Down Expand Up @@ -147,7 +147,7 @@ void checkPublicIPResponse() {
// If we can't resolve actual IP for our hostname on NoIP,
// return to IDLE state and wait for the next interval
if(!ether.dnsLookup(noIP_host)) {
Serial.print("Unable to resolve actual IP for ");
Serial.print(F("Unable to resolve actual IP for "));
SerialPrint_P(noIP_host);
Serial.println();
actual_status = STATUS_IDLE;
Expand All @@ -162,19 +162,19 @@ void checkPublicIPResponse() {
if(i < 3) dnsIp = dnsIp + ".";
}
SerialPrint_P(noIP_host);
Serial.print(" resolved to ");
Serial.print(F(" resolved to "));
Serial.println(dnsIp);

// If they are the same, we can sit down and wait for the next interval
if(actualIp.compareTo(dnsIp) == 0) {
Serial.println("No update needed :)");
Serial.println(F("No update needed :)"));
actual_status = STATUS_IDLE;
attempt = 0;
check_ip_timer = millis() + CHECK_IP_INTERVAL;

// Different? We'd better to update NoIP!
} else {
Serial.println("Update needed :(");
Serial.println(F("Update needed :("));
actual_status = STATUS_NOIP_NEEDS_UPDATE;
attempt = 0;
}
Expand All @@ -185,10 +185,10 @@ void checkPublicIPResponse() {
// and wait for the next interval
} else {
if(millis() > request_timer) {
Serial.println(" no response :(");
Serial.println(F(" no response :("));
actual_status = STATUS_IDLE;
if(attempt == MAX_ATTEMPTS) {
Serial.println("Max number of attempts reached");
Serial.println(F("Max number of attempts reached"));
attempt = 0;
check_ip_timer = millis() + CHECK_IP_INTERVAL;
}
Expand All @@ -198,7 +198,7 @@ void checkPublicIPResponse() {

void updateNoIP() {

Serial.print("Updating NoIP...");
Serial.print(F("Updating NoIP..."));

// Create a request for updating NoIP using NoIP API,
// set destination IP and send request saving session_id
Expand Down Expand Up @@ -253,9 +253,9 @@ void checkNoIPResponse() {
} else {

if(millis() > request_timer) {
Serial.println("No response from NoIP");
Serial.println(F("No response from NoIP"));
if(attempt == MAX_ATTEMPTS) {
Serial.println("Max number of attempts reached");
Serial.println(F("Max number of attempts reached"));
actual_status = STATUS_IDLE;
attempt = 0;
check_ip_timer = millis() + CHECK_IP_INTERVAL;
Expand Down
8 changes: 4 additions & 4 deletions examples/pachube/pachube.ino
Expand Up @@ -18,19 +18,19 @@ Stash stash;

void setup () {
Serial.begin(57600);
Serial.println("\n[webClient]");
Serial.println(F("\n[webClient]"));

if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
Serial.println( "Failed to access Ethernet controller");
Serial.println(F("Failed to access Ethernet controller"));
if (!ether.dhcpSetup())
Serial.println("DHCP failed");
Serial.println(F("DHCP failed"));

ether.printIp("IP: ", ether.myip);
ether.printIp("GW: ", ether.gwip);
ether.printIp("DNS: ", ether.dnsip);

if (!ether.dnsLookup(website))
Serial.println("DNS failed");
Serial.println(F("DNS failed"));

ether.printIp("SRV: ", ether.hisip);
}
Expand Down
4 changes: 2 additions & 2 deletions examples/pings/pings.ino
Expand Up @@ -19,9 +19,9 @@ void setup () {
Serial.println("\n[pings]");

if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
Serial.println( "Failed to access Ethernet controller");
Serial.println(F("Failed to access Ethernet controller"));
if (!ether.dhcpSetup())
Serial.println("DHCP failed");
Serial.println(F("DHCP failed"));

ether.printIp("IP: ", ether.myip);
ether.printIp("GW: ", ether.gwip);
Expand Down
2 changes: 1 addition & 1 deletion examples/rbbb_server/rbbb_server.ino
Expand Up @@ -12,7 +12,7 @@ BufferFiller bfill;

void setup () {
if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
Serial.println( "Failed to access Ethernet controller");
Serial.println(F("Failed to access Ethernet controller"));
ether.staticSetup(myip);
}

Expand Down
8 changes: 4 additions & 4 deletions examples/testDHCP/testDHCP.ino
Expand Up @@ -14,7 +14,7 @@ byte Ethernet::buffer[700];

void setup () {
Serial.begin(57600);
Serial.println("\n[testDHCP]");
Serial.println(F("\n[testDHCP]"));

Serial.print("MAC: ");
for (byte i = 0; i < 6; ++i) {
Expand All @@ -25,11 +25,11 @@ void setup () {
Serial.println();

if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
Serial.println( "Failed to access Ethernet controller");
Serial.println(F("Failed to access Ethernet controller"));

Serial.println("Setting up DHCP");
Serial.println(F("Setting up DHCP"));
if (!ether.dhcpSetup())
Serial.println( "DHCP failed");
Serial.println(F("DHCP failed"));

ether.printIp("My IP: ", ether.myip);
ether.printIp("Netmask: ", ether.netmask);
Expand Down
6 changes: 3 additions & 3 deletions examples/twitter/twitter.ino
Expand Up @@ -53,16 +53,16 @@ void setup () {
Serial.println("\n[webClient]");

if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
Serial.println( "Failed to access Ethernet controller");
Serial.println(F("Failed to access Ethernet controller"));
if (!ether.dhcpSetup())
Serial.println("DHCP failed");
Serial.println(F("DHCP failed"));

ether.printIp("IP: ", ether.myip);
ether.printIp("GW: ", ether.gwip);
ether.printIp("DNS: ", ether.dnsip);

if (!ether.dnsLookup(website))
Serial.println("DNS failed");
Serial.println(F("DNS failed"));

ether.printIp("SRV: ", ether.hisip);

Expand Down
6 changes: 3 additions & 3 deletions examples/udpListener/udpListener.ino
Expand Up @@ -31,15 +31,15 @@ void udpSerialPrint(word port, byte ip[4], const char *data, word len) {

void setup(){
Serial.begin(57600);
Serial.println("\n[backSoon]");
Serial.println(F("\n[backSoon]"));

if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
Serial.println( "Failed to access Ethernet controller");
Serial.println(F("Failed to access Ethernet controller"));
#if STATIC
ether.staticSetup(myip, gwip);
#else
if (!ether.dhcpSetup())
Serial.println("DHCP failed");
Serial.println(F("DHCP failed"));
#endif

ether.printIp("IP: ", ether.myip);
Expand Down
6 changes: 3 additions & 3 deletions examples/webClient/webClient.ino
Expand Up @@ -21,12 +21,12 @@ static void my_callback (byte status, word off, word len) {

void setup () {
Serial.begin(57600);
Serial.println("\n[webClient]");
Serial.println(F("\n[webClient]"));

if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
Serial.println( "Failed to access Ethernet controller");
Serial.println(F("Failed to access Ethernet controller"));
if (!ether.dhcpSetup())
Serial.println("DHCP failed");
Serial.println(F("DHCP failed"));

ether.printIp("IP: ", ether.myip);
ether.printIp("GW: ", ether.gwip);
Expand Down

0 comments on commit 7c0dd09

Please sign in to comment.