├── .gitattributes ├── .gitignore ├── AJAX └── AJAX.ino ├── sd_card ├── index.htm └── sd_card.ino ├── sd_card_with_AJAX ├── index.htm └── sd_card_with_AJAX.ino └── vanilla └── vanilla.ino /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | -------------------------------------------------------------------------------- /AJAX/AJAX.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Web Server - AJAX 3 | 4 | A simple web server that shows the value of the analog input pins. 5 | using an Arduino Wiznet Ethernet shield. This example introduces 6 | using AJAX to both update the analog pins and control a 7 | LED. 8 | 9 | Circuit: 10 | Ethernet shield attached to pins 10, 11, 12, 13 11 | 12 | Last Modified: 27/11/2016 13 | 14 | Author: Gus @ ArduinoMyLifeUp.com 15 | --------------------------------------------------------------*/ 16 | 17 | #include 18 | #include 19 | 20 | // Enter a MAC address and IP address for your controller below. 21 | // The IP address will be dependent on your local network: 22 | byte mac[] = { 23 | 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED 24 | }; 25 | IPAddress ip(192, 168, 1, 177); 26 | 27 | // Initialize the Ethernet server library 28 | // with the IP address and port you want to use 29 | // (port 80 is default for HTTP): 30 | EthernetServer server(80); 31 | 32 | //LED to turn on/off 33 | int RED = 8; 34 | String HTTP_req; // stores the HTTP request 35 | 36 | void setup() { 37 | // Open serial communications and wait for port to open: 38 | Serial.begin(9600); 39 | while (!Serial) { 40 | ; // wait for serial port to connect. Needed for native USB port only 41 | } 42 | 43 | 44 | // start the Ethernet connection and the server: 45 | Ethernet.begin(mac, ip); 46 | server.begin(); 47 | Serial.print("server is at "); 48 | Serial.println(Ethernet.localIP()); 49 | HTTP_req = ""; 50 | //Set LED to output 51 | pinMode(RED, OUTPUT); 52 | } 53 | 54 | void loop() { 55 | // listen for incoming clients 56 | EthernetClient client = server.available(); 57 | if (client) { 58 | Serial.println("new client"); 59 | // an http request ends with a blank line 60 | boolean currentLineIsBlank = true; 61 | while (client.connected()) { 62 | if (client.available()) { 63 | char c = client.read(); 64 | if( HTTP_req.length() < 120) 65 | HTTP_req += c; // save the HTTP request 1 char at a time 66 | Serial.write(c); 67 | // if you've gotten to the end of the line (received a newline 68 | // character) and the line is blank, the http request has ended, 69 | // so you can send a reply 70 | if (c == '\n' && currentLineIsBlank) { 71 | // send a standard http response header 72 | client.println("HTTP/1.1 200 OK"); 73 | client.println("Content-Type: text/html"); 74 | client.println("Connection: close"); // the connection will be closed after completion of the response 75 | client.println(); 76 | Serial.println(HTTP_req); 77 | if (HTTP_req.indexOf("ajaxrefresh") >= 0 ) { 78 | // read switch state and analog input 79 | ajaxRequest(client); 80 | break; 81 | } 82 | else if (HTTP_req.indexOf("ledstatus") >= 0 ) { 83 | // read switch state and analog input 84 | ledChangeStatus(client); 85 | break; 86 | } 87 | else { 88 | client.println(""); 89 | client.println(""); 90 | client.println(""); 119 | // output the value of each analog input pin 120 | client.print("

Analogue Values

"); 121 | client.println("
Arduino analog input values loading.....
"); 122 | client.println("

Arduino LED Status

