Home
ProgramLanguage
DataBase
Err Window Line MEGA SEO IDE Media Google UnixTimestamp Virus
Office
OperatingSystem
MultimediaDesign
Adobe
Photoshop
Illustrator
Corel
DRAW
Painter
PaintShop
會聲會影
Pinta
GIMP
Krita Desktop
Inkscape
Arduino
W5100
SPI預設使用腳位10, 11, 12, 13
SD 記憶哪使用腳位4

/*
  Web Server

 A simple web server that shows the value of the analog input pins.
 using an Arduino Wiznet Ethernet shield.

 Circuit:
 * Ethernet shield attached to pins 10, 11, 12, 13
 * Analog inputs attached to pins A0 through A5 (optional)

 created 18 Dec 2009
 by David A. Mellis
 modified 9 Apr 2012
 by Tom Igoe

 */

#include 
#include 

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip(192, 168, X, XXX);
IPAddress dnServer(168, 95, 1, 1);
IPAddress gateway(192, 168, X, X);
IPAddress subnet(255, 255, 255, 0);
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);

void setup() {
  // 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);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
}


void loop() {
  // listen for incoming clients
  //監聽客戶端的傳入
  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    // 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("");
          client.println("");
          // 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("
"); } client.println(""); 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 disconnected"); } } PWR: 表示 Arduino 控制板和 Ethernet Shield 已經上電 LINK: 網路指示燈,當燈號閃爍時代表正在傳送或接收資料 FULLD: 代表網路連線是全雙工 100M: 表示網路是 100 MB/s (相對於 10 Mb/s) RX: 接收資料時閃爍 TX: 傳送資料時閃爍 COLL: 閃爍時代表網路上發生封包碰撞的情形 (network collisions are detected) http://coopermaa2nd.blogspot.tw/2013/09/arduino-ethernet-shield.html http://www.techbang.com/posts/25109-future-of-humanity-through-network-monitoring-internet-home-brightness http://blogger.gtwang.org/2015/02/arduino-ethernet-shield-w5100-dhcp-ip-address.html https://www.arduino.cc/en/Main/ArduinoEthernetShield http://goods.ruten.com.tw/item/show?21304018050149 http://wiznet2012.blogspot.tw/2012/03/arduinoshield.html http://wiznethk.pixnet.net/blog/post/344710378-arduino-ethernet%E5%85%A5%E9%96%80%E2%80%94%E2%80%94%E6%A7%8B%E5%BB%BA%E7%B0%A1%E6%98%93%E7%9A%84web-server%E6%95%99%E7%A8%8B 乙太網供電(Power over Ethernet,簡稱POE)也稱PoE供電,是一種可以在乙太網路中透過雙絞線來傳輸電力與資料到裝置上的技術。 由於能藉由乙太網路獲得供電的電子裝置無需額外的電源插座就可使用,所以同時能省去配置電源線的時間與金錢,使整個裝置系統的成本相對降低。 目前全球均普遍採用RJ-45網路插座,因此各種PoE裝置都具備相容性。 PoE又分為供電端(Power Sourcing Equipment,簡稱PSE)和受電端(Powered Device,簡稱PD)。還有AT和AF的差別。 原始的IEEE 802.3af-2003標準提供了一台機器15.4W DC功率的保證(最小值可為44V DC與350mA)。但其中穩定功率只有12.95W,這是由於雙絞線中存在有電力損耗。 經過改良的IEEE 802.3at-2009 PoE標準,也就是PoE+,可以為裝置提供高達25.5W的電功率。此2009年的標準不允許裝置將4對線纜全部用作供電。一些廠商已經宣布的產品指標中包含了聲稱相容802.3at的標準之產品。它們(被聲稱)能夠實現51W的高功率。這些產品通過一根主供電線纜配合全部四組其他從線纜進行供電。這些線纜均為5類雙絞線(CAT-5) PoE也有競爭者,即USB(Universal Serial Bus)技術,同樣同時提供資料和電能。但這個標準是為小距離應用(上限為5米,即16英尺)而設計的,獨立供電功率低於2.5W。它比PoE更加廉價,也能同小功率外圍裝置完美配合,例如你的PC滑鼠、耳機和集線器。然而,一些外圍裝置如揚聲器、掃描儀和印表機需要的電能無法籍由USB提供。火線,即Firewire(IEEE1394)很像USB,卻可以提供明顯多於其的電量。(火線提供45W的電功率)然而火線的距離限制為4.5m,甚至近於USB。 有許多不同的名詞都是意指這個功能。Power over Ethernet (PoE)、Power over LAN (PoL), Power on LAN (PoL),以及Inline Power,都是指由乙太網路孔供電給各種裝置的技術。 PoE有許多實做的方式,包括ad-hoc的方法,但是建議使用IEEE的標準來實做由網路線供電的技術。 IEEE 802.3AF[編輯] PSE提供44~57V的電壓,約350mA的直流電源,每一埠至少要可提供15.4W的功率,而經過100米CAT-3的電纜線後,PD端可收到的瓦特數至少要有12.95W。 IEEE 802.3AT[編輯] PSE端提供50~57V的電壓,約600mA的直流電源,每一埠至少要可提供30W的功率,而經過100米CAT-5的電纜線後,PD端可收到的瓦特數至少要有25.5W。 暫存CODE /* Web Server A simple web server that shows the value of the analog input pins. using an Arduino Wiznet Ethernet shield. Circuit: * Ethernet shield attached to pins 10, 11, 12, 13 * Analog inputs attached to pins A0 through A5 (optional) created 18 Dec 2009 by David A. Mellis modified 9 Apr 2012 by Tom Igoe */ #include #include // Enter a MAC address and IP address for your controller below. // The IP address will be dependent on your local network: byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; IPAddress ip(192, 168, 137, 2); IPAddress dnServer(168, 95, 1, 1); IPAddress gateway(192, 168, 137, 255); IPAddress subnet(255, 255, 255, 0); // Initialize the Ethernet server library // with the IP address and port you want to use // (port 80 is default for HTTP): EthernetServer server(80); String readString= "" ; void setup() { pinMode(2, OUTPUT); // 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); server.begin(); Serial.print("server is at "); Serial.println(Ethernet.localIP()); } void loop() { // listen for incoming clients EthernetClient client = server.available(); if (client) { Serial.println("new client"); // an http request ends with a blank line boolean currentLineIsBlank = true; while (client.connected()) { if (client.available()) { char c = client.read(); readString += c; 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(""); client.println(""); // 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("
"); } /* digitalWrite(2, HIGH); client.print(analogRead(2)); delay(1000); client.println("
"); digitalWrite(2, LOW); delay(500); client.print(analogRead(2)); */ client.println("
"); client.print(Ethernet.localIP()); client.println(""); break; } if (c == '\n') { Serial.println(readString); if (readString.indexOf( "?on" ) >0) { digitalWrite(2, HIGH); Serial.println( "Led On" ); } if (readString.indexOf( "?off" ) >0) { digitalWrite(2, LOW); Serial.println( "Led Off" ); } // 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 disconnected"); } } void showpage(){ } /* Web Server A simple web server that shows the value of the analog input pins. using an Arduino Wiznet Ethernet shield. Circuit: * Ethernet shield attached to pins 10, 11, 12, 13 * Analog inputs attached to pins A0 through A5 (optional) created 18 Dec 2009 by David A. Mellis modified 9 Apr 2012 by Tom Igoe */ #include #include // Enter a MAC address and IP address for your controller below. // The IP address will be dependent on your local network: byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; IPAddress ip(192, 168, 137, 2); IPAddress dnServer(168, 95, 1, 1); IPAddress gateway(192, 168, 137, 255); IPAddress subnet(255, 255, 255, 0); // Initialize the Ethernet server library // with the IP address and port you want to use // (port 80 is default for HTTP): EthernetServer server(80); String readString= "" ; void setup() { pinMode(2, OUTPUT); // 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); server.begin(); Serial.print("server is at "); Serial.println(Ethernet.localIP()); } void loop() { // listen for incoming clients EthernetClient client = server.available(); if (client) { Serial.println("new client"); // an http request ends with a blank line boolean currentLineIsBlank = true; while (client.connected()) { if (client.available()) { char c = client.read(); readString += c; 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(""); client.println(""); // 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("
"); } /* digitalWrite(2, HIGH); client.print(analogRead(2)); delay(1000); client.println("
"); digitalWrite(2, LOW); delay(500); client.print(analogRead(2)); */ //client.println("
"); //client.print(Ethernet.localIP()); client.println(""); break; } if (c == '\n') { Serial.println(readString); if (readString.indexOf( "?on" ) >0) { digitalWrite(2, HIGH); Serial.println( "Led On" ); } if (readString.indexOf( "?off" ) >0) { digitalWrite(2, LOW); Serial.println( "Led Off" ); } // 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 disconnected"); } } void showpage(){ } Arduino (五) 網路模組 https://chtseng.wordpress.com/2015/09/24/arduino-%E4%BA%94/ Arduino網路遠端遙控家電開關(二)http://swf.com.tw/?p=634 [arduino] 電腦透過php控制arduino http://blog.davidou.org/archives/718 Arduino Ethernet中文介绍 http://www.arduino.cn/thread-8384-1-1.html
| 關於我們 | 聯絡我們 | 更新記錄 |
版權所有 轉載必究 服務專線: