I am trying to send MFRC522 data to a C# application through a NodeMCU acting as an access point for the C# app. I have modified the code I got from this site.
#include ESP8266WiFi.h>
#include SPI.h>
#include MFRC522.h>
const char* AP_SSID ="IoT4143" ;
const char* AP_PASSWORD ="iot4143";
#define RST_PIN D3
#define SS_PIN D4
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
WiFiServer server(80);
WiFiClient client;
void wifiConnect() {
WiFi.disconnect();
WiFi.softAP(AP_SSID, AP_PASSWORD);
int watchDog = 0;
while (WiFi.status() != WL_CONNECTED) {
delay(500);
watchDog++;
if(watchDog == 60) {
WiFi.disconnect();
WiFi.printDiag(Serial);
watchDog = 0;
return;
}
}
server.begin();
}
void setup() {
Serial.begin(115200);
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522
mfrc522.PCD_DumpVersionToSerial(); // Show details of PCD - MFRC522 Card Reader details
Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
wifiConnect();
}
void loop() {
//Are we connected to WiFi?
if(WiFi.status() != WL_CONNECTED) {
wifiConnect();
}
//Wait for a connection attempt
client = server.available();
if (!client) {
return;
}
// Wait until the client sends some data
int watchDog = 0;
while(!client.available()) {
delay(1);
if(watchDog == 10000) {
watchDog = 0;
return;
}
watchDog++;
}
sendData();
}
void sendData() {
// Read the first line of the request
String request = client.readStringUntil('\r');
client.flush();
// Match the request
while(request=="READSTOP") {
Serial.println("RFID READING STARTED..."); //Forward to C# App
if (!mfrc522.PICC_IsNewCardPresent()) {
return;
}
// Select one of the cards
if (!mfrc522.PICC_ReadCardSerial()) {
return;
}
// Dump debug info about the card; PICC_HaltA() is automatically called
client.print(mfrc522.uid));
}
Serial.println("RFID READING STOPPED"); //Stop server
delay(1);
client.stop();
}
I am very new to hardware/network programming. I don't know what will be possible errors in this code and whether it will work or not.
When I verified the code in the Arduino IDE, there was an error on this line of code:
client.print(mfrc522.uid));
error:= no matching function for call to 'WiFiClient::print(MFRC522::Uid&)'
When the connect button in the application is clicked the "READSTART" string is sent to NodeMCU and when disconnect is clicked the "READSTOP" string is sent.
Please help!
client.print(mfrc522.uid));How many opening and closing parentheses do you count in that line? Hmm...?