"); 123 | client.println("
"); 124 | if(digitalRead(RED) == 1) 125 | client.println("On"); 126 | else 127 | client.println("Off"); 128 | client.println(" |
"); 129 | client.println(""); 130 | break; 131 | } 132 | } 133 | if (c == '\n') { 134 | // you're starting a new line 135 | currentLineIsBlank = true; 136 | } else if (c != '\r') { 137 | // you've gotten a character on the current line 138 | currentLineIsBlank = false; 139 | } 140 | } 141 | } 142 | // give the web browser time to receive the data 143 | delay(1); 144 | // close the connection: 145 | client.stop(); 146 | HTTP_req = ""; 147 | Serial.println("client disconnected"); 148 | } 149 | } 150 | 151 | // send the state of the switch to the web browser 152 | void ajaxRequest(EthernetClient client) 153 | { 154 | for (int analogChannel = 0; analogChannel < 6; analogChannel++) { 155 | int sensorReading = analogRead(analogChannel); 156 | client.print("analog input "); 157 | client.print(analogChannel); 158 | client.print(" is "); 159 | client.print(sensorReading); 160 | client.println("
"); 161 | } 162 | } 163 | 164 | 165 | void ledChangeStatus(EthernetClient client) 166 | { 167 | int state = digitalRead(RED); 168 | Serial.println(state); 169 | if (state == 1) { 170 | digitalWrite(RED, LOW); 171 | client.print("OFF"); 172 | } 173 | else { 174 | digitalWrite(RED, HIGH); 175 | client.print("ON"); 176 | } 177 | } 178 | 179 | -------------------------------------------------------------------------------- /sd_card/index.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 |

SD Card Webpage

4 |

This page has been loaded off the SD Card :O

5 | 6 | -------------------------------------------------------------------------------- /sd_card/sd_card.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Web Server - SD Card 3 | 4 | A simple web server that shows the value of the analog input pins. 5 | using an Arduino Wiznet Ethernet shield. 6 | 7 | Circuit: 8 | * Ethernet shield attached to pins 10, 11, 12, 13 9 | 10 | Last Modified: 27/11/2016 11 | 12 | Author: Gus @ ArduinoMyLifeUp.com 13 | --------------------------------------------------------------*/ 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | 20 | // Enter a MAC address and IP address for your controller below. 21 | // The IP address will be dependent on your local network: 22 | byte mac[] = { 23 | 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED 24 | }; 25 | IPAddress ip(192, 168, 1, 177); 26 | 27 | // Initialize the Ethernet server library 28 | // (port 80 is default for HTTP): 29 | EthernetServer server(80); 30 | 31 | File webPage; 32 | 33 | void setup() 34 | { 35 | Ethernet.begin(mac, ip); // initialize Ethernet device 36 | server.begin(); // start to listen for clients 37 | Serial.begin(9600); // for debugging 38 | 39 | // initialize SD card 40 | Serial.println("Checking SD card is accessible..."); 41 | if (!SD.begin(4)) { 42 | Serial.println("ERROR - SD card initialization failed!"); 43 | return; // init failed 44 | } 45 | Serial.println("SUCCESS - SD card initialized."); 46 | } 47 | 48 | void loop() 49 | { 50 | // listen for incoming clients 51 | EthernetClient client = server.available(); 52 | if (client) { 53 | Serial.println("new client"); 54 | // an http request ends with a blank line 55 | boolean currentLineIsBlank = true; 56 | while (client.connected()) { 57 | if (client.available()) { 58 | char c = client.read(); // read 1 byte (character) from client 59 | // if you've gotten to the end of the line (received a newline 60 | // character) and the line is blank, the http request has ended, 61 | // so you can send a reply 62 | if (c == '\n' && currentLineIsBlank) { 63 | // send a standard http response header 64 | client.println("HTTP/1.1 200 OK"); 65 | client.println("Content-Type: text/html"); 66 | client.println("Connection: close"); 67 | client.println(); 68 | // send web page 69 | webPage = SD.open("index.htm"); // open web page file 70 | if (webPage) { 71 | Serial.println("IF"); 72 | while (webPage.available()) { 73 | client.write(webPage.read()); // send web page to client 74 | } 75 | webPage.close(); 76 | } 77 | break; 78 | } 79 | if (c == '\n') { 80 | // you're starting a new line 81 | currentLineIsBlank = true; 82 | } else if (c != '\r') { 83 | // you've gotten a character on the current line 84 | currentLineIsBlank = false; 85 | } 86 | } 87 | } 88 | // give the web browser time to receive the data 89 | delay(1); 90 | // close the connection: 91 | client.stop(); 92 | Serial.println("client disconnected"); 93 | } // end if (client) 94 | } 95 | -------------------------------------------------------------------------------- /sd_card_with_AJAX/index.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 28 |

