I have a problem with my ESP8266 that I really can understand. I am currently working on a security system which i have to use some RFID cards to manage the access on a door.
So i have create an C# web api + SQL database to manage the person and each RFID card.
The web api is basic, you just have to send at "http:///api/values/" and you will get "GO" or "Deny" if you are or not in the data base.
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
const char* ssid = "yourNetworkName";
const char* password = "yourNetworkPassword";
void setup () {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print("Connecting..");
}
}
void loop() {
if (WiFi.status() == WL_CONNECTED) { //Check WiFi connection status
HTTPClient http; //Declare an object of class HTTPClient
http.begin("http://jsonplaceholder.typicode.com/users/1"); //Specify request destination
int httpCode = http.GET(); //Send the request
if (httpCode > 0) { //Check the returning code
String payload = http.getString(); //Get the request response payload
Serial.println(payload); //Print the response payload
}
http.end(); //Close connection
}
delay(30000); //Send a request every 30 seconds
}
...But as soon as i added the RFID code... the request it will not work any more...
the code looks like this
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 5
#define RST_PIN 4
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
const char* ssid = "mywifi";
const char* password = "Password";
void setup () {
Serial.begin(9600);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print("Connecting..");
}
SPI.begin(); // Initiate SPI bus
mfrc522.PCD_Init(); // Initiate MFRC522
}
void loop() {
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent())
{
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial())
{
return;
}
if (WiFi.status() == WL_CONNECTED) {
//Check WiFi connection status
HTTPClient http; //Declare an object of class HTTPClient
//http://<myip>/api/values/<cardCode>
http.begin("http://<192.168.1.5>/api/values/1231"); //THIS IS A TEST, IT SHOULD WORK WITHOUT ANY PROBLEM!
int httpCode = http.GET(); //Send the request
if (httpCode > 0) { //Check the returning code
String payload = http.getString(); //Get the request response payload
Serial.println(payload); //Print the response payload
[code] }
http.end(); //Close connection
}
delay(30000); //Send a request every 30 seconds
}
[/code]
The problem here is that my httpCode is return -1...and now response...
What i cannot understand is why...the ESP works...but without the MFRC522 library ?
Thank you in advance!