본문 바로가기

프로그래밍/아두이노01- 제품개발

아두이노 wifi shield 개발 - 1. 개요



그림. 아두이노uno r3와 아두이노 와이파이 쉴드를 2층으로 쌓은모습.



그림. 아두이노 + 아두이노 와이파이 쉴드 2층으로 쌓아 연결한모습


기존의 아두이노의 단자를 그대로 사용할 수 있고 쉽게 연결 할 수 있다는 장점이 있습니다.


대신에 11,12,13포트는 아두이노와 아두이노 와이파이 쉴드를 연결하는 용도로 사용되기 때문에 사용을 하지 않는것을 권합니다.

(사실 사용이 안됨.)


===========================================================================



그리고 사실 와이파이 쉴드가 너무비싸서 사설 제품을 쓰는 경우가 있는데,


예를 들자면 




wifly shield 모델같은것.. 기존의 와이파이 쉴드가 13만원정도하지만, 이런건 더 싸다.


이런 사설(?) 모듈을 사용할 수도 있는데, 


스캐치에서 새로운 헤더파일같은것(라이브러리)를 추가해서 사용하는데




그냥 정품을 사용해서 쓰는걸 추천합니다. 왜냐하면 정품을 쓰게되면 새로운 라이브러리를 굳이 사용하지않아도 되구


기존의 라이브러리를 쓰면서 개발도 가능하므로,, (거기에 정품라이브러리는 웹에 소스가 많기 때문에 코딩, 개발하기도 참 좋다.)


돈이 없다면 할수없고.. 싼거 사서 써야져 ㅋㅋ




===========================================================================


<중요!> 와이파이 쉴드를 사용할때 반드시 wifi shield를 펌웨어 업그레이드 하고 시작하시는게 좋습니다.


현재 아두이노 최신버전은 

The firmware for the WiFi shield has changed in Arduino IDE 1.1.0


이므로 반드시 1.1.0로 업글하고 시작해야지 ,펌웨어 업뎃을 하지 않으면 http접속이 제대로 먹지 않아서


제대로 된 테스트 값을 읽을 수가 없으므로 반드시 하자!


펌웨어 하는 법은 아래 블로그와 아두이노 공식 홈페이지에 나와있다.


블로그(for MAC) : http://gbox3d.tistory.com/85

아두이노 와이파이 쉴드 펌웨어 공식홈페이지 : http://arduino.cc/en/Hacking/WiFiShieldFirmwareUpgrading



===========================================================================


#include <SPI.h>

#include <WiFi.h>


char ssid[] = "belkin.E33";      //  your network SSID (name) 

char pass[] = "abc123cde456";   // your network password

int keyIndex = 0;                 // your network key Index number (needed only for WEP)


int status = WL_IDLE_STATUS;

WiFiServer server(80);


void setup() {

  Serial.begin(9600);      // initialize serial communication


  // check for the presence of the shield:

  if (WiFi.status() == WL_NO_SHIELD) {

  Serial.println("WiFi shield not present"); 

   while(true);        // don't continue

   } 


 // check for the presence of the shield:

  if (WiFi.status() == WL_NO_SHIELD) {

    Serial.println(F("WiFi shield not present")); 

    // don't continue:

    while(true);

  } 


  // check firmware version

  Serial.print(F("Firmware version: "));

  Serial.println(WiFi.firmwareVersion());


   // attempt to connect to Wifi network:

  while ( status != WL_CONNECTED) { 

    Serial.print("Attempting to connect to Network named: ");

    Serial.println(ssid);                   // print the network name (SSID);


    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:    

     status = WiFi.begin(ssid, pass);

     // wait 10 seconds for connection:

     delay(10000);

   } 

  server.begin();                           // start the web server on port 80

  printWifiStatus();        // you're connected now, so print out the        status

}



void loop() {



  WiFiClient client = server.available();   // listen for incoming clients


  if (client) {                             // if you get a client,

    Serial.println("new client");           // print a message out the serial port

    String currentLine = "";      // make a String to hold incoming data from the client

    while (client.connected()) {            // loop while the client's connected

     if (client.available()) {             // if there's bytes to read from the client,

     char c = client.read();             // read a byte, then

     Serial.write(c);                    // print it out the serial monitor

     if (c == '\n') {                    // if the byte is a newline character


      // if the current line is blank, you got two newline characters in a row.

      // that's the end of the client HTTP request, so send a response:

      if (currentLine.length() == 0) {  

        // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)

        // and a content-type so the client knows what's coming, then a blank line:    

        client.println("HTTP/1.1 200 OK");

        client.println("Content-type:text/html");

        client.println();


        // the content of the HTTP response follows the header:

        client.print("Click <a href=\"/H\">here</a> turn the LED on pin 9 on<br>");

        client.print("Click <a href=\"/L\">here</a> turn the LED on pin 9 off<br>");


        // The HTTP response ends with another blank line:

        client.println();

        // break out of the while loop:

        break;         

       } 

       else {      // if you got a newline, then clear currentLine:

         currentLine = "";

       }

     }     

     else if (c != '\r') {  // if you got anything else but a carriage return character,

      currentLine += c;      // add it to the end of the currentLine

    }


    // Check to see if the client request was "GET /H" or "GET /L":

    if (currentLine.endsWith("GET /H")) {

    }

    if (currentLine.endsWith("GET /L")) {

     }

   }

 }

// close the connection:

client.stop();

Serial.println("client disonnected");

  }

}


void printWifiStatus() {

  // print the SSID of the network you're attached to:

  Serial.print("SSID: ");

 Serial.println(WiFi.SSID());


 // print your WiFi shield's IP address:

 IPAddress ip = WiFi.localIP();

 Serial.print("IP Address: ");

 Serial.println(ip);


 // print the received signal strength:

 long rssi = WiFi.RSSI();

 Serial.print("signal strength (RSSI):");

 Serial.print(rssi);

 Serial.println(" dBm");

// print where to go in a browser:

Serial.print("To see this page in action, open a browser to http://");

Serial.println(ip);

 }



===========================================================================


위 코드는 arduino uno r3 모델과 arduino wifi shield를 결합하여 코딩한 경우,


아두이노 와이파이 쉴드 펌웨어를 확인 하기 위한 코드이다.


위 코드를 사용하게 되면  빨강색 부분에 의해서 펌웨어 버전이 나타나는데


이것이 1.0.4 이하 버젼이라면 반드시!!! 펌웨어 업그레이드를 할것!!