Page 1 of 1

User defined Script on MB Pro RPI will not run..

Posted: Fri Sep 18, 2026 9:27 am
by xray77
Hello,

I try to run a self-created script via my MeteoBridge RPI, unfortunately only the error message in the sending monitor: 2026-09-18 08:26:40 Error: 2026-09-18 08:26:38 Script failed: (no more tries):

I uploaded the script to the Scripts directory on the MeteoBridge under /data/scripts, in the Events tab, under Select Service, I selected Script Execution. Then select predefined script -> my. Script selected -> Clicked to load script and then click on save. The script is passed as parameter the ground temperature 4: [soil4temp-act.0]

here is the script:
#!/bin/sh
#
# rain_duration.sh (Meteobridge event version)
#------------------------------------------------
# Is periodically set by Meteobridge itself by "events" (events)
# called (e.g. every minute), with the current sensor value as
# first parameter. In the Meteobridge surface in the parameter field
# of the event simply enter:
#
# [soil4temp-act.0]
#
# Meteobridge automatically replaces this with the current value before
# the script is called - the script gets it as $1.
#
# IMPORTANT: Pure POSIX-sh (no bash, no bc, no curl), since
# Meteobridge only brings a slimmed down BusyBox environment.

# ==== Adjust ====
STATE_FILE="/data/scripts/rain_duration_state"
OUTPUT_FILE="/data/scripts/rain_duration.json"
THRESHOLD=75

FTP_HOST="FTP-HOSTde"
FTP_USER="FTP-USER"
FTP_PASS="FTP-PASS"
FTP_PATH="/meteobridge/rain_duration.json"
# ==================

VALUE="$1"
TODAY=$(date +%Y-%m-%d)
NOW_EPOCH=$(date +%s)

# Load status (date;summarized_seconds;last_check_epoch)
if [ -f "$STATE_FILE" ]; then
STATE_DATE=$(cut -d';' -f1 "$STATE_FILE")
STATE_SECONDS=$(cut -d';' -f2 "$STATE_FILE")
STATE_LAST=$(cut -d';' -f3 "$STATE_FILE")
else
STATE_DATE=""
STATE_SECONDS=0
STATE_LAST=$NOW_EPOCH
fi

# If values are empty/invalid, set clean to 0
[ -z "$STATE_SECONDS" ] && STATE_SECONDS=0
[ -z "$STATE_LAST" ] && STATE_LAST=$NOW_EPOCH

# New day? Then reset
if [ "$STATE_DATE" != "$TODAY" ]; then
STATE_DATE="$TODAY"
STATE_SECONDS=0
STATE_LAST=$NOW_EPOCH
fi

# Past time since last check, with safety limitation (max. 5 minutes)
ELAPSED=$((NOW_EPOCH - STATE_LAST))
if [ "$ELAPSED" -gt 300 ]; then ELAPSED=300; fi
if [ "$ELAPSED" -lt 0 ]; then ELAPSED=0; fi

# Numerical comparison with awk instead of bc (bc is mostly on Meteobridge
# not installed). awk returns 1 (true) or 0 (false).
IS_RAINING=$(awk -v v="$VALUE" -v t="$THRESHOLD" 'BEGIN { print (v+0 >= t) ? 1 : 0 }')

if [ "$IS_RAINING" = "1" ]; then
STATE_SECONDS=$((STATE_SECONDS + ELAPSED))
fi

# Save state
echo "${STATE_DATE};${STATE_SECONDS};${NOW_EPOCH}" > "$STATE_FILE"

# Format as HH:MM
HOURS=$((STATE_SECONDS / 3600))
MINUTES=$(( (STATE_SECONDS % 3600) / 60 ))
DURATION_STR=$(printf "%02d:%02d" "$HOURS" "$MINUTES")

# Write JSON file
cat > "$OUTPUT_FILE" <<EOF
{
"rain_duration_today": "${DURATION_STR}",
"rain_duration_seconds": ${STATE_SECONDS},
"is_raining": ${IS_RAINING}
}
EOF

# --- Upload to the webspace ---
# Variante A: BusyBox-Applet ftpput (meist auf Meteobridge verfügbar)
ftpput -u "$FTP_USER" -p "$FTP_PASS" "$FTP_HOST" "$FTP_PATH" "$OUTPUT_FILE" 2>/tmp/rain_duration_ftp_error.log

# Variant B (fallback, if curl is present): income animals,
# Comment variant A above with "#".
# curl -s --user "${FTP_USER}:${FTP_PASS}" -T "$OUTPUT_FILE" "ftp://${FTP_HOST}${FTP_PATH}"



Can someone tell me why the script is not running? Thank you!
The FTP parameters are of course correctly entered in the original script...