diff --git a/examples/scn_send.sh b/examples/scn_send.sh new file mode 100644 index 0000000..9f5dd8d --- /dev/null +++ b/examples/scn_send.sh @@ -0,0 +1,77 @@ +#!/usr/bin/env bash + +# +# Call with `scn_send title` +# or `scn_send title content` +# or `scn_send title content priority` +# +# + +if [ "$#" -lt 1 ]; then + echo "no title supplied via parameter" + exit 1 +fi + +################################################################################ +# INSERT YOUR DATA HERE # +################################################################################ +user_id=999 +user_key="????????????????????????????????????????????????????????????????" +################################################################################ + +title=$1 +content="" + +if [ "$#" -gt 1 ]; then + content=$2 +fi + +priority=1 + +if [ "$#" -gt 2 ]; then + priority=$3 +fi + +usr_msg_id=$(uuidgen) + +while true ; do + + curlresp=$(curl -s -o /dev/null -w "%{http_code}" \ + -d "user_id=$user_id" -d "user_key=$user_key" -d "title=$title" \ + -d "content=$content" -d "priority=$priority" -d "msg_id=$usr_msg_id" \ + https://scn.blackforestbytes.com/send.php) + + if [ "$curlresp" == 200 ] ; then + echo "Successfully send" + exit 0 + fi + + if [ "$curlresp" == 400 ] ; then + echo "Bad request - something went wrong" + exit 1 + fi + + if [ "$curlresp" == 401 ] ; then + echo "Unauthorized - wrong userid/userkey" + exit 1 + fi + + if [ "$curlresp" == 403 ] ; then + echo "Quota exceeded - wait one hour before re-try" + sleep 3600 + fi + + if [ "$curlresp" == 412 ] ; then + echo "Precondition Failed - No device linked" + exit 1 + fi + + if [ "$curlresp" == 500 ] ; then + echo "Internal server error - waiting for better times" + sleep 60 + fi + + # if none of the above matched we probably hav no network ... + echo "Send failed (response code $curlresp) ... try again in 5s" + sleep 5 +done \ No newline at end of file diff --git a/web/api_more.php b/web/api_more.php index 8019d27..3c44f27 100644 --- a/web/api_more.php +++ b/web/api_more.php @@ -187,6 +187,95 @@ Be aware that the server only saves send messages for a short amount of time. Because of that you can only use this to prevent duplicates in a short time-frame, older messages with the same ID are probably already deleted and the message will be send again.
+ +
+ Depending on your use case it can be useful to create a bash script that handles things like resending messages if you have connection problems or waiting if there is no quota left.
+ Here is an example how such a scrippt could look like, you can put it into /usr/local/sbin
and call it with scn_send "title" "content"
+
#!/usr/bin/env bash + +# +# Call with `scn_send title` +# or `scn_send title content` +# or `scn_send title content priority` +# +# + +if [ "$#" -lt 1 ]; then + echo "no title supplied via parameter" + exit 1 +fi + +################################################################################ +# INSERT YOUR DATA HERE # +################################################################################ +user_id=999 +user_key="????????????????????????????????????????????????????????????????" +################################################################################ + +title=$1 +content="" + +if [ "$#" -gt 1 ]; then + content=$2 +fi + +priority=1 + +if [ "$#" -gt 2 ]; then + priority=$3 +fi + +usr_msg_id=$(uuidgen) + +while true ; do + + curlresp=$(curl -s -o /dev/null -w "%{http_code}" \ + -d "user_id=$user_id" -d "user_key=$user_key" -d "title=$title" \ + -d "content=$content" -d "priority=$priority" -d "msg_id=$usr_msg_id" \ + https://scn.blackforestbytes.com/send.php) + + if [ "$curlresp" == 200 ] ; then + echo "Successfully send" + exit 0 + fi + + if [ "$curlresp" == 400 ] ; then + echo "Bad request - something went wrong" + exit 1 + fi + + if [ "$curlresp" == 401 ] ; then + echo "Unauthorized - wrong userid/userkey" + exit 1 + fi + + if [ "$curlresp" == 403 ] ; then + echo "Quota exceeded - wait one hour before re-try" + sleep 3600 + fi + + if [ "$curlresp" == 412 ] ; then + echo "Precondition Failed - No device linked" + exit 1 + fi + + if [ "$curlresp" == 500 ] ; then + echo "Internal server error - waiting for better times" + sleep 60 + fi + + # if none of the above matched we probably hav no network ... + echo "Send failed (response code $curlresp) ... try again in 5s" + sleep 5 +done ++
+ Be aware that the server only saves send messages for a short amount of time. Because of that you can only use this to prevent duplicates in a short time-frame, older messages with the same ID are probably already deleted and the message will be send again. +
+