Ethernet shield ENC28J60

Odpovědět
BigSandy
Příspěvky: 220
Registrován: 23 zář 2017, 07:09
Reputation: 0

Ethernet shield ENC28J60

Příspěvek od BigSandy » 07 zář 2023, 12:29

Zdar všem.
Jsem zkusil toto a funkční.
https://forum.arduino.cc/t/arduino-nano ... /465096/10

Uplně se spokojím s web strankou s jedním tlačitkem, ale jelikož to bude přistupne zvenči, bych potřeboval, aby web najel, až po zadaní přihlašovacích udaju.
Poradí někdo?
Děkují.

BigSandy
Příspěvky: 220
Registrován: 23 zář 2017, 07:09
Reputation: 0

Re: Ethernet shield ENC28J60

Příspěvek od BigSandy » 07 zář 2023, 14:44

Jsem našel řešení, ale je tam asi kopanec.
https://www.base64encode.org/
admin:admin je YWRtaW46YWRtaW4=

Stranka se načte a vyskoči i to okno na zadaní hesla ale furt dokola jako bych zadaval špatne hesko.

Kód: Vybrat vše

#include <UIPEthernet.h> 
#include <SPI.h>
// **** ETHERNET SETTING ****
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x78, 0xEE  };                              
IPAddress ip(192, 168, 1, 115);
String header;
                        
EthernetServer server(80);

void setup() {
  Serial.begin(9600);

  // start the Ethernet connection and the server:
  Ethernet.begin(mac, ip);
  server.begin();

  Serial.print("IP Address: ");
  Serial.println(Ethernet.localIP());
}

void loop() {
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;

    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        header += c;

        if (c == '\n' && currentLineIsBlank) {

          Serial.print(header);

          
          if(header.indexOf("YWRtaW46YWRtaW4=") >= 0) {
            //successful login
            client.println("HTTP/1.1 200 OK");
            client.println("Content-Type: text/html");
            client.println("Connection: close");  // the connection will be closed after completion of the response
            //client.println("Refresh: 5");  // refresh the page automatically every 5 sec
            client.println();
              if(header.indexOf("GET / HTTP/1.1") >= 0) {
                client.println("<!DOCTYPE HTML>");
                client.println("<html>");
                client.println("index");
                client.println("</html>");
              } else {
                client.println("<!DOCTYPE HTML>");
                client.println("<html>");
                client.println("hello world!");
                client.println("</html>");
              }

          } else {

            // wrong user/pass
            //client.println("HTTP/1.0 401 Authorization Required");
            client.println("HTTP/1.1 401 Unauthorized");
            client.println("WWW-Authenticate: Basic realm=\"Secure\"");
            client.println("Content-Type: text/html");
            client.println();
            client.println("<html>Text to send if user hits Cancel button</html>"); // really need this for the popup!

          }

          header = "";
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        }
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
    Serial.println("client disconnected");
  }
}

BigSandy
Příspěvky: 220
Registrován: 23 zář 2017, 07:09
Reputation: 0

Re: Ethernet shield ENC28J60

Příspěvek od BigSandy » 07 zář 2023, 18:23

Tak jsem se na netu dočet, že to musí podporovat knihovna.
Přes knihovnu Ethernet.h Ethernet Shield ENC28J60 nejede a UIPEthernet.h to prý nepodporuje

Odpovědět

Kdo je online

Uživatelé prohlížející si toto fórum: Žádní registrovaní uživatelé a 31 hostů