SHARE
TWEET

Untitled

a guest May 20th, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. char ssid2[] = "internal.IOT";     //  your network SSID (name)
  16. 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.  if (WiFi.status() == WL_NO_SHIELD) {
  61.     Serial.println("WiFi shield not present");
  62.     // don't continue:
  63.     while (true);
  64.   }
  65. //
  66.   while (status != WL_CONNECTED) {
  67.     Serial.print("Attempting to connect to WPA SSID: ");
  68.     Serial.println(ssid2);
  69.     // Connect to WPA/WPA2 network:
  70.     status = WiFi.begin(ssid2, pass2);
  71.  
  72.     // wait 10 seconds for connection:
  73.     delay(10000);
  74.   }
  75.  
  76.   // you're connected now, so print out the data:
  77.   Serial.print("You're connected to the network");  
  78.   printWifiData();
  79. }
  80.  
  81. void loop(void)
  82. {
  83.     server.handleClient();
  84.     if(temp!=counter){
  85.       hasChanged = true;
  86.     }
  87.     if(hasChanged){
  88.       lcd.print("              ");
  89.       lcd.setCursor(0,0);
  90.       lcd.print("connected");
  91.     }
  92.     temp = counter;
  93.     hasChanged = false;
  94.     counter = WiFi.softAPgetStationNum();
  95.     delay(2000);
  96.     lcd.print("              ");
  97. }
  98.  
  99.  
  100. ///////////
  101. void printWifiData() {
  102.   // print your WiFi shield's IP address:
  103.   IPAddress ip = WiFi.localIP();
  104.   Serial.print("IP Address: ");
  105.   Serial.println(ip);
  106.   Serial.println(ip);
  107.  
  108.   // print your MAC address:
  109.   byte mac[6];
  110.   WiFi.macAddress(mac);
  111.   Serial.print("MAC address: ");
  112.   Serial.print(mac[5], HEX);
  113.   Serial.print(":");
  114.   Serial.print(mac[4], HEX);
  115.   Serial.print(":");
  116.   Serial.print(mac[3], HEX);
  117.   Serial.print(":");
  118.   Serial.print(mac[2], HEX);
  119.   Serial.print(":");
  120.   Serial.print(mac[1], HEX);
  121.   Serial.print(":");
  122.   Serial.println(mac[0], HEX);
  123.  
  124. }
  125.  
  126.  
  127.  
  128.  
  129. void handleRoot() {
  130.   static bool state;
  131.   server.send(200, "text/html", "<h1>You are connected</h1>");
  132.   if(state) {
  133.     digitalWrite(LED_BUILTIN, HIGH);
  134.   } else {
  135.     digitalWrite(LED_BUILTIN, LOW);
  136.   }
  137.   delay(2000);
  138.   state = !state;
  139.  
  140. }
  141.  
  142.  
  143. void handleNotFound(){
  144.   digitalWrite(LED_BUILTIN, 1);
  145.   String message = "File Not Found\n\n";
  146.   message += "URI: ";
  147.   message += server.uri();
  148.   message += "\nMethod: ";
  149.   message += (server.method() == HTTP_GET)?"GET":"POST";
  150.   message += "\nArguments: ";
  151.   message += server.args();
  152.   message += "\n";
  153.   for (uint8_t i=0; i<server.args(); i++){
  154.     message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
  155.   }
  156.   server.send(404, "text/plain", message);
  157.   digitalWrite(LED_BUILTIN, 0);
  158. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top