WebServer и rfid(RC522)
- Войдите на сайт для отправки комментариев
Вс, 21/06/2020 - 01:00
Имеется Arduino UNO
стандартный скетч WebServer полностью устраивает только необходимо добавить туда чтобы в вебпанели выводилась информация с rfid(RC522) считывателя, а именно Card UID(номер карты), подскажите пожалуйста как это можно сделать? Спасибо!
001 | /* |
002 | Web Server |
003 |
004 | A simple web server that shows the value of the analog input pins. |
005 | using an Arduino Wiznet Ethernet shield. |
006 |
007 | Circuit: |
008 | * Ethernet shield attached to pins 10, 11, 12, 13 |
009 | * Analog inputs attached to pins A0 through A5 (optional) |
010 |
011 | created 18 Dec 2009 |
012 | by David A. Mellis |
013 | modified 9 Apr 2012 |
014 | by Tom Igoe |
015 | modified 02 Sept 2015 |
016 | by Arturo Guadalupi |
017 | |
018 | */ |
019 |
020 | #include <SPI.h> |
021 | #include <Ethernet.h> |
022 |
023 | // Enter a MAC address and IP address for your controller below. |
024 | // The IP address will be dependent on your local network: |
025 | byte mac[] = { |
026 | 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED |
027 | }; |
028 | IPAddress ip(192, 168, 1, 177); |
029 |
030 | // Initialize the Ethernet server library |
031 | // with the IP address and port you want to use |
032 | // (port 80 is default for HTTP): |
033 | EthernetServer server(80); |
034 |
035 | void setup () { |
036 | // You can use Ethernet.init(pin) to configure the CS pin |
037 | //Ethernet.init(10); // Most Arduino shields |
038 | //Ethernet.init(5); // MKR ETH shield |
039 | //Ethernet.init(0); // Teensy 2.0 |
040 | //Ethernet.init(20); // Teensy++ 2.0 |
041 | //Ethernet.init(15); // ESP8266 with Adafruit Featherwing Ethernet |
042 | //Ethernet.init(33); // ESP32 with Adafruit Featherwing Ethernet |
043 |
044 | // Open serial communications and wait for port to open: |
045 | Serial .begin(9600); |
046 | while (! Serial ) { |
047 | ; // wait for serial port to connect. Needed for native USB port only |
048 | } |
049 | Serial .println( "Ethernet WebServer Example" ); |
050 |
051 | // start the Ethernet connection and the server: |
052 | Ethernet.begin(mac, ip); |
053 |
054 | // Check for Ethernet hardware present |
055 | if (Ethernet.hardwareStatus() == EthernetNoHardware) { |
056 | Serial .println( "Ethernet shield was not found. Sorry, can't run without hardware. :(" ); |
057 | while ( true ) { |
058 | delay(1); // do nothing, no point running without Ethernet hardware |
059 | } |
060 | } |
061 | if (Ethernet.linkStatus() == LinkOFF) { |
062 | Serial .println( "Ethernet cable is not connected." ); |
063 | } |
064 |
065 | // start the server |
066 | server.begin(); |
067 | Serial .print( "server is at " ); |
068 | Serial .println(Ethernet.localIP()); |
069 | } |
070 |
071 |
072 | void loop () { |
073 | // listen for incoming clients |
074 | EthernetClient client = server.available(); |
075 | if (client) { |
076 | Serial .println( "new client" ); |
077 | // an http request ends with a blank line |
078 | boolean currentLineIsBlank = true ; |
079 | while (client.connected()) { |
080 | if (client.available()) { |
081 | char c = client.read(); |
082 | Serial .write(c); |
083 | // if you've gotten to the end of the line (received a newline |
084 | // character) and the line is blank, the http request has ended, |
085 | // so you can send a reply |
086 | if (c == '\n' && currentLineIsBlank) { |
087 | // send a standard http response header |
088 | client.println( "HTTP/1.1 200 OK" ); |
089 | client.println( "Content-Type: text/html" ); |
090 | client.println( "Connection: close" ); // the connection will be closed after completion of the response |
091 | client.println( "Refresh: 5" ); // refresh the page automatically every 5 sec |
092 | client.println(); |
093 | client.println( "<!DOCTYPE HTML>" ); |
094 | client.println( "<html>" ); |
095 | // output the value of each analog input pin |
096 | for ( int analogChannel = 0; analogChannel < 6; analogChannel++) { |
097 | int sensorReading = analogRead(analogChannel); |
098 | client.print( "analog input " ); |
099 | client.print(analogChannel); |
100 | client.print( " is " ); |
101 | client.print(sensorReading); |
102 | client.println( "<br />" ); |
103 | } |
104 | client.println( "</html>" ); |
105 | break ; |
106 | } |
107 | if (c == '\n' ) { |
108 | // you're starting a new line |
109 | currentLineIsBlank = true ; |
110 | } else if (c != '\r' ) { |
111 | // you've gotten a character on the current line |
112 | currentLineIsBlank = false ; |
113 | } |
114 | } |
115 | } |
116 | // give the web browser time to receive the data |
117 | delay(1); |
118 | // close the connection: |
119 | client.stop(); |
120 | Serial .println( "client disconnected" ); |
121 | } |
122 | } |
01 | /* |
02 | * ---------------------------------------------------------------------------- |
03 | * This is a MFRC522 library example; see <a href="https://github.com/miguelbalboa/rfid" title="https://github.com/miguelbalboa/rfid" rel="nofollow">https://github.com/miguelbalboa/rfid</a> |
04 | * for further details and other examples. |
05 | * |
06 | * NOTE: The library file MFRC522.h has a lot of useful info. Please read it. |
07 | * |
08 | * Released into the public domain. |
09 | * ---------------------------------------------------------------------------- |
10 | * Example sketch/program showing how to read data from a PICC (that is: a RFID |
11 | * Tag or Card) using a MFRC522 based RFID Reader on the Arduino SPI interface. |
12 | * |
13 | * When the Arduino and the MFRC522 module are connected (see the pin layout |
14 | * below), load this sketch into Arduino IDE then verify/compile and upload it. |
15 | * To see the output: use Tools, Serial Monitor of the IDE (hit Ctrl+Shft+M). |
16 | * When you present a PICC (that is: a RFID Tag or Card) at reading distance |
17 | * of the MFRC522 Reader/PCD, the serial output will show the ID/UID, type and |
18 | * any data blocks it can read. Note: you may see "Timeout in communication" |
19 | * messages when removing the PICC from reading distance too early. |
20 | * |
21 | * If your reader supports it, this sketch/program will read all the PICCs |
22 | * presented (that is: multiple tag reading). So if you stack two or more |
23 | * PICCs on top of each other and present them to the reader, it will first |
24 | * output all details of the first and then the next PICC. Note that this |
25 | * may take some time as all data blocks are dumped, so keep the PICCs at |
26 | * reading distance until complete. |
27 | * |
28 | * Typical pin layout used: |
29 | * ----------------------------------------------------------------------------------------- |
30 | * MFRC522 Arduino Arduino Arduino Arduino Arduino |
31 | * Reader/PCD Uno Mega Nano v3 Leonardo/Micro Pro Micro |
32 | * Signal Pin Pin Pin Pin Pin Pin |
33 | * ----------------------------------------------------------------------------------------- |
34 | * RST/Reset RST 9 5 D9 RESET/ICSP-5 RST |
35 | * SPI SS SDA(SS) 10 53 D10 10 10 |
36 | * SPI MOSI MOSI 11 / ICSP-4 51 D11 ICSP-4 16 |
37 | * SPI MISO MISO 12 / ICSP-1 50 D12 ICSP-1 14 |
38 | * SPI SCK SCK 13 / ICSP-3 52 D13 ICSP-3 15 |
39 | */ |
40 |
41 | #include <SPI.h> |
42 | #include <MFRC522.h> |
43 |
44 | #define RST_PIN 9 // |
45 | #define SS_PIN 10 // |
46 |
47 | MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance |
48 |
49 | void setup () { |
50 | Serial .begin(9600); // Initialize serial communications with the PC |
51 | while (! Serial ); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4) |
52 | SPI.begin(); // Init SPI bus |
53 | mfrc522.PCD_Init(); // Init MFRC522 |
54 | ShowReaderDetails(); // Show details of PCD - MFRC522 Card Reader details |
55 | Serial .println(F( "Scan PICC to see UID, type, and data blocks..." )); |
56 | } |
57 |
58 | void loop () { |
59 | // Look for new cards |
60 | if ( ! mfrc522.PICC_IsNewCardPresent()) { |
61 | return ; |
62 | } |
63 |
64 | // Select one of the cards |
65 | if ( ! mfrc522.PICC_ReadCardSerial()) { |
66 | return ; |
67 | } |
68 |
69 | // Dump debug info about the card; PICC_HaltA() is automatically called |
70 | mfrc522.PICC_DumpToSerial(&(mfrc522.uid)); |
71 | } |
72 |
73 | void ShowReaderDetails() { |
74 | // Get the MFRC522 software version |
75 | byte v = mfrc522.PCD_ReadRegister(mfrc522.VersionReg); |
76 | Serial .print(F( "MFRC522 Software Version: 0x" )); |
77 | Serial .print(v, HEX); |
78 | if (v == 0x91) |
79 | Serial .print(F( " = v1.0" )); |
80 | else if (v == 0x92) |
81 | Serial .print(F( " = v2.0" )); |
82 | else |
83 | Serial .print(F( " (unknown)" )); |
84 | Serial .println( "" ); |
85 | // When 0x00 or 0xFF is returned, communication probably failed |
86 | if ((v == 0x00) || (v == 0xFF)) { |
87 | Serial .println(F( "WARNING: Communication failure, is the MFRC522 properly connected?" )); |
88 | } |
89 | } |
Не вижу, чтобы вы пытались обьединить два скетча. Почитайте правила форума, никто за вас это делать не будет, здесь помогают тем, кто пытается решать проблемы сам.
И еще - имхо, сама идея выводить UID карты в Вебпанель - не слишком удачная