• Witaj na Forum Arduino Polska! Zapraszamy do rejestracji!
  • Znajdziesz tutaj wiele informacji na temat hardware / software.
Witaj! Logowanie Rejestracja


Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
UNO + ETHERNET + RC522
#10
Hej ktoś by mi mógł pomóc z kodem? chciałem żeby UID pokazywał się na stronie

Kod:
#include <SPI.h>
#include <Ethernet.h>
#include <MFRC522.h>

#define RST_PIN   6     // Configurable, see typical pin layout above
#define SS_PIN    7    // Configurable, see typical pin layout above

MFRC522 mfrc522(SS_PIN, RST_PIN);
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 0, 177);

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
#define NEW_UID {0xDE, 0xAD, 0xBE, 0xEF}
MFRC522::MIFARE_Key key;

void setup() {
 // Open serial communications and wait for port to open:
 Serial.begin(9600);
 while (!Serial){
 SPI.begin();         // Init SPI bus
 mfrc522.PCD_Init();  // Init MFRC522 card
 Serial.println(F("Warning: this example overwrites the UID of your UID changeable card, use with care!"));
 
 // Prepare key - all keys are set to FFFFFFFFFFFFh at chip delivery from the factory.
 for (byte i = 0; i < 6; i++) {
   key.keyByte[i] = 0xFF;
 }
}
   ; // wait for serial port to connect. Needed for native USB port only



 // start the Ethernet connection and the server:
 Ethernet.begin(mac, ip);
 server.begin();
 Serial.print("server is at ");
 Serial.println(Ethernet.localIP());
   Serial.print(F("Card UID:"));
 for (byte i = 0; i < mfrc522.uid.size; i++) {
   Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
   Serial.print(mfrc522.uid.uidByte[i],  DEC);
 }
 Serial.println();
}


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();
       Serial.write(c);
       // if you've gotten to the end of the line (received a newline
       // character) and the line is blank, the http request has ended,
       // so you can send a reply
       if (c == '\n' && currentLineIsBlank) {
         // send a standard http response header
         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();
         client.println("<!DOCTYPE HTML>");
         client.println("<html>");
         // output the value of each analog input pin
 byte newUid[] = NEW_UID;
 if ( mfrc522.MIFARE_SetUid(newUid, (byte)4, true) ) {
   Serial.println(F("Wrote new UID to card."));
 }
 
 // Halt PICC and re-select it so DumpToSerial doesn't get confused
 mfrc522.PICC_HaltA();
 if ( ! mfrc522.PICC_IsNewCardPresent() || ! mfrc522.PICC_ReadCardSerial() ) {
   return;
 }
 
 // Dump the new memory contents
 Serial.println(F("New UID and contents:"));
 mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
 
 delay(2000);


         client.println("</html>");
         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");
   Ethernet.maintain();
 }
}
 
Odpowiedź
  


Wiadomości w tym wątku
UNO + ETHERNET + RC522 - przez awachowski - 22-01-2016, 21:30
RE: UNO + ETHERNET + RC522 - przez JasQ - 22-01-2016, 21:34
RE: UNO + ETHERNET + RC522 - przez awachowski - 22-01-2016, 21:40
RE: UNO + ETHERNET + RC522 - przez awachowski - 22-01-2016, 21:41
RE: UNO + ETHERNET + RC522 - przez awachowski - 22-01-2016, 21:53
RE: UNO + ETHERNET + RC522 - przez wojtekizk - 22-01-2016, 22:25
RE: UNO + ETHERNET + RC522 - przez awachowski - 22-01-2016, 22:31
RE: UNO + ETHERNET + RC522 - przez wojtekizk - 22-01-2016, 22:43
RE: UNO + ETHERNET + RC522 - przez awachowski - 23-01-2016, 00:53
RE: UNO + ETHERNET + RC522 - przez awachowski - 23-01-2016, 13:18
RE: UNO + ETHERNET + RC522 - przez awachowski - 24-01-2016, 20:14
RE: UNO + ETHERNET + RC522 - przez setim - 28-01-2016, 12:56
RE: UNO + ETHERNET + RC522 - przez awachowski - 28-01-2016, 13:34
RE: UNO + ETHERNET + RC522 - przez setim - 28-01-2016, 14:55
RE: UNO + ETHERNET + RC522 - przez adix - 30-01-2016, 00:59

Skocz do:


Przeglądający: 1 gości