# Installation : pi + VMA405 ou RC522
## 1 - Cloner le projet

## 2 - Créer une image
- PI OS Lite LEGACY
- Utilisateur = sysop
- Wifi
- SSH

- Lancer le logiciel "Raspberry Pi Imager v1.7.3" puis "shift + Ctrl + Alt"   
<img src="./images/imager_hostname_ssh.png" height="400" width="auto">   
<img src="./images/imager_user_wifi.png" height="400" width="auto">   
<img src="./images/imager_wifi2_locale.png" height="400" width="auto">   
<img src="./images/imager_image_systeme.png" height="400" width="auto">  

## Copie de la clef ssh publique de l'hote  sur le pi
```
cd /home/userHote/.ssh
ssh-copy-id -i id_rsa.pub sysop@192.168.19
```

## Installer ansible (sur ubuntu)
```
sudo apt install software-properties-common
sudo apt-add-repository --yes --update ppa:ansible/ansible
sudo apt install ansible
```

## 3 - Ansible(hôte), créer l'inventaire des clients(raspberry pi)
- Soit un pi avec le hostname "pi10pouces01"
```
sudo nano /etc/ansible/hosts
```
retour:
```
pi10pouces01 ansible_host=192.168.1.9 hostname=pi10pouces01 token=xxxxxxxxxxxx password=xxxxxxxxxxxx frontType=FPI serveur=django.local.org protocole=http
```
- Lister les machines qui sont gérées:
  ansible-inventory --list -y

- tester (utilisateur sysop):
  ansible pi10pouces01 -m ping -u sysop

## 4 - Ansible(hôte) installation des machines
- Modifier le nom du groupe de pi ou le nom du pi à installer dans le fichier "install_1024x600_vma405_chromium.yml",   
  ligne 2 (- hosts: )   


- A la racine du projet
```
ansible-playbook install_1024x600_vma405_chromium.yml -K
```

# Informations

## Pin raspberry pi 3 b+ 
<table>
  <tbody>
    <tr>
      <td>côté usb</td><td>39</td><td>37</td><td>35</td><td>33</td><td>31</td><td>29</td><td>27</td><td>25</td><td>23</td><td>21</td><td>19</td><td>17</td><td>15</td><td>13</td><td>11</td><td>9</td><td>7</td><td>5</td><td>3</td><td>1</td><td>côté sdcar</td>
    </tr>
    <tr>
      <td>reseau</td><td>40</td><td>38</td><td>36</td><td>34</td><td>32</td><td>30</td><td>28</td><td>26</td><td>24</td><td>22</td><td>20</td><td>18</td><td>16</td><td>14</td><td>12</td><td>10</td><td>8</td><td>6</td><td>4</td><td>2</td> 
    </tr>
  </tbody>
</table>

## Cablage VMA405 ou RC522
### VMA405
<img src="./vma405.jpg" height="400" width="auto">

### RC522
<img src="./rfid_rc522.jpg" height="400" width="auto">

<table>
  <tbody>
    <tr>
      <td>côté usb</td><td>39</td><td>37</td><td>35</td><td>33</td><td>31</td><td>29</td><td>27</td><td>25</td><td>SCK</td><td>MISO</td><td>MOSI</td><td>17</td><td>15</td><td>13</td><td>11</td><td>GND</td><td>7</td><td>5</td><td>3</td><td>vcc</td> 
    </tr>
    <tr>
      <td>reseau</td><td>40</td><td>38</td><td>36</td><td>34</td><td>32</td><td>30</td><td>28</td><td>26</td><td>NSS</td><td>RST</td><td>20</td><td>18</td><td>16</td><td>14</td><td>12</td><td>10</td><td>8</td><td>6</td><td>4</td><td>2</td>
    </tr>
  </tbody>
</table>


<table>
  <thead>
    <tr>
      <th>RC522 / VMA405</th><th>PI 3 B+</th><th>Couleur cable</th>
    </tr>
  </thead>
  <tbody>
    <tr><td>3.3v / VCC</td><td>1</td><td>rouge</td></tr>
    <tr><td>RST</td><td>22</td><td>marron</td></tr>
    <tr><td>GND</td><td>9</td><td>noir</td></tr>
    <tr><td>IRQ</td><td>pas utilisé</td><td></td></tr>
    <tr><td>MISO</td><td>21</td><td>jaune</td></tr>
    <tr><td>MOSI</td><td>19</td><td>vert</td></tr>
    <tr><td>SCK</td><td>23</td><td>bleu</td></tr>
    <tr><td>SDA</td><td>24</td><td>violet</td></tr>
  <tbody>
</table>

## splash screen (écran de boot)

- sudo nano /boot/config.txt   
disable splash=1


- sudo nano /boot/cmdline.txt   
consoleblank=0 loglevel=1 quiet logo.nologo


- Pour afficher l'image   
sudo apt install fbi


- Créer un service   
sudo nano /etc/systemd/system/splashscreen.service
```
[Unit]
Description=Splash screen
DefaultDependencies=no
After=local-fs.target
[Service]
ExecStart=/usr/bin/fbi -d /dev/fb0 --noverbose -a /home/sysop/splash.png
StandardInput=tty
StandardOutput=tty
[Install]
WantedBy=sysinit.target
```
- active le service   
sudo systemctl enable splashscreen.service 
sudo systemctl start  splashscreen.service

## /ext/xdg/openbox/autostart
```
#/etc/xdg/openbox/
DISPLAY=:0 xdotool getactivewindow key F5

# stop veille/économie dénergie
xset dpms 0 0 0 && xset s noblank  && xset s off

#Touches pour sortir du serveur X =>  CTRL-ATL-Backspace
setxkbmap -option terminate:ctrl_alt_bksp

sed -i 's/"exited_cleanly":false/"exited_cleanly":true/' ~/.config/chromium/Default/Preferences
sed -i 's/"exit_type":"Crashed"/"exit_type":"Normal"/' ~/.config/chromium/Default/Preferences

# vidage du cache chromium
rm -fr /home/sysop/.cache/chromium
rm -fr /home/sysop/.config/chromium/Default/

# orientation de l'écran
xrandr --output DSI-1 --rotate right

# lance chromium avec un user agent spécifique hostname,password,periph,ip (provenant en partie de .chromium_env)
cd /home/sysop/serveurNfcNodeJs/
node serveur_nfc.js

```

## /home/sysop/.bashrc (ajouter)
```
[[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && startx -- -nocursor
```