system
June 24, 2011, 7:28pm
1
#include <SPI.h>
#include <Ethernet.h>
#include <Flash.h>
#include <SdFatUtil.h>
#include <TinyWebServer.h>
boolean index_handler(TinyWebServer& web_server);
static uint8_t mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// Don't forget to modify the IP to an available one on your home network
byte ip[] = { 192, 42, 172, 237 };
TinyWebServer::PathHandler handlers[] = {
{"/", TinyWebServer::GET, &index_handler },
{NULL},
};
boolean index_handler(TinyWebServer& web_server) {
web_server.send_error_code(200);
web_server.end_headers();
web_server << F("<html><body><h1>Hello World!</h1></body></html>\n");
return true;
}
boolean has_ip_address = false;
TinyWebServer web = TinyWebServer(handlers, NULL);
const char* ip_to_str(const uint8_t* ipAddr)
{
static char buf[16];
sprintf(buf, "%d.%d.%d.%d\0", ipAddr[0], ipAddr[1], ipAddr[2], ipAddr[3]);
return buf;
}
void setup() {
Serial.begin(115200);
pinMode(10, OUTPUT); // set the SS pin as an output (necessary!)
digitalWrite(10, HIGH); // but turn off the W5100 chip!
pinMode(4, OUTPUT); // set the SS pin as an output (necessary!)
digitalWrite(4, HIGH); // but turn off the SD card functionality!
Serial << F("Free RAM: ") << FreeRam() << "\n";
Serial << F("Setting up the Ethernet card...\n");
Ethernet.begin(mac, ip);
// Start the web server.
Serial << F("Web server starting...\n");
web.begin();
Serial << F("Ready to accept HTTP requests.\n\n");
}
void loop() {
web.process();
}
can someone help me change the IP address to my own and help me change anythink else i need to.
byte ip[] = { 192, 42, 172, 237 };
system
June 25, 2011, 2:55am
2
can someone help me change the IP address to my own
Sure. I'll be over in a little bit. Have the pizza and beer ready when I get there. I like Alaskan Amber and pepperoni and black olives.
Oh, I'll need a street address...
How hard is it to type in a number that is unique on your network?
system
June 25, 2011, 3:13am
3
i dont no what the number is i just some assistance!
i dont no what the number is i just some assistance!
If your aduino is connected to a router, the first three numbers should match the lan ip address of your router, and the fourth number should be something different (similar to below).
byte ip[] = { 192, 168, 1, 102 }; // ip on lan
system
June 25, 2011, 1:20pm
5
Use ipconfig to determine the IP address of your computer. Run around the house/neighborhood and run ipconfig on every computer using your network.
As zoomkat points out, the first three fields will be (or at least should be) the same. The 4th field will be unique. Pick an unused value for the Arduino's IP address.
If you find that 192.168.1.1, 182.168.1.3, and 192.168.1.4 are in use, you can use 192.168.1.22 for the Arduino.
system
June 25, 2011, 3:11pm
6
thanks for the help i do understand now can the last number be anythink?
system
June 25, 2011, 3:38pm
7
can the last number be anythink?
Any value in the range 0 to 255 that is not currently being used. The values 0 and 255 have special meaning, so those should not be used.
Below is some simple client code that you can try. If this code works, you could use the ip address it uses.
//zoomkat 11-13-10
//simple ethernet client test code
//for use with IDE 0021 and W5100 ethernet shield
//modify the arduino lan ip address as needed
//open serial monitor to see what the arduino receives
//push the shield reset button to run client again
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 102 }; // Arduino IP address
byte server[] = { 208, 104, 2, 86 }; // zoomkat's web site
Client client(server, 80);
void setup()
{
Ethernet.begin(mac, ip);
Serial.begin(9600);
Serial.println("starting simple arduino client test");
Serial.println();
delay(1000);
Serial.println("connecting...");
if (client.connect()) {
Serial.println("connected");
client.println("GET /~shb/arduino.txt HTTP/1.0");
client.println();
} else {
Serial.println("connection failed");
}
}
void loop()
{
if (client.available()) {
char c = client.read();
Serial.print(c);
}
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
Serial.println("==================================");
Serial.println("");
client.stop();
for(;;);
}
}
system
June 25, 2011, 4:33pm
9
thanks for your patience with me the server code?
thats unique with the ethernet shield?
thanks for your patience with me the server code?
thats unique with the ethernet shield?
Yes, there are W5100 based ethernet shields, and ENC28J60 based ethernet shields. The ENC28J60 apparently requires advanced programming abilities, where as the W5100 shields are fairly simple to use. I have a W5100 shield, so can't speak to the programming for a ENC28J60 based shield.