Analogue Values

Arduino analog input values loading.....
29 |

Arduino LED Status

30 |
31 | Off 32 | |
33 | 34 | -------------------------------------------------------------------------------- /sd_card_with_AJAX/sd_card_with_AJAX.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Web Server - SD Card 3 | 4 | A simple web server that shows the value of the analog input pins. 5 | using an Arduino Wiznet Ethernet shield. Also makes use of AJAX 6 | to keep elements updated on the webpage. 7 | 8 | Circuit: 9 | Ethernet shield attached to pins 10, 11, 12, 13 10 | LED connected to pin 8 and GND 11 | 12 | Last Modified: 27/11/2016 13 | 14 | Author: Gus @ ArduinoMyLifeUp.com 15 | --------------------------------------------------------------*/ 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | 22 | // Enter a MAC address and IP address for your controller below. 23 | // The IP address will be dependent on your local network: 24 | byte mac[] = { 25 | 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED 26 | }; 27 | IPAddress ip(192, 168, 1, 177); 28 | 29 | // Initialize the Ethernet server library 30 | // (port 80 is default for HTTP): 31 | EthernetServer server(80); 32 | 33 | File webPage; 34 | int RED = 8; //LED to turn on/off 35 | String HTTP_req; // stores the HTTP request 36 | 37 | void setup() 38 | { 39 | Ethernet.begin(mac, ip); // initialize Ethernet device 40 | server.begin(); // start to listen for clients 41 | Serial.begin(9600); // for debugging 42 | while (!Serial) { 43 | ; // wait for serial port to connect. Needed for native USB port only 44 | } 45 | // initialize SD card 46 | Serial.println("Checking SD card is accessible..."); 47 | if (!SD.begin(4)) { 48 | Serial.println("ERROR - SD card initialization failed!"); 49 | return; // init failed 50 | } 51 | Serial.println("SUCCESS - SD card initialized."); 52 | HTTP_req = ""; 53 | //Set LED to output 54 | pinMode(RED, OUTPUT); 55 | } 56 | 57 | void loop() 58 | { 59 | // listen for incoming clients 60 | EthernetClient client = server.available(); 61 | if (client) { 62 | Serial.println("new client"); 63 | // an http request ends with a blank line 64 | boolean currentLineIsBlank = true; 65 | while (client.connected()) { 66 | if (client.available()) { 67 | char c = client.read(); // read 1 byte (character) from client 68 | // if you've gotten to the end of the line (received a newline 69 | // character) and the line is blank, the http request has ended, 70 | // so you can send a reply 71 | if ( HTTP_req.length() < 80) 72 | HTTP_req += c; // save the HTTP request 1 char at a time 73 | if (c == '\n' && currentLineIsBlank) { 74 | // send a standard http response header 75 | client.println("HTTP/1.1 200 OK"); 76 | client.println("Content-Type: text/html"); 77 | client.println("Connection: close"); 78 | client.println(); 79 | // send web page 80 | if (HTTP_req.indexOf("ajaxrefresh") >= 0 ) { 81 | ajaxRequest(client); //update the analog values 82 | break; 83 | } 84 | else if (HTTP_req.indexOf("ledstatus") >= 0 ) { 85 | ledChangeStatus(client); //change the LED state 86 | break; 87 | } 88 | else { 89 | webPage = SD.open("index.htm"); // open web page file 90 | if (webPage) { 91 | while (webPage.available()) { 92 | client.write(webPage.read()); // send web page to client 93 | } 94 | webPage.close(); 95 | } 96 | break; 97 | } 98 | if (c == '\n') { 99 | // you're starting a new line 100 | currentLineIsBlank = true; 101 | } else if (c != '\r') { 102 | // you've gotten a character on the current line 103 | currentLineIsBlank = false; 104 | } 105 | } 106 | } 107 | } 108 | // give the web browser time to receive the data 109 | delay(1); 110 | // close the connection: 111 | client.stop(); 112 | HTTP_req = ""; 113 | Serial.println("client disconnected"); 114 | } // end if (client) 115 | } 116 | 117 | // send the state of the switch to the web browser 118 | void ajaxRequest(EthernetClient client) 119 | { 120 | for (int analogChannel = 0; analogChannel < 6; analogChannel++) { 121 | int sensorReading = analogRead(analogChannel); 122 | client.print("analog input "); 123 | client.print(analogChannel); 124 | client.print(" is "); 125 | client.print(sensorReading); 126 | client.println("
"); 127 | } 128 | } 129 | 130 | void ledChangeStatus(EthernetClient client) 131 | { 132 | int state = digitalRead(RED); 133 | Serial.println(state); 134 | if (state == 1) { 135 | digitalWrite(RED, LOW); 136 | client.print("OFF"); 137 | } 138 | else { 139 | digitalWrite(RED, HIGH); 140 | client.print("ON"); 141 | } 142 | } 143 | 144 | 145 | -------------------------------------------------------------------------------- /vanilla/vanilla.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Web Server - Vanilla 3 | 4 | A simple web server that shows the value of the analog input pins. 5 | using an Arduino Wiznet Ethernet shield. This example introduces 6 | using AJAX to both update the analog pins and control a 7 | LED. 8 | 9 | Circuit: 10 | * Ethernet shield attached to pins 10, 11, 12, 13 11 | 12 | Last Modified: 27/11/2016 13 | 14 | Author: Gus @ ArduinoMyLifeUp.com 15 | --------------------------------------------------------------*/ 16 | 17 | #include 18 | #include 19 | 20 | // Enter a MAC address and IP address for your controller below. 21 | // The IP address will be dependent on your local network: 22 | byte mac[] = { 23 | 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED 24 | }; 25 | IPAddress ip(192, 168, 1, 177); 26 | 27 | // Initialize the Ethernet server library 28 | // with the IP address and port you want to use 29 | // (port 80 is default for HTTP): 30 | EthernetServer server(80); 31 | 32 | void setup() { 33 | // Open serial communications and wait for port to open: 34 | Serial.begin(9600); 35 | while (!Serial) { 36 | ; // wait for serial port to connect. Needed for native USB port only 37 | } 38 | 39 | 40 | // start the Ethernet connection and the server: 41 | Ethernet.begin(mac, ip); 42 | server.begin(); 43 | Serial.print("server is at "); 44 | Serial.println(Ethernet.localIP()); 45 | } 46 | 47 | 48 | void loop() { 49 | // listen for incoming clients 50 | EthernetClient client = server.available(); 51 | if (client) { 52 | Serial.println("new client"); 53 | // an http request ends with a blank line 54 | boolean currentLineIsBlank = true; 55 | while (client.connected()) { 56 | if (client.available()) { 57 | char c = client.read(); 58 | Serial.write(c); 59 | // if you've gotten to the end of the line (received a newline 60 | // character) and the line is blank, the http request has ended, 61 | // so you can send a reply 62 | if (c == '\n' && currentLineIsBlank) { 63 | // send a standard http response header 64 | client.println("HTTP/1.1 200 OK"); 65 | client.println("Content-Type: text/html"); 66 | client.println("Connection: close"); // the connection will be closed after completion of the response 67 | client.println("Refresh: 5"); // refresh the page automatically every 5 sec 68 | client.println(); 69 | client.println(""); 70 | client.println(""); 71 | // output the value of each analog input pin 72 | client.print("

Analogue Values

"); 73 | for (int analogChannel = 0; analogChannel < 6; analogChannel++) { 74 | int sensorReading = analogRead(analogChannel); 75 | client.print("analog input "); 76 | client.print(analogChannel); 77 | client.print(" is "); 78 | client.print(sensorReading); 79 | client.println("
"); 80 | } 81 | client.println(""); 82 | break; 83 | } 84 | if (c == '\n') { 85 | // you're starting a new line 86 | currentLineIsBlank = true; 87 | } else if (c != '\r') { 88 | // you've gotten a character on the current line 89 | currentLineIsBlank = false; 90 | } 91 | } 92 | } 93 | // give the web browser time to receive the data 94 | delay(1); 95 | // close the connection: 96 | client.stop(); 97 | Serial.println("client disconnected"); 98 | } 99 | } 100 | --------------------------------------------------------------------------------