Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ESP8266WiFi.h>
- #include <WiFiClient.h>
- #include <ESP8266WebServer.h>
- #include <ESP8266mDNS.h>
- #include <LiquidCrystal.h>
- #include <SPI.h>
- #define LED_BUILTIN 14
- const int rs = 12, en = 13, d4 = 4, d5 = 0, d6 = 2, d7 = 14;
- LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
- const char* ssid = "KSIADZ.ROBAK";
- const char* password = "IoTLabXD";
- char ssid2[] = "internal.IOT"; // your network SSID (name)
- char pass2[] = "IoTlab32768"; // your network password
- int status = WL_IDLE_STATUS; // the Wifi radio's status
- ESP8266WebServer server(80);
- bool hasChanged = false;
- int temp = 0;
- int counter;
- void setup(void)
- {
- pinMode(LED_BUILTIN, OUTPUT);
- delay(1000);
- Serial.begin(115200);
- lcd.begin(16,2);
- lcd.print("...");
- int numberOfNetworks = WiFi.scanNetworks();
- for(int i =0; i<numberOfNetworks; i++)
- {
- Serial.print("Network name: ");
- Serial.println(WiFi.SSID(i));
- Serial.print("Signal strength: ");
- Serial.println(WiFi.RSSI(i));
- Serial.println("-----------------------");
- }
- ////////////////////////////////////////////////////
- // WiFi.softAP(ssid, password);
- //
- // Serial.println();
- // Serial.print("Server IP address: ");
- // Serial.println(WiFi.softAPIP());
- // Serial.print("Server MAC address: ");
- // Serial.println(WiFi.softAPmacAddress());
- //
- // server.on("/", handleRoot);
- // server.begin();
- //
- // Serial.println("Server listening");
- //
- //
- // counter = WiFi.softAPgetStationNum();
- ///////////////////////////////////////////////////////
- if (WiFi.status() == WL_NO_SHIELD) {
- Serial.println("WiFi shield not present");
- // don't continue:
- while (true);
- }
- //
- while (status != WL_CONNECTED) {
- Serial.print("Attempting to connect to WPA SSID: ");
- Serial.println(ssid2);
- // Connect to WPA/WPA2 network:
- status = WiFi.begin(ssid2, pass2);
- // wait 10 seconds for connection:
- delay(10000);
- }
- // you're connected now, so print out the data:
- Serial.print("You're connected to the network");
- printWifiData();
- }
- void loop(void)
- {
- server.handleClient();
- if(temp!=counter){
- hasChanged = true;
- }
- if(hasChanged){
- lcd.print(" ");
- lcd.setCursor(0,0);
- lcd.print("connected");
- }
- temp = counter;
- hasChanged = false;
- counter = WiFi.softAPgetStationNum();
- delay(2000);
- lcd.print(" ");
- }
- ///////////
- void printWifiData() {
- // print your WiFi shield's IP address:
- IPAddress ip = WiFi.localIP();
- Serial.print("IP Address: ");
- Serial.println(ip);
- Serial.println(ip);
- // print your MAC address:
- byte mac[6];
- WiFi.macAddress(mac);
- Serial.print("MAC address: ");
- Serial.print(mac[5], HEX);
- Serial.print(":");
- Serial.print(mac[4], HEX);
- Serial.print(":");
- Serial.print(mac[3], HEX);
- Serial.print(":");
- Serial.print(mac[2], HEX);
- Serial.print(":");
- Serial.print(mac[1], HEX);
- Serial.print(":");
- Serial.println(mac[0], HEX);
- }
- void handleRoot() {
- static bool state;
- server.send(200, "text/html", "<h1>You are connected</h1>");
- if(state) {
- digitalWrite(LED_BUILTIN, HIGH);
- } else {
- digitalWrite(LED_BUILTIN, LOW);
- }
- delay(2000);
- state = !state;
- }
- void handleNotFound(){
- digitalWrite(LED_BUILTIN, 1);
- String message = "File Not Found\n\n";
- message += "URI: ";
- message += server.uri();
- message += "\nMethod: ";
- message += (server.method() == HTTP_GET)?"GET":"POST";
- message += "\nArguments: ";
- message += server.args();
- message += "\n";
- for (uint8_t i=0; i<server.args(); i++){
- message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
- }
- server.send(404, "text/plain", message);
- digitalWrite(LED_BUILTIN, 0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement