From d7b5366bdc9d6b34362f5b3b8b07c1e08df0f495 Mon Sep 17 00:00:00 2001 From: kske Date: Thu, 11 Mar 2021 17:01:25 +0100 Subject: [PATCH] Rewrite data transfer in bash --- transfer-data.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 transfer-data.sh diff --git a/transfer-data.sh b/transfer-data.sh new file mode 100755 index 0000000..cc574d6 --- /dev/null +++ b/transfer-data.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +URL="https://http.bosch-iot-hub.com/telemetry" +TTD="10" +KEY="ZGVmaW5tYUB0MzhiYmNjZDE2MjE3NDViODgxMTk5ZGI2ZWQzZGFiNmE6RGVGaW5NYWNoZW4yMDIwIQ==" + +# Build name +NAME=${1#*_} +NAME=${NAME%.*} + +# Build body +JSON="{\"$NAME\": [" +while read LINE +do + JSON+="[${LINE%,*}, ${LINE#*,}], " +done < $1 +JSON=${JSON::-2} +JSON+=']}' + +echo "JSON = $JSON" + +# Dispatch curl +curl -X POST $URL -H "accept: */*" -H "hono-ttd: $TTD" -H "Authorization: Basic $KEY" -H "Content-Type: application/json" -d "$JSON"