Change the IP of your router to 192.168.0.1.
EDIT: Why /23? What's this?
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 0, 177); // Change the IP according to your local network
const byte SelectSlave_SD = 5; // For Ferduino Mega
//const byte SelectSlave_SD = 4; // For ethernet shield
const byte SelectSlave_ETH = 53;
const byte SelectSlave_RFM = 69;
EthernetServer server(80);
void setup()
{
pinMode(SelectSlave_SD, OUTPUT);
pinMode(SelectSlave_RFM, OUTPUT);
digitalWrite(SelectSlave_SD, HIGH);
digitalWrite(SelectSlave_RFM, HIGH);
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial)
{
; // wait for serial port to connect. Needed for Leonardo only
}
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip, SelectSlave_ETH);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
void loop()
{
// listen for incoming clients
EthernetClient client = server.available();
if (client)
{
uint8_t remoteIP[4];
client.getRemoteIP(remoteIP);
Serial.print("New client: ");
Serial.print(remoteIP[0]);
Serial.print(".");
Serial.print(remoteIP[1]);
Serial.print(".");
Serial.print(remoteIP[2]);
Serial.print(".");
Serial.println(remoteIP[3]);
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected())
{
if (client.available())
{
char c = client.read();
Serial.write(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank)
{
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close"); // the connection will be closed after completion of the response
client.println("Refresh: 5"); // refresh the page automatically every 5 sec
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
// output the value of each analog input pin
for (int analogChannel = 0; analogChannel < 6; analogChannel++)
{
int sensorReading = analogRead(analogChannel);
client.print("analog input ");
client.print(analogChannel);
client.print(" is ");
client.print(sensorReading);
client.println("<br />");
}
client.println("</html>");
break;
}
if (c == '\n')
{
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r')
{
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println("client disonnected");
}
}
analog input 0 is 336
analog input 1 is 333
analog input 2 is 336
analog input 3 is 334
analog input 4 is 383
analog input 5 is 361
New client: 192.168.0.187
GET / HTTP/1.1
Host: 192.168.0.177
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Cache-Control: max-age=0
analog input 0 is 332
analog input 1 is 327
analog input 2 is 325
analog input 3 is 324
analog input 4 is 384
analog input 5 is 357
client disonnected
New client: 192.168.0.187
GET / HTTP/1.1
Host: 192.168.0.177
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Cache-Control: max-age=0
*********
server is at 192.168.0.177
Initializing SD card...
SUCCESS - SD card initialized.
SUCCESS - Found index.htm file.
server is at 192.168.0.177
Initializing SD card...
ERROR - SD card initialization failed!
server is at 192.168.0.177
Initializing SD card...
SUCCESS - SD card initialized.
SUCCESS - Found index.htm file.
ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ...
server is at 192.168.0.177
Initializing SD card...
SUCCESS - SD card initialized.
SUCCESS - Found index.htm file.
const byte SelectSlave_SD = 5; // For Ferduino Mega
//const byte SelectSlave_SD = 4; // For ethernet shield
const byte SelectSlave_SD = 5; // For Ferduino Mega
//const byte SelectSlave_SD = 4; // For ethernet shield
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 0, 177); // Change the IP according to your local network
//const byte SelectSlave_SD = 5; // For Ferduino Mega
const byte SelectSlave_SD = 4; // For ethernet shield
const byte SelectSlave_ETH = 53;
const byte SelectSlave_RFM = 69;
EthernetServer server(80);
void setup()
{
pinMode(SelectSlave_SD, OUTPUT);
pinMode(SelectSlave_RFM, OUTPUT);
digitalWrite(SelectSlave_SD, HIGH);
digitalWrite(SelectSlave_RFM, HIGH);
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial)
{
; // wait for serial port to connect. Needed for Leonardo only
}
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip, SelectSlave_ETH);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
void loop()
{
// listen for incoming clients
EthernetClient client = server.available();
if (client)
{
uint8_t remoteIP[4];
client.getRemoteIP(remoteIP);
Serial.print("New client: ");
Serial.print(remoteIP[0]);
Serial.print(".");
Serial.print(remoteIP[1]);
Serial.print(".");
Serial.print(remoteIP[2]);
Serial.print(".");
Serial.println(remoteIP[3]);
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected())
{
if (client.available())
{
char c = client.read();
Serial.write(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank)
{
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close"); // the connection will be closed after completion of the response
client.println("Refresh: 5"); // refresh the page automatically every 5 sec
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
// output the value of each analog input pin
for (int analogChannel = 0; analogChannel < 6; analogChannel++)
{
int sensorReading = analogRead(analogChannel);
client.print("analog input ");
client.print(analogChannel);
client.print(" is ");
client.print(sensorReading);
client.println("<br />");
}
client.println("</html>");
break;
}
if (c == '\n')
{
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r')
{
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println("client disonnected");
}
}
analog input 0 is 342
analog input 1 is 339
analog input 2 is 344
analog input 3 is 340
analog input 4 is 398
analog input 5 is 370
client disonnected
New client: 192.168.0.187
GET / HTTP/1.1
Host: 192.168.0.177
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Cache-Control: max-age=0
#include <SPI.h>
#include <Ethernet.h>
#include <SdFat.h>
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 0, 177); // IP address, may need to change depending on network
EthernetServer server(80);
const byte SelectSlave_ETH = 53;
const byte SelectSlave_SD = 4; // For ethernet shield
//const byte SelectSlave_SD = 5; // For Ferduino Mega 2560
const byte SelectSlave_RFM = 69; // For Ferduino Mega 2560
Sd2Card card;
SdFile file;
SdFile root;
SdVolume volume;
void setup()
{
pinMode(SelectSlave_RFM, OUTPUT);
digitalWrite(SelectSlave_RFM, HIGH);
Serial.begin(9600);
while (!Serial)
{
; // wait for serial port to connect. Needed for Leonardo only
}
Ethernet.begin(mac, ip, SelectSlave_ETH);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
Serial.println("Initializing SD card...");
if (!card.init(SPI_QUARTER_SPEED, SelectSlave_SD))
{
Serial.println("ERROR - SD card initialization failed!");
return;
}
volume.init(&card);
root.openRoot(&volume);
Serial.println("SUCCESS - SD card initialized.");
if (!file.open(&root, "index.htm", O_READ))
{
Serial.println("ERROR - Can't open index.htm file!");
return;
}
file.close();
Serial.println("SUCCESS - Found index.htm file.");
}
void loop()
{
EthernetClient client = server.available();
if (client)
{
boolean currentLineIsBlank = true;
while (client.connected())
{
if (client.available())
{
char c = client.read();
if (c == '\n' && currentLineIsBlank)
{
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println();
if (file.open(&root, "index.htm", O_READ))
{
while(file.available())
{
client.write(file.read());
}
file.close();
}
break;
}
if (c == '\n')
{
currentLineIsBlank = true;
}
else if (c != '\r')
{
currentLineIsBlank = false;
}
}
}
delay(1);
client.stop();
}
}
server is at 0.0.0.0
Initializing SD card...
ERROR - SD card initialization failed!
#include <SdFat.h>
const byte SelectSlave_SD = 4; // For ethernet shield
//const byte SelectSlave_SD = 5; // For Ferduino Mega 2560
const byte SelectSlave_RFM = 69; // For Ferduino Mega 2560
const byte SelectSlave_ETH = 53; // For Ferduino Mega 2560
Sd2Card card;
SdFile file;
SdFile root;
SdVolume volume;
float temp;
float tempe;
void setup()
{
int16_t n;
char buf[8];
pinMode(SelectSlave_RFM, OUTPUT);
pinMode(SelectSlave_ETH, OUTPUT);
digitalWrite(SelectSlave_RFM, HIGH);
digitalWrite(SelectSlave_ETH, HIGH);
Serial.begin(9600);
card.init(SPI_QUARTER_SPEED, SelectSlave_SD);
volume.init(&card);
root.openRoot(&volume);
while(!Serial)
{
; // wait for serial.
}
if(file.open(&root, "LOGTDIA.TXT", O_CREAT | O_APPEND | O_WRITE))
{
Serial.println("Writing...");
Serial.println();
for(temp = 27.5; temp > 22.0; temp -= 0.15)
{
file.print(temp);
file.write((uint8_t*)"\0", 1);
file.write((uint8_t*)"\r\n", 2);
}
for(tempe = 22.5; tempe < 28.0; tempe += 0.15)
{
file.print(tempe);
file.write((uint8_t*)"\0", 1);
file.write((uint8_t*)"\r\n", 2);
}
file.close();
Serial.println("Done!");
Serial.println();
}
else
{
Serial.println("Can't open.");
}
if(file.open(&root, "LOGTDIA.TXT", O_READ))
{
Serial.println("Reading...");
Serial.println();
delay(5000);
while ((n = file.read(buf, sizeof(buf))) > 0)
{
Serial.println(buf);
}
file.close();
Serial.println();
Serial.print("Finished!");
}
}
void loop()
{
}
Writing...
Done!
Reading...
27.50
27.35
27.20
27.05
26.90
26.75
26.60
26.45
26.30
....
can't open
Can't open.
can't open
#include <SdFat.h>
const byte SelectSlave_SD = 4; // For ethernet shield
//const byte SelectSlave_SD = 5; // For Ferduino Mega 2560
const byte SelectSlave_RFM = 69; // For Ferduino Mega 2560
const byte SelectSlave_ETH = 53; // For Ferduino Mega 2560
Sd2Card card;
SdFile file;
SdFile root;
SdVolume volume;
float temp;
float tempe;
void setup()
{
int16_t n;
char buf[8];
pinMode(SelectSlave_RFM, OUTPUT);
pinMode(SelectSlave_ETH, OUTPUT);
digitalWrite(SelectSlave_RFM, HIGH);
digitalWrite(SelectSlave_ETH, HIGH);
Serial.begin(9600);
card.init(SPI_FULL_SPEED, SelectSlave_SD);
volume.init(&card);
root.openRoot(&volume);
while(!Serial)
{
; // wait for serial.
}
if(file.open(&root, "LOGTDIA.TXT", O_CREAT | O_APPEND | O_WRITE))
{
Serial.println("Writing...");
Serial.println();
for(temp = 27.5; temp > 22.0; temp -= 0.15)
{
file.print(temp);
file.write((uint8_t*)"\0", 1);
file.write((uint8_t*)"\r\n", 2);
}
for(tempe = 22.5; tempe < 28.0; tempe += 0.15)
{
file.print(tempe);
file.write((uint8_t*)"\0", 1);
file.write((uint8_t*)"\r\n", 2);
}
file.close();
Serial.println("Done!");
Serial.println();
}
else
{
Serial.println("Can't open.");
}
if(file.open(&root, "LOGTDIA.TXT", O_READ))
{
Serial.println("Reading...");
Serial.println();
delay(5000);
while ((n = file.read(buf, sizeof(buf))) > 0)
{
Serial.println(buf);
}
file.close();
Serial.println();
Serial.print("Finished!");
}
}
void loop()
{
}
Writing...
Done!
Reading...
27.50
27.35
...
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 0, 177); // Change the IP according to your local network
//const byte SelectSlave_SD = 5; // For Ferduino Mega
const byte SelectSlave_SD = 4; // For ethernet shield
const byte SelectSlave_ETH = 53;
const byte SelectSlave_RFM = 69;
EthernetServer server(80);
void setup()
{
pinMode(SelectSlave_SD, OUTPUT);
pinMode(SelectSlave_RFM, OUTPUT);
digitalWrite(SelectSlave_SD, HIGH);
digitalWrite(SelectSlave_RFM, HIGH);
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial)
{
; // wait for serial port to connect. Needed for Leonardo only
}
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip, SelectSlave_ETH);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
void loop()
{
// listen for incoming clients
EthernetClient client = server.available();
if (client)
{
uint8_t remoteIP[4];
client.getRemoteIP(remoteIP);
Serial.print("New client: ");
Serial.print(remoteIP[0]);
Serial.print(".");
Serial.print(remoteIP[1]);
Serial.print(".");
Serial.print(remoteIP[2]);
Serial.print(".");
Serial.println(remoteIP[3]);
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected())
{
if (client.available())
{
char c = client.read();
Serial.write(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank)
{
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close"); // the connection will be closed after completion of the response
client.println("Refresh: 5"); // refresh the page automatically every 5 sec
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
// output the value of each analog input pin
for (int analogChannel = 0; analogChannel < 6; analogChannel++)
{
int sensorReading = analogRead(analogChannel);
client.print("analog input ");
client.print(analogChannel);
client.print(" is ");
client.print(sensorReading);
client.println("<br />");
}
client.println("</html>");
break;
}
if (c == '\n')
{
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r')
{
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println("client disonnected");
}
}
Serial:
sserver is at 192.168.0.177
New client: 192.168.0.187
GET / HTTP/1.1
Host: 192.168.0.177
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Browser:
analog input 0 is 353
analog input 1 is 343
analog input 2 is 345
analog input 3 is 349
analog input 4 is 405
analog input 5 is 371
#include <SPI.h>
#include <Ethernet.h>
#include <SdFat.h>
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 0, 177); // IP address, may need to change depending on network
EthernetServer server(80);
const byte SelectSlave_ETH = 53;
const byte SelectSlave_SD = 4; // For ethernet shield
//const byte SelectSlave_SD = 5; // For Ferduino Mega 2560
const byte SelectSlave_RFM = 69; // For Ferduino Mega 2560
Sd2Card card;
SdFile file;
SdFile root;
SdVolume volume;
void setup()
{
pinMode(SelectSlave_RFM, OUTPUT);
digitalWrite(SelectSlave_RFM, HIGH);
Serial.begin(9600);
while (!Serial)
{
; // wait for serial port to connect. Needed for Leonardo only
}
Ethernet.begin(mac, ip, SelectSlave_ETH);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
Serial.println("Initializing SD card...");
if (!card.init(SPI_FULL_SPEED, SelectSlave_SD))
{
Serial.println("ERROR - SD card initialization failed!");
return;
}
volume.init(&card);
root.openRoot(&volume);
Serial.println("SUCCESS - SD card initialized.");
if (!file.open(&root, "index.htm", O_READ))
{
Serial.println("ERROR - Can't open index.htm file!");
return;
}
file.close();
Serial.println("SUCCESS - Found index.htm file.");
}
void loop()
{
EthernetClient client = server.available();
if (client)
{
boolean currentLineIsBlank = true;
while (client.connected())
{
if (client.available())
{
char c = client.read();
if (c == '\n' && currentLineIsBlank)
{
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println();
if (file.open(&root, "index.htm", O_READ))
{
while(file.available())
{
client.write(file.read());
}
file.close();
}
break;
}
if (c == '\n')
{
currentLineIsBlank = true;
}
else if (c != '\r')
{
currentLineIsBlank = false;
}
}
}
delay(1);
client.stop();
}
}
server is at 192.168.0.177
Initializing SD card...
SUCCESS - SD card initialized.
SUCCESS - Found index.htm file.
// Save this file on SD card as index.htm
Hello world!
This page is stored in a SD card plugged on Arduino
Visit my website: www.ferduino.com
Code adapted by Fernando Garcia
Return to DIY Ferduino controller
Users viewing this topic: No registered users and 0 guests