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: MFRC522 MQTT TextLCD WIZnetInterface mbed-src
Fork of MFRC522_Reader_Program by
main.cpp
00001 //Test of cheap 13.56 Mhz RFID-RC522 module from eBay 00002 //This code is based on Martin Olejar's MFRC522 library. Minimal changes 00003 //Adapted for Nucleo STM32 F401RE. Should work on other Nucleos too 00004 00005 //Connect as follows: 00006 //RFID pins -> Nucleo header CN5 (Arduino-compatible header) 00007 //---------------------------------------- 00008 //RFID IRQ=pin5 -> Not used. Leave open 00009 //RFID MISO=pin4 -> Nucleo SPI_MISO=PA_6=D12 00010 //RFID MOSI=pin3 -> Nucleo SPI_MOSI=PA_7=D11 00011 //RFID SCK=pin2 -> Nucleo SPI_SCK =PA_5=D13 00012 //RFID SDA=pin1 -> Nucleo SPI_CS =PB_6=D10 00013 //RFID RST=pin7 -> Nucleo =PA_9=D8 00014 //3.3V and Gnd to the respective pins 00015 00016 #include "mbed.h" 00017 #include "MFRC522.h" 00018 #include "MQTTEthernet.h" 00019 #include "MQTTClient.h" 00020 #include <sstream> 00021 #include <string> 00022 #define ECHO_SERVER_PORT 7 00023 00024 00025 Serial out(USBTX,USBRX); 00026 int arrivedcount = 0; 00027 char RFIDTagMessage[20]="Hello!!!!!"; 00028 00029 void messageArrived(MQTT::MessageData& md) 00030 { 00031 MQTT::Message &message = md.message; 00032 out.printf("Message arrived: qos %d, retained %d, dup %d, packetid %d\n", message.qos, message.retained, message.dup, message.id); 00033 out.printf("Payload %.*s\n", message.payloadlen, (char*)message.payload); 00034 ++arrivedcount; 00035 } 00036 00037 void baud(int baudrate) 00038 { 00039 Serial s(USBTX, USBRX); 00040 s.baud(baudrate); 00041 } 00042 char* store_buf; 00043 00044 int main(void) 00045 { 00046 char* topic="arrive"; 00047 out.printf("starting...\n"); 00048 MQTTEthernet ipstack = MQTTEthernet(); 00049 00050 00051 out.printf("\n\r"); 00052 store_buf=RFIDTagMessage; 00053 out.printf("Stored variable: %s",store_buf); 00054 00055 if(store_buf[10]!='\0') { 00056 MQTT::Client<MQTTEthernet, Countdown> client = MQTT::Client<MQTTEthernet, Countdown>(ipstack); 00057 char* hostname = "172.16.73.4"; 00058 int port = 1883; 00059 int rc = ipstack.connect(hostname, port); 00060 out.printf("rc from TCP connect is %d\n", rc); 00061 if (rc != 0) 00062 out.printf("rc from TCP connect is %d\n", rc); 00063 char MQTTClientID[30]; 00064 MQTTPacket_connectData data = MQTTPacket_connectData_initializer; 00065 data.MQTTVersion = 3; 00066 out.printf(MQTTClientID,"WIZwiki-W7500-client-%d",rand()%1000); 00067 data.clientID.cstring = MQTTClientID; 00068 data.username.cstring = "testuser"; 00069 data.password.cstring = "testpassword"; 00070 00071 if ((rc = client.connect(data)) != 0) 00072 out.printf("rc from MQTT connect is %d\n", rc); 00073 00074 if ((rc = client.subscribe(topic, MQTT::QOS1, messageArrived)) != 0) 00075 out.printf("rc from MQTT subscribe is %d\n", rc); 00076 00077 MQTT::Message message; 00078 00079 while(true){ 00080 message.qos = MQTT::QOS0; 00081 message.retained = false; 00082 message.dup = false; 00083 00084 message.payload = (void*)RFIDTagMessage; 00085 message.payloadlen = strlen(RFIDTagMessage); 00086 00087 rc = client.publish("test", message); 00088 out.printf("Rc result: % d ",rc); 00089 // client.yield(60000); 00090 } 00091 } 00092 }
Generated on Mon Jul 18 2022 02:18:53 by
1.7.2
