Advertisement
Guest User

Untitled

a guest
Jun 13th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. /*
  2.  
  3. This example connects to an unencrypted Wifi network.
  4. Then it prints the MAC address of the Wifi shield,
  5. the IP address obtained, and other network details.
  6.  
  7. Circuit:
  8. * WiFi shield attached
  9.  
  10. created 13 July 2010
  11. by dlf (Metodo2 srl)
  12. modified 31 May 2012
  13. by Tom Igoe
  14. */
  15. #include <WiFi.h>
  16.  
  17. char ssid[] = "Omega"; // your network SSID (name)
  18. char pass[] = "12345678"; // your network password
  19. int status = WL_IDLE_STATUS; // the Wifi radio's status
  20.  
  21. void setup() {
  22. //Initialize serial and wait for port to open:
  23. Serial.begin(9600);
  24. while (!Serial) {
  25. ; // wait for serial port to connect. Needed for Leonardo only
  26. }
  27.  
  28. // check for the presence of the shield:
  29. if (WiFi.status() == WL_NO_SHIELD) {
  30. Serial.println("WiFi shield not present");
  31. // don't continue:
  32. while(true);
  33. }
  34.  
  35. // attempt to connect to Wifi network:
  36. while ( status != WL_CONNECTED) {
  37. Serial.print("Attempting to connect to WPA SSID: ");
  38. Serial.println(ssid);
  39. // Connect to WPA/WPA2 network:
  40. status = WiFi.begin(ssid, pass);
  41.  
  42. // wait 10 seconds for connection:
  43. delay(10000);
  44. }
  45.  
  46. // you're connected now, so print out the data:
  47. Serial.print("You're connected to the network");
  48. printCurrentNet();
  49. printWifiData();
  50.  
  51. }
  52.  
  53. void loop() {
  54. // check the network connection once every 10 seconds:
  55. delay(10000);
  56. printCurrentNet();
  57. }
  58.  
  59. void printWifiData() {
  60. // print your WiFi shield's IP address:
  61. IPAddress ip = WiFi.localIP();
  62. Serial.print("IP Address: ");
  63. Serial.println(ip);
  64. Serial.println(ip);
  65.  
  66. // print your MAC address:
  67. byte mac[6];
  68. WiFi.macAddress(mac);
  69. Serial.print("MAC address: ");
  70. Serial.print(mac[5],HEX);
  71. Serial.print(":");
  72. Serial.print(mac[4],HEX);
  73. Serial.print(":");
  74. Serial.print(mac[3],HEX);
  75. Serial.print(":");
  76. Serial.print(mac[2],HEX);
  77. Serial.print(":");
  78. Serial.print(mac[1],HEX);
  79. Serial.print(":");
  80. Serial.println(mac[0],HEX);
  81.  
  82. }
  83.  
  84. void printCurrentNet() {
  85. // print the SSID of the network you're attached to:
  86. Serial.print("SSID: ");
  87. Serial.println(WiFi.SSID());
  88.  
  89. // print the MAC address of the router you're attached to:
  90. byte bssid[6];
  91. WiFi.BSSID(bssid);
  92. Serial.print("BSSID: ");
  93. Serial.print(bssid[5],HEX);
  94. Serial.print(":");
  95. Serial.print(bssid[4],HEX);
  96. Serial.print(":");
  97. Serial.print(bssid[3],HEX);
  98. Serial.print(":");
  99. Serial.print(bssid[2],HEX);
  100. Serial.print(":");
  101. Serial.print(bssid[1],HEX);
  102. Serial.print(":");
  103. Serial.println(bssid[0],HEX);
  104.  
  105. // print the received signal strength:
  106. long rssi = WiFi.RSSI();
  107. Serial.print("signal strength (RSSI):");
  108. Serial.println(rssi);
  109.  
  110. // print the encryption type:
  111. byte encryption = WiFi.encryptionType();
  112. Serial.print("Encryption Type:");
  113. Serial.println(encryption,HEX);
  114. Serial.println();
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement