65 lines
2.3 KiB
Bash
Executable File
65 lines
2.3 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Test script to call the Pi's baresip every 5 minutes
|
|
# This will help verify the NAT connection stays alive
|
|
|
|
ACCOUNT_SID="AC1290bf86af061f24406c6762f48fa24e"
|
|
AUTH_TOKEN="6bfac57e5e26ea52c841594ef8d99ed1"
|
|
FROM_NUMBER="+13476229543"
|
|
TO_SIP="sip:yellow@probablycorey.sip.us1.twilio.com"
|
|
LOG_FILE="baresip-test-results.log"
|
|
|
|
echo "=== Baresip Call Test Started at $(date) ===" | tee -a $LOG_FILE
|
|
echo "Will call every 5 minutes. Press Ctrl+C to stop." | tee -a $LOG_FILE
|
|
echo "" | tee -a $LOG_FILE
|
|
|
|
call_count=0
|
|
|
|
while true; do
|
|
call_count=$((call_count + 1))
|
|
echo "[$(date)] Test call #$call_count" | tee -a $LOG_FILE
|
|
|
|
# Make the call
|
|
CALL_SID=$(curl -s -X POST "https://api.twilio.com/2010-04-01/Accounts/$ACCOUNT_SID/Calls.json" \
|
|
-u "$ACCOUNT_SID:$AUTH_TOKEN" \
|
|
--data-urlencode "Url=http://demo.twilio.com/docs/voice.xml" \
|
|
--data-urlencode "To=$TO_SIP" \
|
|
--data-urlencode "From=$FROM_NUMBER" \
|
|
| jq -r '.sid')
|
|
|
|
echo " Call SID: $CALL_SID" | tee -a $LOG_FILE
|
|
|
|
# Wait for call to complete
|
|
sleep 10
|
|
|
|
# Check status
|
|
STATUS=$(curl -s "https://api.twilio.com/2010-04-01/Accounts/$ACCOUNT_SID/Calls/$CALL_SID.json" \
|
|
-u "$ACCOUNT_SID:$AUTH_TOKEN" \
|
|
| jq -r '.status')
|
|
|
|
echo " Status: $STATUS" | tee -a $LOG_FILE
|
|
|
|
# Check for errors
|
|
ERROR=$(curl -s "https://api.twilio.com/2010-04-01/Accounts/$ACCOUNT_SID/Calls/$CALL_SID/Notifications.json" \
|
|
-u "$ACCOUNT_SID:$AUTH_TOKEN" \
|
|
| jq -r '.notifications[0].error_code // "none"')
|
|
|
|
if [ "$ERROR" != "none" ]; then
|
|
echo " ❌ ERROR: $ERROR" | tee -a $LOG_FILE
|
|
ERROR_MSG=$(curl -s "https://api.twilio.com/2010-04-01/Accounts/$ACCOUNT_SID/Calls/$CALL_SID/Notifications.json" \
|
|
-u "$ACCOUNT_SID:$AUTH_TOKEN" \
|
|
| jq -r '.notifications[0].message_text')
|
|
echo " Message: $ERROR_MSG" | tee -a $LOG_FILE
|
|
elif [ "$STATUS" = "no-answer" ] || [ "$STATUS" = "completed" ]; then
|
|
echo " ✓ Success" | tee -a $LOG_FILE
|
|
else
|
|
echo " ⚠ Unexpected status: $STATUS" | tee -a $LOG_FILE
|
|
fi
|
|
|
|
echo "" | tee -a $LOG_FILE
|
|
|
|
# Wait 5 minutes (minus the 10 seconds we already waited)
|
|
echo " Waiting 5 minutes until next call..." | tee -a $LOG_FILE
|
|
sleep 290
|
|
done
|