Advertisement
Guest User

Client

a guest
Jan 26th, 2020
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.58 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <WiFiNINA.h>
  3. #include <WiFiUdp.h>
  4.  
  5. char ssid[] = "SONNE";        // your network SSID (name)
  6. char pass[] = "PWD";    // your network password (use for WPA, or use as key for WEP)
  7. int status = WL_IDLE_STATUS;     // the Wifi radio's status
  8. WiFiUDP Udp;
  9. void setup() {
  10.   //Initialize serial and wait for port to open:
  11.   Serial.begin(9600);
  12.   while (!Serial) {
  13.     ; // wait for serial port to connect. Needed for native USB port only
  14.   }
  15.  
  16.   // check for the WiFi module:
  17.   if (WiFi.status() == WL_NO_MODULE) {
  18.     Serial.println("Communication with WiFi module failed!");
  19.     // don't continue
  20.     while (true);
  21.   }
  22.  
  23.   String fv = WiFi.firmwareVersion();
  24.   if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
  25.     Serial.println("Please upgrade the firmware");
  26.   }
  27.  
  28.   // attempt to connect to Wifi network:
  29.   while (status != WL_CONNECTED) {
  30.     Serial.print("Attempting to connect to WPA SSID: ");
  31.     Serial.println(ssid);
  32.     // Connect to WPA/WPA2 network:
  33.     status = WiFi.begin(ssid, pass);
  34.  
  35.     // wait 10 seconds for connection:
  36.     delay(10000);
  37.   }
  38.  
  39.   // you're connected now, so print out the data:
  40.   Serial.print("You're connected to the network");
  41.   printCurrentNet();
  42.   printWifiData();
  43.  
  44. }
  45.  
  46. void loop() {
  47.   // check the network connection once every 10 seconds:
  48.  
  49.   delay(10000);
  50.   printCurrentNet();
  51.      Udp.beginPacket((192,168,4,1), 80);
  52.     Udp.write("UDP sent Hello");
  53.     Udp.endPacket();
  54. }
  55.  
  56. void printWifiData() {
  57.   // print your board's IP address:
  58.   IPAddress ip = WiFi.localIP();
  59.   Serial.print("IP Address: ");
  60.   Serial.println(ip);
  61.   Serial.println(ip);
  62.  
  63.   // print your MAC address:
  64.   byte mac[6];
  65.   WiFi.macAddress(mac);
  66.   Serial.print("MAC address: ");
  67.   printMacAddress(mac);
  68. }
  69.  
  70. void printCurrentNet() {
  71.   // print the SSID of the network you're attached to:
  72.   Serial.print("SSID: ");
  73.   Serial.println(WiFi.SSID());
  74.  
  75.   // print the MAC address of the router you're attached to:
  76.   byte bssid[6];
  77.   WiFi.BSSID(bssid);
  78.   Serial.print("BSSID: ");
  79.   printMacAddress(bssid);
  80.  
  81.   // print the received signal strength:
  82.   long rssi = WiFi.RSSI();
  83.   Serial.print("signal strength (RSSI):");
  84.   Serial.println(rssi);
  85.  
  86.   // print the encryption type:
  87.   byte encryption = WiFi.encryptionType();
  88.   Serial.print("Encryption Type:");
  89.   Serial.println(encryption, HEX);
  90.   Serial.println();
  91. }
  92.  
  93. void printMacAddress(byte mac[]) {
  94.   for (int i = 5; i >= 0; i--) {
  95.     if (mac[i] < 16) {
  96.       Serial.print("0");
  97.     }
  98.     Serial.print(mac[i], HEX);
  99.     if (i > 0) {
  100.       Serial.print(":");
  101.     }
  102.   }
  103.   Serial.println();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement