Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By silver boy
#63224 Hi
I want change this code add some thins , for example add Serial.print function but every time I got error

!
Code: Select all#include <SPI.h>
#include <MFRC522.h>
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <DNSServer.h>
#include <WiFiManager.h>

WiFiClient client;
ESP8266WebServer server(80);
String Argument_Name, Clients_Response1, Clients_Response2;

#define SS_PIN D4
#define RST_PIN D2
MFRC522 rfid(SS_PIN, RST_PIN);
void printHex(byte *buffer, byte bufferSize) {
  for (byte i = 0; i < bufferSize; i++) {
    Serial.print(buffer[i] < 0x10 ? " 0" : "");
    Serial.print(buffer[i], HEX);}
  }




void HandleClient() {
  server.send(200, "text/html", "test page");
}

void setup() {
  Serial.begin(115200);
  SPI.begin();
  rfid.PCD_Init();
  WiFiManager wifiManager;
  wifiManager.setTimeout(180);
  if (!wifiManager.autoConnect("ESP8266_AP")) {
    Serial.println("failed to connect and timeout occurred");
    delay(3000);
    ESP.reset(); //reset and try again
    delay(5000);
  }
  Serial.println("WiFi connected..");
  server.begin(); Serial.println("Webserver started...");
  Serial.print("Use this URL to connect: http://");
  Serial.print(WiFi.localIP()); Serial.println("/");
  Serial.println("teette");
  server.on("/", HandleClient);
 
 Serial.print("errorrrrr"); \\got error this line

}
void loop() {
  server.handleClient();
  if (!rfid.PICC_IsNewCardPresent()) return;
  if (!rfid.PICC_ReadCardSerial()) return;
  printHex(rfid.uid.uidByte, rfid.uid.size);
  Serial.println();
  rfid.PICC_HaltA();

Serial.print("errorrrrr"); \\or this one 
}


thank you
User avatar
By silver boy
#63332 I think the problem is rc522 code , because when comment the rfid code it run normally!
I dont know the problem ?!!

Code: Select all#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <SPI.h>
#include <MFRC522.h>

#define SS_PIN 10
#define RST_PIN 9
byte nuidPICC[4];
String uid="";
int i=0;

const char* ssid = "-";
const char* password = "-";
//MFRC522 rfid(SS_PIN, RST_PIN); // Instance of the class
//MFRC522::MIFARE_Key key;

ESP8266WebServer server(80);

void handleRoot() {
  server.send(200, "text/plain", "uid");
}

void handleNotFound() {
  String message = "File Not Found\n\n";
  message += "URI: ";
  message += server.uri();
  message += "\nMethod: ";
  message += (server.method() == HTTP_GET) ? "GET" : "POST";
  message += "\nArguments: ";
  message += server.args();
  message += "\n";
  for (uint8_t i = 0; i<server.args(); i++) {
    message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
  }
  server.send(404, "text/plain", message);
}


void setup() {
  Serial.begin(115200);
  WiFi.begin(ssid, password);
  Serial.println("");
  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  if (MDNS.begin("esp8266")) {
    Serial.println("MDNS responder started");
  }
  server.on("/", handleRoot);

  server.on("/inline", []() {
    server.send(200, "text/plain", "this works as well");
  });

  server.onNotFound(handleNotFound);

  server.begin();
  Serial.println("HTTP server started");
//  SPI.begin();
//  rfid.PCD_Init();

 
}

void loop() {
 
  //if (!rfid.PICC_IsNewCardPresent() || !rfid.PICC_ReadCardSerial())
  //  return;
  //uid = "";
  //for (byte i = 0; i < 4; i++) {
  //  nuidPICC[i] = rfid.uid.uidByte[i];
  //  uid += String(rfid.uid.uidByte[i], HEX);
  //}
  ////printHex(rfid.uid.uidByte, rfid.uid.size);
  //uid.toUpperCase();
  //Serial.println("uid : " + uid);
  //rfid.PICC_HaltA();

}