Fajne, internetowe kursy programowania po Polsku Kursy programowania i rozwoju osobistego. |
Pewnie vss-owi chodzi o żródło którego nie widać, czyli co wrzuciłem do flasha ESP8266. Żadna tajemnica, no poza hasłami na domowe AP, bo to oparte na francuskim przykładzie, trochę go wzbogaciłem, bo to ma też móc łazić w robocie po całym domu i móc sobie przełaczać access pointy wifi. No niestety zrobię bałagan, bo nie widzę mozliwości publikacji kodu, jak na forach informatycznych: #include <,WiFiClient.h>, #include <,ESP8266WebServer.h>, #include <,DHT.h>, //#include <,Adafruit_BMP085.h>, const char* ssid[] PROGMEM = "ssid0", "ssid1", "ssid2", const char* password[] PROGMEM = "pass0", "pass1", "pass2", const int apn = 3, // number of known Access points int rssis[3] = -200, -200, -200, #define MINSIGNAL -95 //Below starts try to find stronger AP const int serverport = 82, #define DHTTYPE DHT11 // DHT type (DHT11, DHT22) #define DHTPIN D4 // DHT Pin const uint8_t GPIOPIN[4] = D5, D6, D7, D8, // Led float t = 0 , float h = 0 , float p = 0, String etatGpio[4] = "OFF", "OFF", "OFF", "OFF", int apj = 0, //Access points counter // create Objects DHT dht(DHTPIN, DHTTYPE), //Adafruit_BMP085 bmp, //ESP8266WebServer server ( 80 ), ESP8266WebServer server ( serverport ), //Port serverport set above to distinguish from ordinary web pages String getPage() String page = "<,html lang='pl'<,head>,<,meta http-equiv='refresh' content='60' name='viewport' content='width=device-width, initial-scale=1'/>,", page += "<,link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css'>,<,script src='https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js'>,<,/script>,<,script src='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js'>,<,/script>,", page += "<,meta charset='utf-8'>,", page += "<,title>,ESP8266 Stacja Pogodowa<,/title>,<,/head>,<,body>,", page += "<,div class='container-fluid'>,", page += "<,div class='row'>,", page += "<,div class='col-md-12'>,", page += "<,h1>,Mini stacja meteo & włącznik LED ESP8266<,/h1>,", page += "<,h3>,Mini stacja meteo<,/h3>,", page += "<,ul class='nav nav-pills'>,", page += "<,li class='active'>,", page += "<,a href='#'>, <,span class='badge pull-right'>,", page += t, page += "<,/span>, Temperatura<,/a>,", page += "<,/li>,<,li>,", page += "<,a href='#'>, <,span class='badge pull-right'>,", page += h, page += "<,/span>, Wilgotność<,/a>,", page += "<,/li>,<,li>,", page += "<,a href='#'>, <,span class='badge pull-right'>,", page += p, page += "<,/span>, Ciśnienie atmosferyczne<,/a>,<,/li>,", page += "<,/li>,<,li>,", page += "<,a href='#'>, <,span class='badge pull-right'>,", page += ssid[apj], page += "<,/span>, Połaczenie WiFi z <,/a>,<,/li>,", page += "<,/li>,<,li>,", page += "<,a href='#'>, <,span class='badge pull-right'>,", page += WiFi.RSSI(), page += "<,/span>, Siła sygnału <,/a>,", page += "<,/ul>,", page += "<,table class='table'>,", // Tableau des relevés page += "<,thead>,<,tr>,<,th>,Czujnik<,/th>,<,th>,Pomiar<,/th>,<,th>,Wartość<,/th>,<,th>,Wartość przewidywana<,/th>,<,/tr>,<,/thead>,", //Entê,te page += "<,tbody>,", // Contenu du tableau page += "<,tr>,<,td>,DHT11<,/td>,<,td>,Temperatura<,/td>,<,td>,", // Premiè,re ligne : température page += t, page += "°,C<,/td>,<,td>,", page += " -<,/td>,<,/tr>,", page += "<,tr class='active'>,<,td>,DHT11<,/td>,<,td>,Wilgotność<,/td>,<,td>,", // 2nd ligne : Humidité page += h, page += "%<,/td>,<,td>,", page += " -<,/td>,<,/tr>,", page += "<,tr>,<,td>,BMP180<,/td>,<,td>,Ciśnienie atmosferyczne<,/td>,<,td>,", // 3è,me ligne : PA (BMP180) page += p, page += " mbar<,/td>,<,td>,", page += "-<,/td>,<,/tr>,", page += "<,/tbody>,<,/table>,", page += "<,h3>,GPIO<,/h3>,", page += "<,div class='row'>,", page += "<,div class='col-md-4'>,<,h4 class ='text-left'>,D5 ", page += "<,span class='badge'>,", page += etatGpio[0], page += "<,/span>,<,/h4>,<,/div>,", page += "<,div class='col-md-4'>,<,form action='/' method='POST'>,<,button type='button submit' name='D5' value='1' class='btn btn-success btn-lg'>,ON<,/button>,<,/form>,<,/div>,", page += "<,div class='col-md-4'>,<,form action='/' method='POST'>,<,button type='button submit' name='D5' value='0' class='btn btn-danger btn-lg'>,OFF<,/button>,<,/form>,<,/div>,", page += "<,div class='col-md-4'>,<,h4 class ='text-left'>,D6 ", page += "<,span class='badge'>,", page += etatGpio[1], page += "<,/span>,<,/h4>,<,/div>,", page += "<,div class='col-md-4'>,<,form action='/' method='POST'>,<,button type='button submit' name='D6' value='1' class='btn btn-success btn-lg'>,ON<,/button>,<,/form>,<,/div>,", page += "<,div class='col-md-4'>,<,form action='/' method='POST'>,<,button type='button submit' name='D6' value='0' class='btn btn-danger btn-lg'>,OFF<,/button>,<,/form>,<,/div>,", page += "<,div class='col-md-4'>,<,h4 class ='text-left'>,D7 ", page += "<,span class='badge'>,", page += etatGpio[2], page += "<,/span>,<,/h4>,<,/div>,", page += "<,div class='col-md-4'>,<,form action='/' method='POST'>,<,button type='button submit' name='D7' value='1' class='btn btn-success btn-lg'>,ON<,/button>,<,/form>,<,/div>,", page += "<,div class='col-md-4'>,<,form action='/' method='POST'>,<,button type='button submit' name='D7' value='0' class='btn btn-danger btn-lg'>,OFF<,/button>,<,/form>,<,/div>,", page += "<,div class='col-md-4'>,<,h4 class ='text-left'>,D8 ", page += "<,span class='badge'>,", page += etatGpio[3], page += "<,/span>,<,/h4>,<,/div>,", page += "<,div class='col-md-4'>,<,form action='/' method='POST'>,<,button type='button submit' name='D8' value='1' class='btn btn-success btn-lg'>,ON<,/button>,<,/form>,<,/div>,", page += "<,div class='col-md-4'>,<,form action='/' method='POST'>,<,button type='button submit' name='D8' value='0' class='btn btn-danger btn-lg'>,OFF<,/button>,<,/form>,<,/div>,", page += "<,/div>,", page += "<,br>,<,p>,<,a href='http://www.projetsdiy.fr'>,www.projetsdiy.fr<,/p>,", page += "<,/div>,<,/div>,<,/div>,", page += "<,/body>,<,/html>,", return page, void handleRoot() if ( server.hasArg("D5") ) handleD5(), else if ( server.hasArg("D6") ) handleD6(), else if ( server.hasArg("D7") ) handleD7(), else if ( server.hasArg("D8") ) handleD8(), else server.send ( 200, "text/html", getPage() ), void handleD5() String D5Value, updateGPIO(0, server.arg("D5")), void handleD6() String D6Value, updateGPIO(1, server.arg("D6")), void handleD7() String D7Value, updateGPIO(2, server.arg("D7")), void handleD8() String D8Value, updateGPIO(3, server.arg("D8")), void updateGPIO(int gpio, String DxValue) Serial.println(""), Serial.println("Aktualizuj GPIO "), Serial.print(GPIOPIN[gpio]), Serial.print(" ->, "), Serial.println(DxValue), if ( DxValue == "1" ) digitalWrite(GPIOPIN[gpio], HIGH), etatGpio[gpio] = "ON", server.send ( 200, "text/html", getPage() ), else if ( DxValue == "0" ) digitalWrite(GPIOPIN[gpio], LOW), etatGpio[gpio] = "OFF", server.send ( 200, "text/html", getPage() ), else Serial.println("Err Led Value"), void connection() // Wait for connection for (apj = 0, apj <, apn, apj++) rssis[apj] = -200,//Set low strengths for known access points. WiFi.mode(WIFI_STA), WiFi.disconnect(), delay(100), Serial.println("scan start"), // WiFi.scanNetworks will return the number of networks found int n = WiFi.scanNetworks(), Serial.println("scan done"), if (n == 0) Serial.println("no networks found"), else Serial.print(n), Serial.println(" networks found"), for (int i = 0, i <, n, i++) // Print SSID and RSSI for each network found Serial.print(i), Serial.print(": "), Serial.print(WiFi.SSID(i)), Serial.print(" ("), Serial.print(WiFi.RSSI(i)), for (apj = 0, apj <, apn, apj++) if (WiFi.SSID(i) == ssid[apj]) rssis[apj] = int(WiFi.RSSI(i)), // assigns signal strengths to known access points Serial.print(")"), Serial.println((WiFi.encryptionType(i) == ENC_TYPE_NONE) ? " " : "*"), delay(10), Serial.println("Finding the strongest network "), //Finding the strongest AP. int maxrssi = -200, int apjmax = 0, for (apj = 0, apj <, apn, apj++) if (rssis[apj] >, maxrssi) maxrssi = rssis[apj], apjmax = apj, apj = apjmax, WiFi.disconnect(), delay(1000), Serial.print("Trying to connect to the strongest known Access Point no "), Serial.print(apj), Serial.print(" "), Serial.print(ssid[apj]), Serial.print(" Signal strength "), Serial.println(rssis[apj]), WiFi.begin ( ssid[apj], password[apj] ), for (int i = 0, (i <, 30 && WiFi.status() != WL_CONNECTED), i++) delay ( 500 ), Serial.print ( "." ), if (WiFi.status() != WL_CONNECTED) Serial.println(""), Serial.print("Failed to connect to no "), Serial.print(apj), Serial.print(" "), Serial.println(ssid[apj]), //If failed for any reasons try to connect to other knowsn AP while ( WiFi.status() != WL_CONNECTED ) for (apj = 0, apj <, apn && WiFi.status() != WL_CONNECTED, apj++) Serial.print("Trying to connect to no "), Serial.print(apj), Serial.print(" "), Serial.println(ssid[apj]), WiFi.begin ( ssid[apj], password[apj] ), for (int i = 0, (i <, 20 && WiFi.status() != WL_CONNECTED), i++) delay ( 500 ), Serial.print ( "." ), if (WiFi.status() != WL_CONNECTED) Serial.println(""), Serial.print("Failed to connect to "), Serial.println(ssid[apj]), else break, // WiFi connexion is OK Serial.println ( "" ), Serial.print ( "Connected to no " ), Serial.println (apj), Serial.println (" "), Serial.println ( ssid[apj] ), Serial.print ( "IP address: " ), Serial.println ( WiFi.localIP() ), Serial.print("Signal strength "), Serial.println(int(WiFi.RSSI())), // On branche la fonction qui gè,re la premiere page / link to the function that manage launch page server.on ( "/", handleRoot ), server.begin(), Serial.print ( "HTTP server started on port " ), Serial.println(serverport), //******************************************************************************************************** void setup() for ( int x = 0 , x <, 5 , x++ ) pinMode(GPIOPIN[x], OUTPUT), delay(5000), //delay for com port to establish. Serial.begin ( 115200 ), /* // Initialisation du BMP180 / Init BMP180 if ( !bmp.begin() ) Serial.println("BMP180 KO!"), while(1), else Serial.println("BMP180 OK"), */ connection(), void loop() // put your main code here, to run repeatedly: if (WiFi.status() == WL_CONNECTED && int(WiFi.RSSI()) >, MINSIGNAL) server.handleClient(), t = dht.readTemperature(), h = dht.readHumidity(), // p = bmp.readPressure() / 100.0F, delay(500), else Serial.print("Lost connection with "), Serial.println(ssid[apj]), connection(), Tu zastosowano upiększacze ze strony bootstrap i właśnie to chcę wywalić i zrobić własne style, Tu też brakuje suwaków i kontekstowej zmiany atrybutów obiektów. W moim pythonowym okienku, jak się zapali leda to się kolor buttona zmienmia na jaśniejszy i napis się zmienia na set led off off, no i jest "toggle", nie mówiąc już o suwaczku do kręcenia serwem . Do takiego "scope of work" nie potrzeba ani js ani php a już napewno mysql . Purystów językowych przepraszam za anglojęzyczne komentarze w kodzie, ale tak się już przyzwyczaiłem i tak też jest praktyczniej. "Polacy nie gęsi i swój język mają", ale też obce języki znają. Mikołaj Rej znał Łacinę, Grekę i Bóg wie co jeszcze. |