Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: ControlAcceso MFRC522 mbed
Revision 3:2b8258feb9b7, committed 2016-04-26
- Comitter:
- capantojar
- Date:
- Tue Apr 26 23:15:22 2016 +0000
- Parent:
- 2:ffb9b2112baa
- Child:
- 4:ef96fe085434
- Commit message:
- 26/04/2016-2
Changed in this revision
| UIPEthernet.lib | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/UIPEthernet.lib Tue Apr 26 23:15:22 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/hudakz/code/UIPEthernet/#2eb264b81e3b
--- a/main.cpp Tue Apr 26 14:34:30 2016 +0000
+++ b/main.cpp Tue Apr 26 23:15:22 2016 +0000
@@ -1,43 +1,64 @@
#include "mbed.h"
#include "MFRC522.h"
+#include "UIPEthernet.h"
+#include "UIPClient.h"
+#include "string"
+using namespace std;
//------------------------------------
-// Hyperterminal configuration
+// Serial configuration
// 9600 bauds, 8-bit data, no parity
//------------------------------------
+const uint8_t MY_MAC[6] = {0x00,0x01,0x02,0x03,0x04,0x06};
+const IPAddress MY_IP(10,42,0,2);
+const IPAddress SERVER_IP(10,69,100,75);
+const uint16_t PORT = 10022; // for HTTP connection
+UIPClient Client;
+
Serial pc(SERIAL_TX, SERIAL_RX);
-MFRC522 rf(PB_15, PB_14, PB_13, PC_4, PC_12);
+UIPEthernetClass UIPEthernet(PC_12, PC_11, PC_10, PD_2);
+MFRC522 rf(PB_15, PB_14, PB_13, PC_4, PA_13);
DigitalOut green(PA_5);
uint8_t UID_P[4] = {0x44,0xBE,0x5D,0x56};
bool UID_OK;
-
-int main() {
- rf.PCD_Init();
- while(1) {
- green = 0;
- if ( ! rf.PICC_IsNewCardPresent())
- {
- wait_ms(500);
- continue;
- }
- if ( ! rf.PICC_ReadCardSerial())
- {
- wait_ms(500);
- continue;
+
+int main()
+{
+ uint8_t hello[9] = "HELLO!!!";
+ size_t size = 9;
+ pc.printf("iniciando ethernet.... \n\r");
+ UIPEthernet.begin(MY_MAC, MY_IP);
+ pc.printf("ethernet iniciado ip: %03d.%03d.%03d.%03d \n\r", MY_IP[0], MY_IP[1], MY_IP[2], MY_IP[3]);
+ Client.connect(SERVER_IP, PORT);
+ pc.printf("conexion iniciada \n\r");
+ pc.printf("Enviando dato.... \n\r");
+ Client.write(hello,size);
+ pc.printf("dato enviado \n\r");
+ rf.PCD_Init();
+ while(1) {
+ green = 0;
+ if ( !rf.PICC_IsNewCardPresent()) {
+ wait_ms(500);
+ continue;
+ }
+ if ( ! rf.PICC_ReadCardSerial()) {
+ wait_ms(500);
+ continue;
+ }
+ pc.printf("Card UID: ");
+ UID_OK = true;
+ for (uint8_t i = 0; i < rf.uid.size; i++) {
+ pc.printf("%X", rf.uid.uidByte[i]);
+ if (UID_P[i] != rf.uid.uidByte[i]) {
+ UID_OK = false;
+ }
+ }
+ if (UID_OK) green = 1;
+ pc.printf("\n\r");
+ uint8_t piccType = rf.PICC_GetType(rf.uid.sak);
+ pc.printf("PICC Type: %s \n\r", rf.PICC_GetTypeName(piccType));
+
+ wait_ms(1000);
}
- pc.printf("Card UID: ");
- UID_OK = true;
- for (uint8_t i = 0; i < rf.uid.size; i++)
- {
- pc.printf("%X", rf.uid.uidByte[i]);
- if (UID_P[i] != rf.uid.uidByte[i]) UID_OK = false;
- }
- if (UID_OK) green = 1;
- pc.printf("\n\r");
- uint8_t piccType = rf.PICC_GetType(rf.uid.sak);
- pc.printf("PICC Type: %s \n\r", rf.PICC_GetTypeName(piccType));
- wait_ms(1000);
- }
}
-
\ No newline at end of file