ToDo
- Arduino MKR WiFi 1010
- AdaFruit PN532 NFC/RFID controller breakout board
- AdaFruit Assembled Standard LCD 16x2
- Piezo Buzzer
- Push Button
- Potentiometer
- Adafruit_busIO
- WiFiNINA
- Adafruit_PN532
- LiquidCrystal
- ArduinoJson
- Create a secrets file:
$ touch badger/arduino_secrets.h
- Populate it with the following template:
#define SECRET_SSID ""
#define SECRET_PASS ""
#define IPADDRESS_SERVER ""
#define PORT
#define SCAN_URL ""
#define INIT_URL ""
#define TOKEN_POST ""
-
At the launch of the arduino, it sets up the NFC READER. If the set up failed it will stay blocked in an infinite loop.
So You need to relaunch the arduino. A message is printed on the LCD screen.
✅ : NFC Reader OK!
❎ : NFC Reader KO! -
Once the NFC READER is ok, it will try to connect to the Wifi with
SECRET_SSID
andSECRET_PASS
which are respectively the name of the wifi and the password of the wifi. ➡️ If the connection failed, it will try to reconnect indefinitely.
A message is printed on the LCD screen.
✅ : Wifi connect. OK!
❎ : Wifi connect. KO! -
Once the Wifi connection is setup it tries to connect to the server. It uses the
IPADDRESS_SERVER
andPORT
to connect. ➡️ If the connection failed, it will try to reconnect indefinitely. A message is printed on the LCD screen.
✅ : Server connect. OK!
❎ : Server connect. KO! -
Once all is connected, it tries to get all the modes. It sends a
HTTP request
to the server on theINIT_URL
page. It gets all the modes and put it in variables. A message is printed on the LCD screen.
✅ : Init. mode OK!
❎ : No Event... Then a countdown is displayed for the retry. -
After the init, we will attach an interrupt by
attachInterrupt()
method. In this way, we are able to change the mode anywhere we are in the code.
-
If the client isn't connected, we will try to reconnect it indefinitely.
-
The program is waiting for a card to read.
-
Reading card ✅
➡️ Create the HTTP request with theuid
of the card and the currentmode
to the server on theSCAN_PAGE
. -
Reading card ❎
➡️ Do nothing and go to the top of the loop function. -
Response from webapp ✅ (
201 CREATED
) : We get data from the server. Data will be inJSON
form so we need to deserialize them.
using ArduinoJSON library. -
Response from webapp ❎ : we disconnect the client and we try to reconnect.
This prevent us to read data from the response we don't want to. -
Deserialization ✅ : We get the
color
of the led, theboolean
for the buzzer and themessage
to display. -
Deserialization ❎ : We do nothing.
-
Display : the
color
is set on the LED, theboolean
sound is played on the buzzer and themessage
is displayed on the LCD Screen. Check if the Wifi is OK. If it's not the case try to reconnect indefinitely. It does the same after with the client. During those reconnections, theinterrupt
is disabled to prevent us from changing the mode involuntarily.