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: EthernetInterface ID12RFID mbed-rtos mbed
main.cpp
00001 00002 #include "mbed.h" 00003 #include "EthernetInterface.h" 00004 #include "ID12RFID.h" 00005 00006 ID12RFID rfid(p14); // uart rx 00007 EthernetInterface eth; 00008 //Here is the IP address of Server and port 00009 const char* ECHO_SERVER_ADDRESS = "130.207.234.205"; 00010 const int ECHO_SERVER_PORT = 7; 00011 00012 int main() { 00013 printf("Hello World\n"); 00014 eth.init(); //Use DHCP 00015 //print out the MAC address first 00016 printf("MAC Address is %s\n", eth.getMACAddress()); 00017 00018 while(1) { 00019 if(rfid.readable()) { 00020 int j=rfid.read(); 00021 //check if using right tag 00022 if (j==36902518){ 00023 printf("Right RFID, Here is the Monitor Info\r\n"); 00024 eth.connect(7000);//Longer timeout here 00025 printf("Client IP Address is %s\n", eth.getIPAddress()); 00026 TCPSocketConnection socket; 00027 //Begin Connecting the server, if not, print the error info 00028 while (socket.connect(ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT) < 0) { 00029 printf("Unable to connect to (%s) on port (%d)\n", ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT); 00030 wait(1); 00031 } 00032 //Begin receiving the data from server, and print out onto the terminal 00033 char buf[256]={0}; 00034 int n = socket.receive(buf, 256); 00035 buf[n] = '\0'; 00036 printf("%s", buf); 00037 socket.close(); 00038 eth.disconnect(); 00039 } 00040 //if not right tag, print out the error info and wait for another tag 00041 else 00042 printf("Wrong RFID Tag\r\n"); 00043 00044 printf("Wait for next RFID Tag\r\n"); 00045 } 00046 } 00047 }
Generated on Mon Jul 18 2022 08:24:51 by
1.7.2