PIQ@home
PIQ@home
Introdution
Pré-requis
- un arduino réseau (ESP8266 au hasard), avec firmware ESPeasy
- Display - MAX7219 dot matrix (4 mod pour Heure et 2 x 2 mod pour IV)
- Un script shell sur une machine connectée à Internet
- Une clef d'accès à l'API PRIM (de IdFM)
Afficheur

Script d'affichage IV
On peut trouver les point d'arrêt à partir de la carte sur le site https://prim.iledefrance-mobilites.fr/fr/donnees-statiques/perimetre-des-donnees-tr-disponibles-plateforme-idfm
Pour la clef d'accès API, créer un compte et se rendre dans la section "Mes jetons d'authentification".
Une fois ces informations collectées, les saisir dans le script suivant:
#!/usr/bin/env bash
# PIQ@home
#
# (c) Yves Lavanant - 2024
#
# Enable xtrace if the DEBUG environment variable is set
if [[ ${DEBUG-} =~ ^1|yes|true$ ]]; then
set -o xtrace # Trace the execution of the script (debug)
fi
# Only enable these shell behaviours if we're not being sourced
# Approach via: https://stackoverflow.com/a/28776166/8787985
if ! (return 0 2> /dev/null); then
# A better class of script...
set -o errexit # Exit on most errors (see the manual)
set -o nounset # Disallow expansion of unset variables
set -o pipefail # Use last non-zero exit code in a pipeline
fi
# Enable errtrace or the error trap handler will not work as expected
set -o errtrace # Ensure the error trap handler is inherited
# Variables
TMP=$(mktemp)
StopPoint="STIF:StopPoint:Q:463039:" # Point d'arret choisi
PIQ=192.168.1.138 # Afficheur IV
# DESC: Usage help
# ARGS: None
# OUTS: None
function script_usage() {
cat << EOF
Usage:
-h|--help Displays this help
-v|--verbose Displays verbose output
-nc|--no-colour Disables colour output
-cr|--cron Run silently unless we encounter an error
EOF
}
# DESC: Parameter parser
# ARGS: $@ (optional): Arguments provided to the script
# OUTS: Variables indicating command-line parameters and options
function parse_params() {
local param
while [[ $# -gt 0 ]]; do
param="$1"
shift
case $param in
-h | --help)
script_usage
exit 0
;;
-v | --verbose)
verbose=true
;;
-nc | --no-colour)
no_colour=true
;;
-cr | --cron)
cron=true
;;
*)
script_exit "Invalid parameter was provided: $param" 1
;;
esac
done
}
# DESC: Get IVTR from PRIM
# ARGS: $@ (optional): Arguments provided to the script
# OUTS: None
function get_IVTR() {
curl --silent --header "apiKey: xxxxxxxxxxxxxxxxxxxxxxxx" \ # Mettre votre clef API PRIM
"https://prim.iledefrance-mobilites.fr/marketplace/stop-monitoring?MonitoringRef=${StopPoint}" \
-o $TMP
}
# DESC: send IVTR to the PIQ
# ARGS: $@ (optional): Arguments provided to the script
# OUTS: None
function send_IVTR() {
FIRST=$(echo "($(date -d $(jq -r .Siri.ServiceDelivery.StopMonitoringDelivery\[\].MonitoredStopVisit\[0\].MonitoredVehicleJourney.MonitoredCall.ExpectedArrivalTime $TMP) +%s) - $(date +%s)) / 60" | bc)
SECOND=$(echo "($(date -d $(jq -r .Siri.ServiceDelivery.StopMonitoringDelivery\[\].MonitoredStopVisit\[1\].MonitoredVehicleJourney.MonitoredCall.ExpectedArrivalTime $TMP) +%s) - $(date +%s)) / 60" | bc)
if [[ -n ${verbose-} ]]; then
echo "Premier passage dans $FIRST minutes."
echo "Deuxieme passage dans $SECOND minutes."
fi
# Envoi
curl --silent "http://$PIQ/control?cmd=DotMatrix,txt,2,$FIRST" >/dev/null
curl --silent "http://$PIQ/control?cmd=DotMatrix,txt,3,$SECOND" >/dev/null
}
# DESC: Main control flow
# ARGS: $@ (optional): Arguments provided to the script
# OUTS: None
function main() {
trap script_trap_err ERR
trap script_trap_exit EXIT
script_init "$@"
parse_params "$@"
cron_init
colour_init
#lock_init system
while :
do
# Recuperation des infos
get_IVTR
# Calcul et envoi des infos au PIQ
send_IVTR
# Attente
sleep 30
done
}
# shellcheck source=source.sh
source "$(dirname "${BASH_SOURCE[0]}")/source.sh"
# Invoke main with args if not sourced
# Approach via: https://stackoverflow.com/a/28776166/8787985
if ! (return 0 2> /dev/null); then
main "$@"
fi
# vim: syntax=sh cc=80 tw=79 ts=4 sw=4 sts=4 et sr

Notes
Il est à noter que le script se base sur un StopPoint. L'afficheur PIQ est donc utilisable pour tous les types de transport (Métro bien sûr, mais également Bus, Tram et RER).
ToDo
- Affichage "à quai"
- Essayer de supprimer le script (utilisation des règles?)