Here's my code:
#include <Arduino.h>
#include <SPI.h>
#include <mfrc630.h>
#include <ESP8266WiFi.h>
const char* ssid = "XXXXXXXXXXXX";
const char* password = "XXXXXXXXXXX";
#define CHIP_SELECT 5
IPAddress server(XXXXXXXXXX);
WiFiClient client;
int startmillis;
int startmillis1;
int hit1;
unsigned long currentmillis3;
unsigned long currentmillis4;
const unsigned long period = 30000;
const unsigned long interval4 = 100000;
void mfrc630_SPI_transfer(const uint8_t* tx, uint8_t* rx, uint16_t len) {
for (uint16_t i=0; i < len; i++){
rx[i] = SPI.transfer(tx[i]);
}
}
void mfrc630_SPI_select() {
SPI.beginTransaction(SPISettings(10000000, MSBFIRST, SPI_MODE0)); // gain control of SPI bus
digitalWrite(CHIP_SELECT, LOW);
}
void mfrc630_SPI_unselect() {
digitalWrite(CHIP_SELECT, HIGH);
SPI.endTransaction(); // release the SPI bus
}
void mfrc630_MF_example_dump_arduino() {
uint16_t atqa = mfrc630_iso14443a_REQA();
if (atqa != 0) {
client.println(hit1);
}
}
void setup() {
WiFi.begin(ssid, password);
if (WiFi.status() != WL_CONNECTED) {
currentmillis3 = millis();
static long prevmilll = 0;
if (currentmillis3 - prevmilll >= period) {
if (WiFi.status() != WL_CONNECTED) {
digitalWrite(4, LOW);
} else {
prevmilll = currentmillis3;
}
}
}
// Set the chip select pin to output.
pinMode(CHIP_SELECT, OUTPUT);
// Start the SPI bus.
SPI.begin();
pinMode(15, OUTPUT);
digitalWrite(15,LOW);
// Set the registers of the MFRC630 into the default.
mfrc630_AN1102_recommended_registers(MFRC630_PROTO_ISO14443A_106_MILLER_MANCHESTER);
// This are register required for my development platform, you probably have to change (or uncomment) them.
mfrc630_write_reg(0x28, 0x8E);
mfrc630_write_reg(0x29, 0x15);
mfrc630_write_reg(0x2A, 0x11);
mfrc630_write_reg(0x2B, 0x06);
}
void loop() {
if(!client.connected()){
digitalWrite(15,LOW);
client.connect(server,1980);
client.println("RC006\r");
startmillis1 = millis();
static long prevmill4 = 0;
if (startmillis1 - prevmill4 >= period) {
if(!client.connected()){
digitalWrite(4, LOW);
}prevmill4 = startmillis1;}
}else{
currentmillis4 = millis();
static long prevmill4 = 0;
if (currentmillis4 - prevmill4 >= interval4) {
client.println("RC006\r");
prevmill4 = currentmillis4;
}
digitalWrite(15, HIGH);
int hit = analogRead(A0);
delay(3);
hit1 = hit * (33 / 1024.0);
if(hit1 > 5){
mfrc630_MF_example_dump_arduino();
}
}
}