PPTIK FORUM
RFID dan RabbitMQ - Printable Version

+- PPTIK FORUM (http://forum.pptik.id)
+-- Forum: Learning Material (http://forum.pptik.id/forumdisplay.php?fid=1)
+--- Forum: Internet of Things (http://forum.pptik.id/forumdisplay.php?fid=2)
+---- Forum: Basic Internet of Things (http://forum.pptik.id/forumdisplay.php?fid=3)
+----- Forum: Absensi RFID (http://forum.pptik.id/forumdisplay.php?fid=626)
+----- Thread: RFID dan RabbitMQ (/showthread.php?tid=67803)



RFID dan RabbitMQ - obing - 09-12-2021

Pembahasan kali ini kita akan menguji pembacaan ID Tag RFID menggunakan Modul MFRC522 dan Nodemcu ESP8266.  Data ID dikirim ke RabbitMQ Server dan dibaca oleh Aplikasi Android MQTT RabbitMQ Client.
(Lihat hasil pengujian disini https://www.youtube.com/watch?v=DWGZvgzlmfY)


Sketch Arduino
Code:
const char* ssid        = "SSID";
const char* pass        = "PASSWORD";
const char* MQTTServer  = "SERVER";
const char* MQTTUser    = "USER";
const char* MQTTPass    = "PASSWORD";
const char* MQTTID      = "RFID01";
// Routing Key = "rfid"

#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 2
#define RST_PIN 0
MFRC522 mfrc522(SS_PIN, RST_PIN);
WiFiClient espClient;
PubSubClient client(espClient);
char ID[50];
String IDs;

void setup(){
  Serial.begin(9600);
  pinMode(2, OUTPUT);
  pinMode(4, OUTPUT);
  digitalWrite(2,LOW);
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, pass);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
    }
  client.setServer(MQTTServer, 1883);
  while (!client.connect(MQTTID, MQTTUser, MQTTPass)) {}
  digitalWrite(2,HIGH);
  SPI.begin();
  mfrc522.PCD_Init();
}

void loop() {
  client.loop();
  digitalWrite(4,HIGH);
  if ( ! mfrc522.PICC_IsNewCardPresent()){return;}
  if ( ! mfrc522.PICC_ReadCardSerial()){return;}
  String content= "";
  byte letter;
  for (byte i = 0; i < mfrc522.uid.size; i++) {
     content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
     content.concat(String(mfrc522.uid.uidByte[i], HEX));
  }
  if (content.length() > 0) {
      content.toUpperCase();
      IDs = content.substring(1);
      IDs.toCharArray(ID,50);
      client.publish("rfid",ID);
      digitalWrite(4,LOW);
      delay(1000);
  }

}