-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.sh
executable file
·39 lines (30 loc) · 1.04 KB
/
script.sh
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
#!/bin/bash
# Ensure these environment variables exist
if [ -z "$salame_feed_id" ]; then
echo "salame_feed_id environment variable is not defined"
fi
if [ -z "$salame_script_full_path" ]; then
echo "script_full_path environment variable is not defined"
fi
if [ -z "$iotplotter_api_key" ]; then
echo "iotplotter_api_key environment variable is not defined"
fi
# Set the URL to which the POST request will be sent
url=http://iotplotter.com/api/v2/feed/$salame_feed_id.csv
# Run the Python program and capture the first two lines of output (temp and humidity)
output=$(python $salame_script_full_path/read_sensor.py | head -n 2)
# Assign the first line
temperature=$(echo "$output" | sed -n 1p)
# Assign the second line
humidity=$(echo "$output" | sed -n 2p)
# Print the values of the variables
echo "temperature: $temperature"
echo "humidity: $humidity"
data=$(cat <<EOF
0,Salame_Temperature,$temperature
0,Salame_Humidity,$humidity
EOF
)
echo "data: $data"
logger $data
wget -O /dev/null --post-data="$data" --header="api-key: $iotplotter_api_key" "$url"