Arduino nano 33 IOT - WiFi 연결 (STA Mode)
Arduino

Arduino nano 33 IOT - WiFi 연결 (STA Mode)

Arduino nano 33 IOT - 개발환경 설정

https://rorsi.tistory.com/15

 

이제 Nano33 IoT보드에서 WiFi를 사용하기 위해서는 "WiFiNINA"라이브러리가 필요합니다.

라이브러리 관리에서 "WiFiNINA"라이브러리를 받아줍니다.

 

 

이제 WiFi에 접속하는 소스코드에 대해 알아보도록 하겠습니다.

 

nano33_IoT_WiFi.ino
0.00MB

#include <SPI.h>
#include <WiFiNINA.h>

const char* ssid = "Test";        // WiFi의 SSID
const char* pass = "12345678";     // WiFi의 비밀번호
int status = WL_IDLE_STATUS;

void setup() {
  Serial.begin(9600);
  while (!Serial) {;}
                  
  if (WiFi.status() == WL_NO_MODULE) {     //와이파이 모듈 체크
    Serial.println("Communication with WiFi module failed!");  
    while (true);
  }

  String fv = WiFi.firmwareVersion();      //버전 체크
  if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
    Serial.println("Please upgrade the firmware");
  }
  
  // 와이파이 연결시도(연결이 되어 있지 않을때만 실행)
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to WPA SSID: ");
    Serial.println(ssid);
    
    // Connect to WPA/WPA2 network:
    status = WiFi.begin(ssid, pass);
    
    // wait 10 seconds for connection:
    delay(10000);
  }

  Serial.println("You're connected to the network");
  printWifiStatus();
}

void loop() {     
}

void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your board'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");
}

 

위의 소스를 업로드 한 뒤 시리얼 모니터를 확인하면 아래 그림과 같이 접속을 확인할 수 있습니다.

 

보시는 바와 같이 연결하고자 하는 ssid를 표시하고 연결에 성공하면 "you're connected to the network" 라는 메시지를 띄워주고 와이파이의 상태정보를 출력해줍니다.

 

WiFi AP Mode 방법

https://rorsi.tistory.com/14