Commit 1f909f1e authored by simon.nutsey's avatar simon.nutsey

Add new file

parent 0c89118b
#include <ESP8266WiFi.h>
#include <SPI.h>
#include <MFRC522.h>
#include "ThingSpeak.h";
constexpr uint8_t RST_PIN = D3; //reset pin set
constexpr uint8_t SS_PIN = D4; //slave pin set
MFRC522 rfid(SS_PIN, RST_PIN);
MFRC522::MIFARE_Key key;
const char* ssid = "VM8257564"; //wifi ssid
const char* pass = "Qx6nqdyv4hhy"; //wifi pass
int connectledPin = D8; //Blue led when connected to internet
int unconnectledPin = D1; //Red let when not connected to internet
WiFiClient client;
const unsigned long channel_id = 1223547; //Thing Speak channel id
const char write_api_key[] = "7JWC5PW2TW4YQ10L"; //Thing Speak write api key
String tag; //define "Tag" as a string
void setup()
{
pinMode(connectledPin,OUTPUT); //Set both LEDs to output
pinMode(unconnectledPin, OUTPUT);
digitalWrite(connectledPin,LOW);
digitalWrite(unconnectledPin, HIGH); //When starting Blue LED off Red LED on
Serial.begin(9600);
delay(10);
Serial.println("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, pass);
Serial.println();
Serial.println("Connecting");
SPI.begin(); // Init SPI bus // Attempt to connect to the wifi
rfid.PCD_Init(); // Init MFRC522
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
digitalWrite(connectledPin, HIGH);
digitalWrite(unconnectledPin, LOW);
Serial.println("");
Serial.println("You are now connected to ");
Serial.println(ssid);
ThingSpeak.begin(client);
}
void loop() {
if ( ! rfid.PICC_IsNewCardPresent())
return;
if (rfid.PICC_ReadCardSerial()) { //when a card is detected print its ID value
for (byte i = 0; i < 4; i++) {
tag += rfid.uid.uidByte[i];
}
Serial.println(tag);
if (tag =="160248110163") {
Serial.println("Access Granted"); //If statment. If ID scanned = 160248110163 then write to thing speak. More ids can be added should the need arise
ThingSpeak.setField(3, String(tag));
ThingSpeak.writeFields(channel_id, write_api_key);
}
tag = "";
rfid.PICC_HaltA();
rfid.PCD_StopCrypto1();
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment