본문 바로가기

Nordic/nRF52

[nRF52 xBee EVM] Arduino SPI 테스트 - W5500 Ethernet Webserver

[nRF52 xBee EVM]보드를 이용하여 SPI 테스트를 하기위해 이더넷 모듈은 W5500 EVM보드를 이용하여 테스트 해 보았다.

 

W5500 EVM 모듈의 CS핀은 IO27에 연결되어 있다.

 

이더넷 모듈의 라이브러리는 Ethernet2를 사용하였다.

 

 

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  Serial.print("server is at ");
  // start the Ethernet connection and the server:
  Ethernet.w5500_cspin = 27;

  Ethernet.begin(mac, ip);
  server.begin();
  
  Serial.println(Ethernet.localIP());
}

 

 

이더넷 웹서버를 이용해서 [nRF52 xBee EVM] Arduino 테스트 - 내장 온도 측정하기를 이용하여 웹페이지에 온도값을 출력 하는 예제를 작성해 보았다.

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("<!DOCTYPE HTML>");
          client.println("<html><center>");

          client.print("<h1>");
          client.print("nRF52x Temperature : ");

          int sensorReading = get_temperature();
          client.print(sensorReading);

          client.println("<br /></center></h1>");

          /*
          // 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 disconnected");
  }
}

 

 

nRF52와 W5500 모듈을 이용하여 웹서버 구현 예제

반응형