-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsr
69 lines (58 loc) · 1.65 KB
/
sr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
# WildlifeSystems - sensor read
#
# This script provides a standard wrapper for reading sensors in WildlifeSystems,
# and handles inserting the device serial number and timestamp into the JSON response.
#
# This script is part of the WildlifeSystems project. For further information
# please refer to https://docs.wildlife.systems, or for more information on
# the project itself, please refer to https://wildlife.systems.
# Return codes
#
# Further information on WildlifeSystems standard reurn codes can be found
# at https://docs.wildlife.systems/return-codes.html
# 0 - Success
# 2 - no arguments provided
if [[ $# -eq 0 ]]; then
echo "No arguments supplied"
exit 2
fi
if [[ $1 == "list" ]]; then
find /usr/bin -name 'sensor-*' -type f -executable | while read SENS_SCRIPT; do
# Execute the sensor script with a parameter
$SENS_SCRIPT identify
if [[ $? -eq 60 ]]; then
# If the sensor script returns 60, it is a valid sensor script
SCRIPT=$(basename $SENS_SCRIPT)
echo "$SCRIPT"
fi
done
exit 0
fi
SCRIPT=$1
if [[ $# -eq 2 ]]; then
DEV=$2
else
DEV="all"
fi
SENS_SCRIPT="sensor-$1"
if [[ $DEV == "list" ]]; then
$SENS_SCRIPT list
exit 0
else
PI_SERIAL=$(grep Serial /proc/cpuinfo | cut -d ' ' -f 2)
TSTAMP=$(date +%s)
SENS_JSON=$($SENS_SCRIPT ${DEV})
# Terminate with error code from sensor script if error thrown
if [[ $? -ne 0 ]]; then
if [[ $? -eq 20 ]]; then
echo "Unknown device"
fi
if [[ $? -eq 21 ]]; then
echo "Unknown sensor"
fi
exit $?
fi
SENS_JSON=$(echo $SENS_JSON | jq ".[].node_id |= \"${PI_SERIAL}\" | .[].timestamp |= ${TSTAMP}")
echo $SENS_JSON
fi