I want to print a text every like "Test" on my webserver. I use the libary EtherCard.h When i now upload my sketch with the text: client.print("Test") there is an error. Can anyone help me?
My Sketch:
// Present a "Will be back soon web page", as stand-in webserver.
// 2011-01-30 <jc@wippler.nl> http://opensource.org/licenses/mit-license.php
#include <EtherCard.h>
#define STATIC 1 // set to 1 to disable DHCP (adjust myip/gwip values below)
#if STATIC
// ethernet interface ip address
static byte myip[] = { 192,168,1,130 };
// gateway ip address
static byte gwip[] = { 192,168,1,1 };
#endif
// ethernet mac address - must be unique on your network
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
byte Ethernet::buffer[500]; // tcp/ip send and receive buffer
const char page[] PROGMEM =
"HTTP/1.0 503 Service Unavailable\r\n"
"Content-Type: text/html\r\n"
"Retry-After: 600\r\n"
"\r\n"
"<html>"
"<head><title>"
"Service Temporarily Unavailable"
"</title></head>"
"<body>"
"<h3>This service is currently unavailable</h3>"
"<p><em>"
"The main server is currently off-line.
"
"Please try again later."
"</em></p>"
"</body>"
"</html>"
;
void setup(){
Serial.begin(9600);
Serial.println("\n[backSoon]");
if (ether.begin(sizeof Ethernet::buffer, mymac, 10) == 0)
Serial.println( "Failed to access Ethernet controller");
#if STATIC
ether.staticSetup(myip, gwip);
#else
if (!ether.dhcpSetup())
Serial.println("DHCP failed");
#endif
ether.printIp("IP: ", ether.myip);
ether.printIp("GW: ", ether.gwip);
ether.printIp("DNS: ", ether.dnsip);
}
void loop(){
// wait for an incoming TCP packet, but ignore its contents
if (ether.packetLoop(ether.packetReceive())) {
memcpy_P(ether.tcpOffset(), page, sizeof page);
ether.httpServerReply(sizeof page - 1);
}
client.print("Test");
}
arduino_weather:
Maybe we can't declare client.print("sth") But there must be a way to print sth into the webserver like a float value (temperature, preasure) etc.
Of course there is. The page variable contains the web page to be sent. It is unlikely that that is what you really plan to send to a client. When you do decide what to send, you can put variable values as part of the content.
Do you know the command for print sth into the webpage?
const char page[] PROGMEM = "This is the fucking web page";
It's in PROGMEM, so it can't be changed. Whether you can get it out of PROGMEM effectively, that is whether the rest of the code NEEDS it to be in PROGMEM, or not, is up to you to find out.
If you can, you can change the string to include whatever you want. If not, you're hosed.
Do yourself a big favor. Get the real Ethernet shield. The one that is easy to use.
I agree with PaulS the W5100 is much better but if you are set on continuing with the ENC28J60 you might want to try the uipethernet library instead of ethercard because it has the same API as the Arduino Ethernet library so you can use the Client object.