daily_automated
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Chat Server
|
||||
*
|
||||
* A simple server that distributes any incoming messages to all
|
||||
* connected clients. To use telnet to 10.0.0.177 and type!
|
||||
*/
|
||||
|
||||
#include <Ethernet.h>
|
||||
|
||||
// network configuration. gateway and subnet are optional.
|
||||
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
|
||||
byte ip[] = { 10, 0, 0, 177 };
|
||||
byte gateway[] = { 10, 0, 0, 1 };
|
||||
byte subnet[] = { 255, 255, 0, 0 };
|
||||
|
||||
// telnet defaults to port 23
|
||||
Server server(23);
|
||||
|
||||
void setup()
|
||||
{
|
||||
// initialize the ethernet device
|
||||
Ethernet.begin(mac, ip, gateway, subnet);
|
||||
|
||||
// start listening for clients
|
||||
server.begin();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Client client = server.available();
|
||||
if (client) {
|
||||
server.write(client.read());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
#include <Ethernet.h>
|
||||
|
||||
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
|
||||
byte ip[] = { 192, 168, 42, 42 };
|
||||
byte server[] = { 192, 168, 42, 1 };
|
||||
|
||||
Client client(server, 80);
|
||||
|
||||
void setup() {
|
||||
Ethernet.begin(mac, ip);
|
||||
Serial.begin(9600);
|
||||
|
||||
delay(1000);
|
||||
Serial.println("connecting...");
|
||||
|
||||
if (client.connect()) {
|
||||
Serial.println("connected");
|
||||
client.println("GET /search?q=arduino 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.");
|
||||
client.stop();
|
||||
for(;;)
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
#include <Ethernet.h>
|
||||
|
||||
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
|
||||
byte ip[] = { 192, 168, 111, 2 };
|
||||
byte server[] = { 192, 168, 111, 1 };
|
||||
|
||||
Client client(server, 80);
|
||||
|
||||
#ifdef ETHERSHIELD_DEBUG
|
||||
#include <inttypes.h>
|
||||
uint8_t *debugCodes;
|
||||
|
||||
void printSocketDebug() {
|
||||
debugCodes = Ethernet.returnDebug();
|
||||
if (debugCodes[0] != 255) {
|
||||
Serial.println("DEBUG:");
|
||||
for (int i = 0; debugCodes[i] != 255; i++) {
|
||||
Serial.print(" ");
|
||||
Serial.println(debug2str(debugCodes[i]));
|
||||
}
|
||||
Ethernet.clearDebug();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void setup() {
|
||||
Ethernet.begin(mac, ip);
|
||||
Serial.begin(9600);
|
||||
|
||||
delay(1000);
|
||||
Serial.println("connecting...");
|
||||
int isConnected = client.connect();
|
||||
|
||||
#ifdef ETHERSHIELD_DEBUG
|
||||
printSocketDebug();
|
||||
Serial.println(client.debug());
|
||||
#endif
|
||||
|
||||
if (isConnected) {
|
||||
Serial.println("connected");
|
||||
client.println("GET /search?q=arduino 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.");
|
||||
client.stop();
|
||||
for(;;)
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Web Server
|
||||
*
|
||||
* A simple web server that shows the value of the analog input pins.
|
||||
*/
|
||||
|
||||
#include <Ethernet.h>
|
||||
|
||||
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
|
||||
byte ip[] = { 10, 0, 0, 177 };
|
||||
|
||||
Server server(80);
|
||||
|
||||
void setup()
|
||||
{
|
||||
Ethernet.begin(mac, ip);
|
||||
server.begin();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Client client = server.available();
|
||||
if (client) {
|
||||
// an http request ends with a blank line
|
||||
boolean current_line_is_blank = true;
|
||||
while (client.connected()) {
|
||||
if (client.available()) {
|
||||
char c = client.read();
|
||||
// if we've gotten to the end of the line (received a newline
|
||||
// character) and the line is blank, the http request has ended,
|
||||
// so we can send a reply
|
||||
if (c == '\n' && current_line_is_blank) {
|
||||
// send a standard http response header
|
||||
client.println("HTTP/1.1 200 OK");
|
||||
client.println("Content-Type: text/html");
|
||||
client.println();
|
||||
|
||||
// output the value of each analog input pin
|
||||
for (int i = 0; i < 6; i++) {
|
||||
client.print("analog input ");
|
||||
client.print(i);
|
||||
client.print(" is ");
|
||||
client.print(analogRead(i));
|
||||
client.println("<br />");
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (c == '\n') {
|
||||
// we're starting a new line
|
||||
current_line_is_blank = true;
|
||||
} else if (c != '\r') {
|
||||
// we've gotten a character on the current line
|
||||
current_line_is_blank = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
// give the web browser time to receive the data
|
||||
delay(1);
|
||||
client.stop();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
#include <Ethernet.h>
|
||||
|
||||
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
|
||||
byte ip[] = { 192, 168, 111, 2 };
|
||||
|
||||
Server server(80);
|
||||
|
||||
#ifdef ETHERSHIELD_DEBUG
|
||||
#include <inttypes.h>
|
||||
uint8_t *debugCodes;
|
||||
|
||||
void printSocketDebug() {
|
||||
debugCodes = Ethernet.returnDebug();
|
||||
if (debugCodes[0] != 255) {
|
||||
Serial.println("DEBUG:");
|
||||
for (int i = 0; debugCodes[i] != 255; i++) {
|
||||
Serial.print(" ");
|
||||
Serial.println(debug2str(debugCodes[i]));
|
||||
}
|
||||
Ethernet.clearDebug();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void setup() {
|
||||
Ethernet.begin(mac, ip);
|
||||
server.begin();
|
||||
|
||||
#ifdef ETHERSHIELD_DEBUG
|
||||
Serial.begin(9600);
|
||||
#endif
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Client client = server.available();
|
||||
|
||||
#ifdef ETHERSHIELD_DEBUG
|
||||
printSocketDebug();
|
||||
#endif
|
||||
|
||||
if (client) {
|
||||
|
||||
#ifdef ETHERSHIELD_DEBUG
|
||||
Serial.println("New client!");
|
||||
#endif
|
||||
|
||||
// an http request ends with a blank line
|
||||
boolean current_line_is_blank = true;
|
||||
while (client.connected()) {
|
||||
if (client.available()) {
|
||||
char c = client.read();
|
||||
|
||||
#ifdef ETHERSHIELD_DEBUG
|
||||
Serial.print(c);
|
||||
#endif
|
||||
|
||||
// if we've gotten to the end of the line (received a newline
|
||||
// character) and the line is blank, the http request has ended,
|
||||
// so we can send a reply
|
||||
if (c == '\n' && current_line_is_blank) {
|
||||
// send a standard http response header
|
||||
|
||||
#ifdef ETHERSHIELD_DEBUG
|
||||
Serial.println("Received headers!");
|
||||
#endif
|
||||
|
||||
client.println("HTTP/1.1 200 OK");
|
||||
client.println("Content-Type: text/html");
|
||||
client.println();
|
||||
|
||||
// output the value of each analog input pin
|
||||
client.print("Analog input 0 = <b>");
|
||||
client.print(analogRead(0));
|
||||
client.println("</b><br>");
|
||||
client.print("millis() = <b>");
|
||||
client.println(millis());
|
||||
client.println("</b><br>");
|
||||
break;
|
||||
}
|
||||
if (c == '\n') {
|
||||
// we're starting a new line
|
||||
current_line_is_blank = true;
|
||||
} else if (c != '\r') {
|
||||
// we've gotten a character on the current line
|
||||
current_line_is_blank = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef ETHERSHIELD_DEBUG
|
||||
Serial.println("Disconnected");
|
||||
#endif
|
||||
|
||||
// give the web browser time to receive the data
|
||||
delay(1);
|
||||
client.stop();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
#include <Ethernet.h>
|
||||
|
||||
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
|
||||
byte ip[] = { 192, 168, 1, 177 };
|
||||
|
||||
Server server(80);
|
||||
|
||||
void setup() {
|
||||
Ethernet.begin(mac, ip);
|
||||
server.begin();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Client client = server.available();
|
||||
if (client) {
|
||||
boolean current_line_is_blank = true;
|
||||
while (client.connected()) {
|
||||
if (client.available()) {
|
||||
char c = client.read();
|
||||
if (c == '\n' && current_line_is_blank) {
|
||||
client.println("HTTP/1.1 200 OK");
|
||||
client.println("Content-Type: text/html");
|
||||
client.println();
|
||||
|
||||
client.print("Analog input 0 = <b>");
|
||||
client.print(analogRead(0));
|
||||
client.println("</b><br>");
|
||||
client.print("millis() = <b>");
|
||||
client.println(millis());
|
||||
client.println("</b><br>");
|
||||
break;
|
||||
}
|
||||
if (c == '\n') {
|
||||
current_line_is_blank = true;
|
||||
} else if (c != '\r') {
|
||||
current_line_is_blank = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
delay(1);
|
||||
client.stop();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
#include <Ethernet.h>
|
||||
#define LED 8
|
||||
|
||||
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
|
||||
byte ip[] = { 192, 168, 111, 2 };
|
||||
char link[30], LEDStatus[4];
|
||||
|
||||
Server server(80);
|
||||
|
||||
void setup() {
|
||||
pinMode(LED, OUTPUT);
|
||||
Ethernet.begin(mac, ip);
|
||||
server.begin();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Client client = server.available();
|
||||
if (client) {
|
||||
char request[10];
|
||||
int i = 0;
|
||||
boolean current_line_is_blank = true;
|
||||
request[9] = '\0';
|
||||
while (client.connected()) {
|
||||
if (client.available()) {
|
||||
char c = client.read();
|
||||
if (i < 9) {
|
||||
request[i] = c;
|
||||
i++;
|
||||
}
|
||||
if (c == '\n' && current_line_is_blank) {
|
||||
client.println("HTTP/1.1 200 OK");
|
||||
client.println("Content-Type: text/html");
|
||||
client.println();
|
||||
|
||||
client.println("<html><head><title>Arduino etherShield</title></head><body>");
|
||||
client.println("<h1>Arduino etherShield Example</h1>");
|
||||
client.println("<table>");
|
||||
client.print("<tr><td>Analog inputs:</td><td><b>");
|
||||
for (int x = 0; x < 6; x++) {
|
||||
client.print(x);
|
||||
client.print(" = ");
|
||||
client.print(5000 * (analogRead(x) / 1024.0));
|
||||
client.print(" mV<br>");
|
||||
}
|
||||
client.println("</b></td></tr><tr><td>uptime:</td> <td><b>");
|
||||
client.print(millis() / 1000.0);
|
||||
client.println(" seconds</b></td></tr>");
|
||||
if (strncmp("GET /off", request, 8) == 0) {
|
||||
digitalWrite(LED, LOW);
|
||||
sprintf(LEDStatus, "OFF");
|
||||
sprintf(link, "<a href=\"/on\">Turn on</a>");
|
||||
}
|
||||
else {
|
||||
sprintf(LEDStatus, "ON");
|
||||
digitalWrite(LED, HIGH);
|
||||
sprintf(link, "<a href=\"/off\">Turn off</a>");
|
||||
}
|
||||
client.print("<tr><td>LED status:</td> <td><b>");
|
||||
client.print(LEDStatus);
|
||||
client.println("</b></td></tr><tr><td colspan=\"2\" align=\"center\">");
|
||||
client.println(link);
|
||||
client.println("</td></tr></table></body></html>");
|
||||
break;
|
||||
}
|
||||
if (c == '\n') {
|
||||
current_line_is_blank = true;
|
||||
} else if (c != '\r') {
|
||||
current_line_is_blank = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
delay(1);
|
||||
client.stop();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user