Advertisement
Guest User

Untitled

a guest
May 27th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.01 KB | None | 0 0
  1. #include <ESP8266WiFi.h>
  2. #include <WiFiClient.h>
  3. #include <ESP8266WebServer.h>
  4. #include <ESP8266mDNS.h>
  5. #include <LiquidCrystal.h>
  6. #include <SPI.h>
  7.  
  8. #define LED_BUILTIN 14
  9. const int rs = 12, en = 13, d4 = 4, d5 = 0, d6 = 2, d7 = 14;
  10. LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
  11.  
  12. const char* ssid = "KSIADZ.ROBAK";
  13. const char* password =  "IoTLabXD";
  14.  
  15. const char* ssid2 = "internal.IOT";     //  your network SSID (name)
  16. const char* pass2 = "IoTlab32768";  // your network password
  17. int status = WL_IDLE_STATUS;     // the Wifi radio's status
  18.  
  19. ESP8266WebServer server(80);
  20.  
  21. bool hasChanged = false;
  22. int temp = 0;
  23. int counter;
  24.  
  25.  
  26. void setup(void)
  27. {
  28.       pinMode(LED_BUILTIN, OUTPUT);
  29.       delay(1000);
  30.       Serial.begin(115200);
  31.       lcd.begin(16,2);
  32.       lcd.print("...");
  33.      
  34.       int numberOfNetworks = WiFi.scanNetworks();
  35.       for(int i =0; i<numberOfNetworks; i++)
  36.       {
  37.       Serial.print("Network name: ");
  38.       Serial.println(WiFi.SSID(i));
  39.       Serial.print("Signal strength: ");
  40.       Serial.println(WiFi.RSSI(i));
  41.       Serial.println("-----------------------");
  42.       }
  43.  ////////////////////////////////////////////////////
  44. //      WiFi.softAP(ssid, password);
  45. //    
  46. //      Serial.println();
  47. //      Serial.print("Server IP address: ");
  48. //      Serial.println(WiFi.softAPIP());
  49. //      Serial.print("Server MAC address: ");
  50. //      Serial.println(WiFi.softAPmacAddress());
  51. //    
  52. //      server.on("/", handleRoot);
  53. //      server.begin();
  54. //
  55. //      Serial.println("Server listening");
  56. //
  57. //
  58. //       counter = WiFi.softAPgetStationNum();
  59.  ///////////////////////////////////////////////////////
  60. //
  61.  
  62.   WiFi.begin(ssid2, pass2);
  63.   while (WiFi.status() != WL_CONNECTED) {
  64.     Serial.print("Attempting to connect to WPA SSID: ");
  65.     Serial.println(ssid2);
  66.     delay(500);
  67.   }
  68.   // you're connected now, so print out the data:
  69.   Serial.print("You're connected to the network");  
  70.   printWifiData();
  71. }
  72.  
  73. void loop(void)
  74. {
  75.     server.handleClient();
  76.  
  77.     if(WiFi.status() == WL_CONNECTED){
  78.       lcd.println("          ");
  79.       lcd.setCursor(0,0);
  80.       lcd.print("connected");
  81.       lcd.setCursor(0,1);
  82.       lcd.print(WiFi.localIP());
  83.     }
  84.     else{
  85.       lcd.setCursor(16,2);
  86.       lcd.print("              ");
  87.       lcd.print("disconnected");
  88.     }
  89. //    if(temp!=counter){
  90. //      hasChanged = true;
  91. //    }
  92. //    if(hasChanged){
  93. //      lcd.print("              ");
  94. //      lcd.setCursor(0,0);
  95. //      lcd.print("connected");
  96. //    }
  97. //    temp = counter;
  98. //    hasChanged = false;
  99. //    counter = WiFi.softAPgetStationNum();
  100. //    delay(2000);
  101. //    lcd.print("              ");
  102. }
  103.  
  104.  
  105. ///////////
  106. void printWifiData() {
  107.   // print your WiFi shield's IP address:
  108.   IPAddress ip = WiFi.localIP();
  109.   Serial.print("IP Address: ");
  110.   Serial.println(ip);
  111.   Serial.println(ip);
  112.  
  113.   // print your MAC address:
  114.   byte mac[6];
  115.   WiFi.macAddress(mac);
  116.   Serial.print("MAC address: ");
  117.   Serial.print(mac[5], HEX);
  118.   Serial.print(":");
  119.   Serial.print(mac[4], HEX);
  120.   Serial.print(":");
  121.   Serial.print(mac[3], HEX);
  122.   Serial.print(":");
  123.   Serial.print(mac[2], HEX);
  124.   Serial.print(":");
  125.   Serial.print(mac[1], HEX);
  126.   Serial.print(":");
  127.   Serial.println(mac[0], HEX);
  128.  
  129. }
  130.  
  131.  
  132.  
  133.  
  134. void handleRoot() {
  135.   static bool state;
  136.   server.send(200, "text/html", "<h1>You are connected</h1>");
  137.   if(state) {
  138.     digitalWrite(LED_BUILTIN, HIGH);
  139.   } else {
  140.     digitalWrite(LED_BUILTIN, LOW);
  141.   }
  142.   delay(2000);
  143.   state = !state;
  144.  
  145. }
  146.  
  147.  
  148. void handleNotFound(){
  149.   digitalWrite(LED_BUILTIN, 1);
  150.   String message = "File Not Found\n\n";
  151.   message += "URI: ";
  152.   message += server.uri();
  153.   message += "\nMethod: ";
  154.   message += (server.method() == HTTP_GET)?"GET":"POST";
  155.   message += "\nArguments: ";
  156.   message += server.args();
  157.   message += "\n";
  158.   for (uint8_t i=0; i<server.args(); i++){
  159.     message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
  160.   }
  161.   server.send(404, "text/plain", message);
  162.   digitalWrite(LED_BUILTIN, 0);
  163. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement