Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. //#define BLUELED D1
  2. //#define GREENLED D2
  3. //#define REDLED D3
  4. //
  5. //void setup() {
  6. //
  7. // pinMode(BLUELED, OUTPUT);
  8. // pinMode(GREENLED, OUTPUT);
  9. // pinMode(REDLED, OUTPUT);
  10. //
  11. //}
  12. //
  13. //void loop() {
  14. // redLight();
  15. // delay (1000);
  16. // yellowLight();
  17. // delay (1000);
  18. //}
  19. //
  20. //void redLight() {
  21. // Serial.println("Waiting for connection and IP Address from DHCP");
  22. // digitalWrite(REDLED,HIGH);
  23. // digitalWrite(GREENLED,LOW);
  24. // digitalWrite(BLUELED,LOW);
  25. //}
  26. //void yellowLight() {
  27. // digitalWrite(REDLED,HIGH);
  28. // digitalWrite(GREENLED,HIGH);
  29. // digitalWrite(BLUELED,LOW);
  30. //}
  31.  
  32. #include <ESP8266WiFi.h>
  33.  
  34. extern "C" {
  35. #include "user_interface.h"
  36. #include "wpa2_enterprise.h"
  37. }
  38.  
  39. // SSID to connect to
  40. static const char* ssid = "MAP1268R";
  41. // Username for authentification
  42. static const char* username = "velievd";
  43. // Password for authentication
  44. static const char* password = "Redbottle456";
  45.  
  46. char buff[20];
  47. String ip;
  48.  
  49. void setup() {
  50. // put your setup code here, to run once:
  51. Serial.begin(115200);
  52.  
  53. delay(500);
  54.  
  55. // WPA2 Connection starts here
  56. // Setting ESP into STATION mode only (no AP mode or dual mode)
  57. wifi_set_opmode(STATION_MODE);
  58. struct station_config wifi_config;
  59. memset(&wifi_config, 0, sizeof(wifi_config));
  60. strcpy((char*)wifi_config.ssid, ssid);
  61. wifi_station_set_config(&wifi_config);
  62. wifi_station_clear_cert_key();
  63. wifi_station_clear_enterprise_ca_cert();
  64. wifi_station_set_wpa2_enterprise_auth(1);
  65. wifi_station_set_enterprise_identity((uint8*)username, strlen(username));
  66. wifi_station_set_enterprise_username((uint8*)username, strlen(username));
  67. wifi_station_set_enterprise_password((uint8*)password, strlen(password));
  68. wifi_station_connect();
  69. // WPA2 Connection ends here
  70.  
  71. // Wait for connection AND IP address from DHCP
  72. Serial.println();
  73. Serial.println("Waiting for connection and IP Address from DHCP");
  74. while (WiFi.status() != WL_CONNECTED) {
  75. delay(2000);
  76. Serial.print(".");
  77. WiFi.printDiag(Serial);
  78.  
  79. }
  80. Serial.println("");
  81. Serial.println("WiFi connected");
  82. Serial.println("IP address: ");
  83. Serial.println(WiFi.localIP());
  84. IPAddress myAddr = WiFi.localIP();
  85. sprintf(buff, "%d.%d.%d.%d", myAddr[0], myAddr[1], myAddr[2], myAddr[3]);
  86. ip = String(buff);
  87. Serial.println(ip);
  88.  
  89. }
  90.  
  91. void loop() {
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement