Guest User

Untitled

a guest
Sep 20th, 2018
83
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. WiFiEsp example: ConnectWPA
  3.  
  4. This example connects to an encrypted WiFi network using an ESP8266 module.
  5. Then it prints the MAC address of the WiFi shield, the IP address obtained
  6. and other network details.
  7. For more details see: http://yaab-arduino.blogspot.com/p/wifiesp-example-connect.html
  8. */
  9.  
  10. #include <WiFiEsp.h>
  11. #include <WiFiUdp.h>
  12.  
  13.  
  14. #include "AppleMidi.h"
  15. APPLEMIDI_CREATE_INSTANCE(WiFiUDP, appleMIDI1);
  16.  
  17.  
  18.  
  19. char ssid[] = "Rinaldo"; // your network SSID (name)
  20. char pass[] = "gakadapassword"; // your network password
  21. int status = WL_IDLE_STATUS; // the Wifi radio's status
  22.  
  23.  
  24.  
  25. void setup()
  26. {
  27. // initialize serial for debugging
  28. Serial.begin(115200);
  29. // initialize serial for ESP module
  30. Serial3.begin(115200);
  31. // initialize ESP module
  32. WiFi.init(&Serial3);
  33.  
  34. // check for the presence of the shield
  35. if (WiFi.status() == WL_NO_SHIELD) {
  36. Serial.println("WiFi shield not present");
  37. // don't continue
  38. while (true);
  39. }
  40.  
  41. // attempt to connect to WiFi network
  42. while ( status != WL_CONNECTED) {
  43. Serial.print("Attempting to connect to WPA SSID: ");
  44. Serial.println(ssid);
  45. // Connect to WPA/WPA2 network
  46. status = WiFi.begin(ssid, pass);
  47. }
  48.  
  49. Serial.println("You're connected to the network");
  50. }
  51.  
  52. void loop()
  53. {
  54. // print the network connection information every 10 seconds
  55. Serial.println();
  56. printCurrentNet();
  57. printWifiData();
  58.  
  59. delay(10000);
  60. }
  61.  
  62. void printWifiData()
  63. {
  64. // print your WiFi shield's IP address
  65. IPAddress ip = WiFi.localIP();
  66. Serial.print("IP Address: ");
  67. Serial.println(ip);
  68.  
  69. // print your MAC address
  70. byte mac[6];
  71. WiFi.macAddress(mac);
  72. char buf[20];
  73. sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X", mac[5], mac[4], mac[3], mac[2], mac[1], mac[0]);
  74. Serial.print("MAC address: ");
  75. Serial.println(buf);
  76. }
  77.  
  78. void printCurrentNet()
  79. {
  80. // print the SSID of the network you're attached to
  81. Serial.print("SSID: ");
  82. Serial.println(WiFi.SSID());
  83.  
  84. // print the MAC address of the router you're attached to
  85. byte bssid[6];
  86. WiFi.BSSID(bssid);
  87. char buf[20];
  88. sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X", bssid[5], bssid[4], bssid[3], bssid[2], bssid[1], bssid[0]);
  89. Serial.print("BSSID: ");
  90. Serial.println(buf);
  91.  
  92. // print the received signal strength
  93. long rssi = WiFi.RSSI();
  94. Serial.print("Signal strength (RSSI): ");
  95. Serial.println(rssi);
  96. }
RAW Paste Data