-1
My school work consists of a basic security system using card frequencies, in a similar way to buses: passes card in the reader, if the frequency is X releases the ratchet, if it is non-X the ratchet remains closed.
In my case, I approach a card from the reader and the key relay if I set your UID (card frequency) in the code:
if (conteudo.substring(1) == "40 C8 12 D9") //UID
{
Serial.println("Acesso liberado.");
...
}
else
{
Serial.println("Acesso negado.");
...
}
The problem is that the project should, in theory, be implemented on a large scale, IE, I can not store manually much more than 100 Uids (frequency of the card), Arduino does not have memory for this -- and would be a lot of work on several occasions.
What I did was create a form filled site, a local server with Apache, a database with Mariadb and phpMyAdmin.
My challenge now is to take a column of this database (which would be the registered Uids) and play in a variable to use in the Arduino code to look something like:
if (conteudo.substring(1) == "$variavel_UID") //Todas as UIDs da tabela
{
Serial.println("Acesso liberado.");
...
}
else
{
Serial.println("Acesso negado.");
...
}
That way, I would never need to mess with the Arduino code, only update the table that already entered automatically as a permissible value.
Things I’ve tried before:
<?php
$query = "SELECT tabela from `usuarios`";
$result = mysql_query($query);
$fetch = mysql_fetch_row($result);
$
?>
.
<?php
$sql="SELECT tabela FROM `usuarios`";
$records=mysqli_query($dbconnect,$sql);
$json_array=array();
while($row=mysqli_fetch_assoc($records))
{
$json_array[]=$row;
}
echo json_encode($json_array);
?>
.
<?php
$colunas = array();
$selectColunas = mysqli_query(
$conexao,
"SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'banco_de_dados' AND TABLE_NAME = 'tabela';"
);
while($coluna = mysqli_fetch_assoc($selectColunas)){
array_push($colunas, $coluna['COLUMN_NAME']) ;
}
print_r($colunas)
?>
And many others... I’ve been trying for a long time, but I’m not experienced in it and I don’t pay material on.
At first, I want to at least display the table results in an HTML/PHP page. Then I decide on the translation to Arduino code, but any advice on how to proceed with the project.
EDIT
I was able to show the Uids on a php page with the code:
<?php
session_start();
include_once("conexao.php")
?>
<html>
<head>
<title>JSON</title>
</head>
<body>
<?php
$dbselect = mysqli_select_db($connect, "Arduino");
$sql="SELECT frequencia FROM usuarios";
$records=mysqli_query($connect,$sql);
$json_array=array();
while($row=mysqli_fetch_assoc($records))
{
$json_array[]=$row;
}
echo json_encode($json_array);
?>
</body>
</html>
If someone knows how to improve and play for Arduino!
Is that when you said data_banco_de_data = validate.fetchmany(1)) you just said that, not that uid = UID0 you have tried to change the (validate = 1 if (uid in dados_frequencia) Else 0) instead of in, to not in to see what happens? it would also be interesting to print the frequency_data to know how it is formatted, if it is an array and etc, and it would also be interesting to see if in is actually detecting if an element is in an "array" for example: create a random array and check if a data that you know is in the array really is, with IN
– JassRiver
Friend, simply change your select so it already fetches the UID you want to validate, like this
validar.execute("SELECT frequencia FROM usuarios WHERE frequencia = 'UID1' ")
, so when executing the fetchall() command you only need to arrive if you returned something, if you returned it is because there is then released ta, if the fetchall returns empty then it does not exist, it does not release– Murilo Portugal
If you want to go this way then change that line of your code
validacao = 1 if (uid in dados_frequencia) else 0
for him to check with a for, as in the comment is not identado this site to put the code you should use. This is due to the fact that fetchall returns the data.– Murilo Portugal
Apparently I solved the problem. I deleted the for for dados_frequencia in dados_banco_de_dados: print (dates_frequencia) and subistitui the dados_banco_de_data = validate.fetchall() for data_frequency = [i[0] for i in list(validate)]. As far as I can Tell, all right. Thank you both so much for guiding me through the process, it really made a difference to someone who’s starting now!
– Noah Saulz