Skip to content

Instantly share code, notes, and snippets.

@goffinet
Created June 5, 2016 13:29
Show Gist options
  • Save goffinet/85f6869aaf06a8e541b04b35f7caf8eb to your computer and use it in GitHub Desktop.
Save goffinet/85f6869aaf06a8e541b04b35f7caf8eb to your computer and use it in GitHub Desktop.
cloudbit script example : list all, id, signal, value, pub, sub
#!/bin/bash
# dependencies : curl, python, jq
DEVICE_ID=put_your_device_id
TOKEN=put_your_device_token
# ! mettre les headers HTTP en variable
# Fonctions all,id,signal,value,pub,sub
# curl -i : pour voir les entêtes des sorties
# pour formater les sorties json "`| python -mjson.tool`" ou "`| jq`"
all() {
#echo "Liste les cloudbits"
curl -XGET -H "Authorization: Bearer $TOKEN" -H "Accept: application/vnd.littlebits.v2+json" \
https://api-http.littlebitscloud.cc/devices
}
id() {
#echo "Donne des infos sur l'ID"
curl -XGET -H "Authorization: Bearer $TOKEN" -H "Accept: application/vnd.littlebits.v2+json" \
https://api-http.littlebitscloud.cc/devices/$DEVICE_ID
}
signal() {
#echo "Envoit un signal à 100/100 pendant 1s"
curl -XPOST -H "Authorization: Bearer $TOKEN" -H "Accept: application/vnd.littlebits.v2+json" \
https://api-http.littlebitscloud.cc/devices/$DEVICE_ID/output -d percent=100 -d duration_ms=1000
}
value() {
#echo "Demande la valeur d'entrée du cloudbit"
curl -XGET -H "Authorization: Bearer $TOKEN" -H "Accept: application/vnd.littlebits.v2+json" \
https://api-http.littlebitscloud.cc/devices/$DEVICE_ID/input
}
pub() {
#echo "Souscriptions en tant que publisher"
curl -XGET -H "Authorization: Bearer $TOKEN" -H "Accept: application/vnd.littlebits.v2+json" \
https://api-http.littlebitscloud.cc/subscriptions?publisher_id=$DEVICE_ID
}
sub() {
#echo "Souscriptions en tant que subscriber"
curl -XGET -H "Authorization: Bearer $TOKEN" -H "Accept: application/vnd.littlebits.v2+json" \
https://api-http.littlebitscloud.cc/subscriptions?subscriber_id=$DEVICE_ID
}
$1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment