20
20
21
21
#include < SPI.h>
22
22
#include " MFRC522.h"
23
- #define RST_PIN 0 // RST-PIN for RC522 - RFID - SPI - Modul GPIO0 - D3
23
+ #define RST_PIN 0 // RST-PIN for RC522 - RFID - SPI - Modul GPIO0 - D3
24
24
#define SS_PIN 2 // SDA-PIN for RC522 - RFID - SPI - Modul GPIO2 - D4
25
25
26
26
27
27
// define your default values here, if there are different values in config.json, they are overwritten.
28
- // length should be max size + 1
28
+ // length should be max size + 1
29
29
char odoo_host[90 ];
30
30
char odoo_port[6 ] = " 8069" ;
31
31
char odoo_user[33 ] = " admin" ;
@@ -62,7 +62,7 @@ void setup() {
62
62
pinMode (RED_LED, OUTPUT);
63
63
pinMode (GREEN_LED, OUTPUT);
64
64
SPI.begin (); // Init SPI bus
65
- mfrc522.PCD_Init (); // Init MFRC522
65
+ mfrc522.PCD_Init (); // Init MFRC522
66
66
67
67
// clean FS, for testing
68
68
// SPIFFS.format();
@@ -125,7 +125,7 @@ void setup() {
125
125
126
126
// set config save notify callback
127
127
wifiManager.setSaveConfigCallback (saveConfigCallback);
128
-
128
+
129
129
// add all your parameters here
130
130
wifiManager.addParameter (&custom_odoo_host);
131
131
wifiManager.addParameter (&custom_odoo_port);
@@ -139,7 +139,7 @@ void setup() {
139
139
// set minimu quality of signal so it ignores AP's under that quality
140
140
// defaults to 8%
141
141
wifiManager.setMinimumSignalQuality ();
142
-
142
+
143
143
// sets timeout until configuration portal gets turned off
144
144
// useful to make it all retry or go to sleep
145
145
// in seconds
@@ -195,46 +195,43 @@ void setup() {
195
195
Serial.println (WiFi.subnetMask ());
196
196
Serial.println (WiFi.SSID ());
197
197
198
- // Definindo server mqtt do Client
198
+ // Set mqtt server data
199
199
client.setServer (mqtt_server, mqtt_port);
200
-
201
- // Definindo método callback que irá receber os callbacks do client criado.
200
+
202
201
client.setCallback (callback);
203
202
204
203
Serial.println (F (" Ready!" ));
205
- Serial.println (F (" ======================================================" ));
204
+ Serial.println (F (" ======================================================" ));
206
205
Serial.println (F (" Scan for Card and print UID:" ));
207
206
}
208
207
209
208
void conectMqtt () {
210
- while (!client.connected ()) {
211
- Serial.print (" ConectandoQTT ..." );
212
-
213
- // Parametros são nodeMCUClient, usuárioMQTT, senhaMQTT
209
+ while (!client.connected ()) {
210
+ Serial.print (" ConnectingMQTT ..." );
211
+
212
+ // Parameters nodeMCUClient, userMQTT, passwordMQTT
214
213
if (client.connect (" MqttClient" ," MqttUser" ," MqttPass" )) {
215
- Serial.println (" Conectado " );
216
- // Inscrevendo-se no tópico retorno.
214
+ Serial.println (" Connected " );
215
+ // Subscriing to topic retorno.
217
216
client.subscribe (" retorno" );
218
217
} else {
219
- Serial.print (" Falha " );
220
- Serial.print (client.state ());
221
- Serial.println (" Tentando novamente em 5 segundos " );
218
+ Serial.print (" Error " );
219
+ Serial.print (client.state ());
220
+ Serial.println (" Retry in 5 seconds " );
222
221
// Wait 5 seconds before retrying
223
222
delay (5000 );
224
223
}
225
224
}
226
225
}
227
226
228
- // Método que foi definido para receber os retornos dos tópicos que demos subscribe,
229
- // neste caso apenas o tópico 'retorno'
230
- // Parametros: NomedoTópico, mensagem , tamanho da mensagem
227
+ // Parameters: topic_name, msg , msg length
231
228
void callback (char * topic, byte* payload, unsigned int length) {
232
229
Serial.println ();
233
- Serial.print (" Messagembida [" );
230
+ Serial.print (" Welcome [" );
234
231
Serial.print (topic);
235
232
Serial.print (" ]: " );
236
233
String mensagem = " " ;
237
- // Conversão da mensagem recebidade de byte pra String
234
+ // Convert msg from byte to string
238
235
for (int i = 0 ; i < length; i++) {
239
236
mensagem += (char )payload[i];
240
237
}
@@ -272,7 +269,7 @@ void loop() {
272
269
delay (3000 );
273
270
ESP.reset ();
274
271
delay (5000 );}
275
-
272
+
276
273
// Look for new cards
277
274
if ( ! mfrc522.PICC_IsNewCardPresent ()) {
278
275
delay (50 );
@@ -289,7 +286,7 @@ void loop() {
289
286
dump_byte_array (mfrc522.uid .uidByte , mfrc522.uid .size );
290
287
Serial.println ();
291
288
}
292
-
289
+
293
290
}
294
291
295
292
// Helper routine to dump a byte array as hex values to Serial
@@ -299,16 +296,16 @@ void dump_byte_array(byte *buffer, byte bufferSize) {
299
296
for (byte i = 0 ; i < bufferSize; i++) {
300
297
Serial.print (buffer[i] < 0x10 ? " 0" : " " );
301
298
Serial.print (buffer[i], HEX);
302
- // Conversão de byte pra Hexadecimal
303
- sprintf (s," %s%x" ,buffer[i] < 0x10 ? " 0" : " " ,mfrc522.uid .uidByte [i]);
304
- // Concatenando para o array de char que será enviado
299
+ // Convert from byte to Hexadecimal
300
+ sprintf (s," %s%x" ,buffer[i] < 0x10 ? " 0" : " " ,mfrc522.uid .uidByte [i]);
301
+ // Concatenate msg
305
302
strcat ( &rfidstr[i] , s);
306
303
}
307
304
char buf[512 ];
308
305
snprintf (buf, sizeof buf, " %s###%s###%s###%s###%s###%s" , odoo_host, odoo_port, odoo_user, odoo_password, odoo_database, rfidstr);
309
306
currentCard = rfidstr;
310
- client.publish (" acesso" , buf);
311
- Serial.println (" Verificando ..." );
307
+ client.publish (" acesso" , buf);
308
+ Serial.println (" Verifing ..." );
312
309
}
313
310
314
311
0 commit comments