When employees access a business using RFID tags, we additionally measure the employees ' body temperature using a non-contact infrared thermometer. If there is an elevated temperature (one of the symptoms of COVID19), access is blocked. In addition, all data (employee identification using RFID) is sent to the company's website, which tracks data on arrival time to work and body temperature (employee identification by UID RFID). LORAWAN The Things Network is used for sending data.
The project uses equipment provided by The Things Network:
We are very grateful to them for this.
Entering the cloud using RFID with temperature control
Viewing sent data from the cloud
Entering the office using RFID with temperature control
Step 1. The Things UnoWe use The Things Uno as the controller.
The Things Uno for organizing wireless communication over LoRa. it is based on the design of the Arduino Leonardo (not the Arduino UNO). Things Uno is based on the ATmega32u4 microcontroller. The Things Uno Board has a Microchip RN2483 transceiver for communication over the Larawan network, and there is also a built-in printed antenna for better communication.
To support the LARAWAN network, you need to install the TheThingsNetwork library to get easy-to-use methods for connecting to the network and sending data.
Since there are no available points in my region to connect The Things Uno to the Larawan network, you must install and configure The Things Tndoor Gateway as a gateway.
Instructions for activating The Things Indoor Gateway and connecting to The Things Network Backend can be found on the page https://www.thethingsnetwork.org/docs/gateways/thethingsindoor/.
Connecting to the Things Network server
First we register in the Things Network service (www.thethingsnetwork.org). Then you need to log in to your profile and register the gateway. Click on the button Setup a gateway
To connect this gateway to the Things Network console, register the gateway using The I'm using the Legacy Packet Forwarder option.
Gateway EUI can be obtained from the WiFi settings page.
This value must be entered in the Gateway EUI on the console.
Enter other data such as location, frequency plan and router.
If your configuration was successful, you will see the Status connected
The gateway is connected to the service. We can connect to it with Lora devices.
Step 3. Connecting an IR temperature sensor MLX90614 to The Things UnoThe MLX90614 is an infrared sensor for non-contact temperature measurement. It can measure temperatures in the range of -70 to 380 degrees Celsius with an accuracy of about 0.5°C. I had MLX90614DAA in stock
The sensor uses the I2C Protocol. Assign contacts
Connection diagram to The Things Uno
For programming, we use the Adafruit_MLX90614.h library, which must be installed via Manager Libraries (Sketch > Include library > Manager Libraries). Upload a sketch to the Arduino Board
// Connecting libraries
#include <Wire.h>
#include <Adafruit_MLX90614.h>
// Creating an instance of an object
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
void setup() {
Serial.begin(9600);
Serial.println("start");
// starting the MLX90614 sensor
mlx.begin();
}
void loop() {
Serial.print("Ambient = "); Serial.print(mlx.readAmbientTempC());
Serial.print("*C");
Serial.print("\tObject = "); Serial.print(mlx.readObjectTempC());
Serial.print("*C");
Serial.print("\tObject = "); Serial.print(mlx.readObjectTempF());
Serial.println("*F");
delay(3000);
}
And open the serial port monitor. The ambient temperature and object temperature are output to the serial port every 3 seconds
There is a wide variety of RFID tags. Tags are active and passive (without a built-in power source, powered by a current induced in the antenna by a signal from the reader). Tags work at different frequencies: LF (125 - 134 kHz), HF (13.56 MHz), UHF (860 - 960 MHz). Devices that read information from tags and write data to them are called readers. In Arduino projects, the RFID-RC522 module is very often used as a reader. The module is made on the MFRC522 chip of the NSP company, which provides work with RA tags (at a frequency of 13.56 MHz).
Connecting the rc522 RFID reader module to The Things Uno via SPI Protocol
Sketch of UID detection for an RFID card and temperature measurement
// Connecting libraries
#include <SPI.h>
#include <MFRC522.h>
#include <Wire.h>
#include <Adafruit_MLX90614.h>
MFRC522 mfrc522(10, 9);
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
byte cardUID[4] = {0,0,0,0};
float mytemp=0.0;
void setup() {
//
Serial.begin(9600);
// SPI
SPI.begin();
// MFRC522
mfrc522.PCD_Init();
// starting the MLX90614 sensor
mlx.begin();
// Wait a maximum of 10s for Serial Monitor
while (!Serial && millis() < 10000)
;
}
void loop() {
if ( mfrc522.PICC_IsNewCardPresent()) {
// .
if ( mfrc522.PICC_ReadCardSerial()) {
// UID
Serial.print(F("Card UID:"));
for (byte i = 0; i < 4; i++) {
cardUID[i]=mfrc522.uid.uidByte[i];
Serial.print(cardUID[i],HEX);
}
Serial.println();
// Print a message to the LCD.
get_temperature();
Serial.print("t=");
Serial.println(mytemp);
delay(2000);
}
mfrc522.PICC_HaltA();
mfrc522.PCD_StopCrypto1();
}
}
// get temperature
boolean get_temperature() {
int count=0;
float sumtemp=0.0;
unsigned long millist=millis();
do {
float t=mlx.readObjectTempC();
if(t>34.0 && t<42.0) {
count++;
sumtemp=sumtemp+t;
}
}while(millis()-millist<5000 || count<5);
if(count<5) {
mytemp=0.0;
return false;
}
else {
mytemp=sumtemp/count;
return true;
}
}
Now you need to connect a display and a relay that will issue a command to allow an employee to enter the company. We use WH1602 I2C as the display. Display and relay connection diagram
To send data over the network LORAWAN, add the library to the connection sketch and enter the data from our application,
#include <TheThingsNetwork.h>
// Set your AppEUI and AppKey
const char *appEui = "70B3D57ED00313E5";
const char *appKey = "FAFA472FB54FFE967CE63F5EE056F6D7";
#define loraSerial Serial1
#define debugSerial Serial
// Replace REPLACE_ME with TTN_FP_EU868 or TTN_FP_US915
#define freqPlan TTN_FP_EU868
TheThingsNetwork ttn(loraSerial, debugSerial, freqPlan);
And the entire sketch with sending unformatted data to the service thethingsnetwork.org
// Connecting libraries
#include <SPI.h>
#include <MFRC522.h>
#include <TheThingsNetwork.h>
#include <Wire.h>
#include <Adafruit_MLX90614.h>
#include <LiquidCrystal_I2C.h>
// Set your AppEUI and AppKey
const char *appEui = "70B3D57ED00313E5";
const char *appKey = "FAFA472FB54FFE967CE63F5EE056F6D7";
#define loraSerial Serial1
#define debugSerial Serial
// Replace REPLACE_ME with TTN_FP_EU868 or TTN_FP_US915
#define freqPlan TTN_FP_EU868
TheThingsNetwork ttn(loraSerial, debugSerial, freqPlan);
MFRC522 mfrc522(10, 9);
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
LiquidCrystal_I2C lcd(0x27,16,2);
byte cardUID[4] = {0,0,0,0};
byte payload[6] = {0,0,0,0,0,0};
float mytemp=0.0;
int pin_relay=12;
void setup() {
//
loraSerial.begin(57600);
debugSerial.begin(9600);
// display
lcd.init();
lcd.backlight();
lcd.clear();
// SPI
SPI.begin();
// MFRC522
mfrc522.PCD_Init();
// starting the MLX90614 sensor
mlx.begin();
// relay
pinMode(pin_relay, OUTPUT);
digitalWrite(pin_relay, LOW);
// Wait a maximum of 10s for Serial Monitor
while (!debugSerial && millis() < 10000)
;
debugSerial.println("-- STATUS");
ttn.showStatus();
debugSerial.println("-- JOIN");
ttn.join(appEui, appKey);
// Print a message to the LCD.
lcd.setCursor(0,0);
lcd.print("Wait card....");
}
void loop() {
if ( mfrc522.PICC_IsNewCardPresent()) {
// .
if ( mfrc522.PICC_ReadCardSerial()) {
// UID
Serial.print(F("Card UID:"));
for (byte i = 0; i < 4; i++) {
cardUID[i]=mfrc522.uid.uidByte[i];
debugSerial.print(cardUID[i],HEX);
}
debugSerial.println();
debugSerial.println("-- LOOP");
// Prepare payload of 1 byte to indicate LED status
//byte payload[6];
payload[0] = cardUID[0];
payload[1] = cardUID[1];
payload[2] = cardUID[2];
payload[3] = cardUID[3];
//
// Print a message to the LCD.
lcd.setCursor(0,0);
lcd.print("Gett temp ..");
if(get_temperature()) {
send_ttn(mytemp);
if(mytemp>37.0) {
// close
digitalWrite(pin_relay, LOW);
lcd.setCursor(0,0);
lcd.print("CLOSE !!!!!!! ..");
delay(2000);
}
else {
// open
digitalWrite(pin_relay, HIGH);
lcd.setCursor(0,0);
lcd.print("OPEN !!!!!!! ..");
delay(5000);
digitalWrite(pin_relay, LOW);
}
}
debugSerial.print("t=");
debugSerial.println(mytemp);
// Print a message to the LCD.
lcd.setCursor(0,0);
lcd.clear();
lcd.print("Wait card....");
delay(2000);
}
mfrc522.PICC_HaltA();
mfrc522.PCD_StopCrypto1();
}
}
In The Thing Network console we enter the function decoding incoming data
function Decoder(bytes, port) {
var decoded = {};
if (port === 1) {
decoded.uid = (bytes[0]<<24)+(bytes[1]<<16)+(bytes[2]<<8)+bytes[3];
var temperatureInt = bytes[4];
var temperatureDecimal = bytes[5];
var temperature = temperatureInt + "." + temperatureDecimal;
decoded.temp = parseFloat(temperature);
}
return decoded;
}
Now we see incoming data in the Data tab (json format)
We will redirect data over HTTP to the resource we need.
Example of data coming to our server
{"app_id":"test_pyatigorsk_mira","dev_id":"pyatigorsk_mira_device01","hardware_serial":"0004A30B001C3FB6","port":1,"counter":0,"payload_raw":"Wk+LGSIx","payload_fields":{"temp":34.49,"uid":1515162393},"metadata":{"time":"2020-07-06T11:48:22.534496336Z","frequency":867.7,"modulation":"LORA","data_rate":"SF7BW125","coding_rate":"4/5","gateways":[{"gtw_id":"eui-58a0cbfffe80125c","timestamp":681777324,"time":"2020-07-06T11:48:22.433408975Z","channel":0,"rssi":-42,"snr":9.25,"rf_chain":0}]},"downlink_url":"https://integrations.thethingsnetwork.org/ttn-eu/api/v2/down/test_pyatigorsk_mira/test01?key=ttn-account-v2.iGsvHMLzmrCXJ1p6D9u2Tm1x-yoHo3y0feranDWkqGg"}
Step 8. Creating a database of employees on the company's website and a database for collecting daily temperature readings at the entranceCreating a database on hosting (MySQL) and two tables in it:
- users - employee data and their uid;
- temp - for collecting data of the body temperature measured at the input.
Script get_temp2.php sends the employee's temperature to the database
The contents of the script get_temp2.php
<?php
//
$location="localhost";
$user="************";
$pass="************";
$db_name="************";
// connect db
if(! $db=mysqli_connect($location,$user,$pass,$db_name))
{echo "connect error";}
else
{;}
$contentType = isset($_SERVER["CONTENT_TYPE"]) ? trim($_SERVER["CONTENT_TYPE"]) : '';
if(strcasecmp($contentType, 'application/json') != 0){
echo 'Content type must be: application/json';
}
//Receive the RAW post data.
$content = trim(file_get_contents("php://input"));
//write post data to file for debug, you need to create data2.txt in the same folder as ttnpost2
file_put_contents('json', $content . PHP_EOL, FILE_APPEND);
//Attempt to decode the incoming RAW post data from JSON.
$decoded = json_decode($content, true);
$filed = "json";
//file_put_contents($filed, " ".date('Y-m-d H:i:s').$decoded[payload_fields]['temp']." ".dechex($decoded['payload_fields']['uid']));
$query0=" SELECT * FROM users WHERE uid='".dechex($decoded['payload_fields']['uid'])."' ";
$rez0=mysqli_query($db,$query0);
if(mysqli_num_rows($rez0)>0) {
$row0=mysqli_fetch_assoc($rez0);
$query1=" INSERT INTO temp SET
id_user='".$row0['id']."',
temp='".$decoded[payload_fields]['temp']."',
day='".date('Y-m-d H:i:s')."' ";
mysqli_query($db,$query1);
echo "#yes";
}
else {
echo "#no";
}
?>
To view the data sent to the server, open the site page. The contents of the script to output a page file view_temp.php
<?php
//
$location="localhost";
$user="********";
$pass="********";
$db_name="********";
// connect db
if(! $db=mysqli_connect($location,$user,$pass,$db_name))
{echo "connect error";}
else
{;}
$query0=" SELECT * FROM temp WHERE uid='".$_GET['uid']."' ";
$rez0=mysqli_query($db,$query0);
$content1.=date('Y-m-d')."<br><br>";
$content1.="<table>";
$query1="SELECT * FROM temp WHERE day >= CURDATE() ";
$rez1=mysqli_query($db,$query1); $i=1;
while($row1=mysqli_fetch_assoc($rez1)) {
$content1.="<tr>";
$content1.="<td>".$i."</td>";
$rez2=mysqli_query($db,"SELECT name FROM users WHERE id =".$row1['id_user']." ");
$row2=mysqli_fetch_assoc($rez2);
$content1.="<td>".$row2['name']."</td>";
$content1.="<td>".mb_substr($row1['day'],10,9)."</td>";
if($row1['temp']>37.5)
$content1.="<td style='background-color:red'>".$row1['temp']."</td>";
else
$content1.="<td>".$row1['temp']."</td>";
$content1.="</tr>";
$i++;
}
$content1.="</table>";
echo $content1;
?>
Comments