Labs Cloudbit

1. Matériel nécessaire

  • 1 x PC
  • 1 x connexion au WLAN (un client et un point d'accès connecté à l'Internet)
  • 1 x module cloudbit
  • 1 x module bouton
  • 1 x module d'entrée (température, mouvement, son, curseur, ...)
  • 1 x module de sortie (buzzer, led, bargraph)
  • 1 x compte gmail.com

2. Prise de mesure et alerte

Un premier montage : prise de température et alerte

3. Contrôle à partir de litllebitscloud

A partir de l'interface http://control.littlebitscloud.cc/

  1. Brancher le cloudbit.
  2. Attendre que la diode devienne verte ou blanche .
  3. A partir de http://control.littlebitscloud.cc/ lancer la procédure d'installation via "+ New CloudBit"
  4. Maintenir son doigt sur le bouton jusqu'à ce que la diode devienne bleue clignotante. Le cloudbit passe en mode de configuration et devient point d'accès local quand la diode bleue est fixée.
  5. Connecter son PC au SSID Wi-Fi "littleBits_Cloud_..." que le cloudbit propose.
  6. Encoder le mot de passe du réseau Wi-Fi local.

Image : https://files.linuxgizmos.com/littlebits_cloudbit_app.jpg !!!

4. Contrôle via API HTTP

Image : http://files.linuxgizmos.com/littlebits_cloudbit_arch.jpg

Source : http://hackerboards.com/tiny-linux-sbc-taps-plug-and-play-iot-modules/

La documentation de l'API des cloudbits se trouve sur http://developer.littlebitscloud.cc/.

L'API est interrogée via des méthodes HTTP GET ou POST sur des URIs précis.

Pour manipuler l'API cloudbit, il est nécessaire de connaître son "token", sorte de jeton d'authentification. On le trouvera dans l'onglet "Settings" de l'interface http://control.littlebitscloud.cc/.

Les requêtes HTTP doivent contenir des Headers HTTP avec ces valeurs :

Authorization: Bearer $TOKEN
Accept: application/vnd.littlebits.v2+json

La méthode GET permet d'obtenir des données et la commande PUT permet de placer des données. L'API est basée sur le modèle REST et propose un service pub/sub.

On trouvera plus bas 6 exemples de fonctions curl (https://gist.github.com/goffinet/85f6869aaf06a8e541b04b35f7caf8eb) :

#!/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`"
# par exemple ./cb.sh all | 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

Par exemple, pour lire les données du premier objet :

curl -XGET -H 'Authorization: Bearer $TOKEN' -H 'Accept: application/vnd.littlebits.v2+json' \
https://api-http.littlebitscloud.cc/devices \
| jq '.[0]'

Résultat formaté :

{
  "label": "cb01",
  "id": "243c200bfb48",
  "subscriptions": [],
  "subscribers": [
    {
      "publisher_id": "243c200bfb48",
      "subscriber_id": "https://api-ifttt.littlebitscloud.cc/receive_cloudbit_event/ignite/e2397f",
      "publisher_events": [
        "amplitude:delta:ignite"
      ]
    }
  ],
  "user_id": 98950,
  "is_connected": false,
  "input_interval_ms": 200
}

Par exemple pour obtenir le nom du premier objet :

curl -XGET -H 'Authorization: Bearer $TOKEN' -H 'Accept: application/vnd.littlebits.v2+json' \
https://api-http.littlebitscloud.cc/devices \
| jq  '.[] .label'

Par exemple, pour tous les id et leur label :

curl -XGET -H 'Authorization: Bearer $TOKEN' -H 'Accept: application/vnd.littlebits.v2+json' \
https://api-http.littlebitscloud.cc/devices \
| jq '[] .label, .[] .id'

Voir le projet en Node-RED sur https://github.com/eciggaar/littlebits-to-bluemix

5. Automation IFTT

6. Cloudbits hacking

Système de fichier du cloudbit

Source : Read CloubBit FileSystem https://github.com/yepher/littlebits/edit/master/CloubitFileSystem.md

This webpage from LittleBits meant to post a link to the open parts of CloubBits source code. Looks like they put a wrong link there.

Based on the componenetly used by the device it seems easy enough to just mount CloudBits filesystem on Mac and try and find the web interfaces manually.

Prerequisites

The CloudBits filesystem is ext4 which in not natvily supported by OSX. You will need to install some tools to enable support for ext4.

NOTO: If I can get permission from LittleBits I will provide access to a CloudBit image that already has SSHD running and ready..

Backup SD Card (just in case)

Warning dd can be a very dagerous command that can wipe your SDCard or worse you Mac harddrive. You should study up on this command before you use it.

  • Open terminal
  • connect sdcard to Mac
  • type sudo dd if=/dev/disk1s3 of=/tmp/backupfile.img
  • type open /tmp
  • put the file somewhere safe
  • Create a duplicate of the card to keep the original safe
  • TODO: descibe how to do this....

Mount FileSystem

  • Remove SD card from the CloudBit
  • Use Spotlight to open Disk Utility
  • Connct SD card to your Mac and Note the new names
  • Open Terminal
    • mkdir /Volumes/little
    • sudo fuse-ext2 -o force /dev/disk1s3 /Volumes/little
    • cd /Volumes/little (or view in finder with: open /Volume/little )

One line form: mkdir /Volumes/little && sudo fuse-ext2 -o force /dev/disk1s3 /Volumes/little && cd /Volumes/little

Enable sshd on CloudBit

This part assume you already mounted the SD card from the CloudBit.

  • edit /Volumes/little/etc/ssh/sshd_config
    • change UsePAM yes to UsePAM no
    • uncommnet #PermitRootLogin yes to PermitRootLogin yes
    • save and close file
  • edit /Volumes/little/usr/lib/sysctl.d/50-default.conf
    • Add line net.ipv4.conf.default.rp_filter = 0
  • Disable iptables
    • mv /Volumes/little/etc/systemd/system/multi-user.target.wants/iptables.service /Volumes/little/etc/systemd/
  • cd /Volumes/little/etc/systemd/system
    • cp /Volumes/little/usr/lib/systemd/system/sshdgenkeys.service .
    • cp /Volumes/little/usr/lib/systemd/system/sshd.service .
  • TODO: decribe howto setup password
  • Unmount SDCARD
  • Put back into CloudBit and ssh to device

Linux Access

  • Shadow file
    • Generate password: openssl passwd -1 -salt bit cloud
    • Original root shadow password $6$p9leKwKF$MkCEuyjkObA0/Yl7GD93WaqHHEA/yFY4sWpUqN5vB2YVIdBOf/UoQfMUgB0uh1enC7q2BrEaCRJfcD0tkheXZ/

Other Info

  • netstat -an
    • tcp 0 0 10.0.6.181:56173 54.235.112.129:9480 ESTABLISHED
ps -efxw
 PID TTY      STAT   TIME COMMAND
   2 ?        S      0:00 [kthreadd]
   3 ?        S      0:06  \_ [ksoftirqd/0]
   4 ?        S      0:03  \_ [kworker/0:0]
   5 ?        S<     0:00  \_ [kworker/0:0H]
   7 ?        S<     0:00  \_ [kworker/u:0H]
   8 ?        S      0:01  \_ [watchdog/0]
   9 ?        S<     0:00  \_ [cpuset]
  10 ?        S<     0:00  \_ [khelper]
  11 ?        S      0:00  \_ [kdevtmpfs]
  12 ?        S<     0:00  \_ [netns]
  13 ?        S      0:00  \_ [kworker/u:1]
 159 ?        S      0:00  \_ [bdi-default]
 160 ?        S<     0:00  \_ [kintegrityd]
 162 ?        S<     0:00  \_ [kblockd]
 205 ?        S      0:00  \_ [khubd]
 305 ?        S      0:00  \_ [khungtaskd]
 308 ?        S      0:00  \_ [kswapd0]
 309 ?        S      0:00  \_ [fsnotify_mark]
 310 ?        S<     0:00  \_ [cifsiod]
 311 ?        S<     0:00  \_ [crypto]
 368 ?        S<     0:00  \_ [ci_otg]
 380 ?        S      0:00  \_ [kworker/u:2]
 391 ?        S<     0:00  \_ [deferwq]
 394 ?        S      0:14  \_ [mmcqd/0]
 400 ?        S      0:00  \_ [jbd2/mmcblk0p3-]
 401 ?        S<     0:00  \_ [ext4-dio-unwrit]
 419 ?        S      0:00  \_ [kworker/0:2]
 806 ?        S      0:14  \_ [RTW_CMD_THREAD]
   1 ?        Ss     0:56 /sbin/init HOME=/ TERM=linux
 425 ?        Ss     0:01 /usr/lib/systemd/systemd-journald LANG=en_US.UTF-8 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin NOTIFY_SOCKET=@/org/freedesktop/systemd1/notify LISTEN_PID=425 LISTEN_FDS
 528 ?        Ss     0:00 /usr/lib/systemd/systemd-udevd LANG=en_US.UTF-8 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin NOTIFY_SOCKET=@/org/freedesktop/systemd1/notify LISTEN_PID=528 LISTEN_FDS=2
 717 ?        Ss     0:00 /usr/bin/sshd -D LANG=en_US.UTF-8 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
1018 ?        Ss     0:16  \_ sshd: root@pts/0                                                                         n
1020 pts/0    Ss     0:07      \_ -bash USER=root LOGNAME=root HOME=/root PATH=/usr/bin:/bin:/usr/sbin:/sbin MAIL=/var/mail/root SHELL=/bin/bash SSH_CLIENT=10.0.6.169 58324 22 SSH_CONNECTION=10.0.6.169 583
3226 pts/0    R+     0:00          \_ ps -efxw TERM=xterm-256color SHELL=/bin/bash SSH_CLIENT=10.0.6.169 58324 22 SSH_TTY=/dev/pts/0 USER=root MAIL=/var/mail/root PATH=/usr/local/sbin:/usr/local/bin:/usr/b
 720 ?        Ss     0:00 /usr/local/lb/ADC/bin/ADC.d LANG=en_US.UTF-8 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
 723 ?        Ss     0:00 login -- root
 786 ttyAMA0  Ss+    0:00  \_ -bash HOME=/root USER=root SHELL=/bin/bash TERM=vt102 PATH=/usr/local/lb/ADC/bin:/usr/local/lb/Button/bin:/usr/local/lb/DAC/bin:/usr/local/lb/LEDcolor/bin:/usr/local/lb/cloud_
 725 ?        Ss     0:00 /usr/local/lb/DAC/bin/DAC.d LANG=en_US.UTF-8 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
 731 ?        Ss     0:26 /usr/local/lb/Button/bin/button.d LANG=en_US.UTF-8 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
 781 ?        Ss     0:00 /usr/lib/systemd/systemd-logind LANG=en_US.UTF-8 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin NOTIFY_SOCKET=@/org/freedesktop/systemd1/notify WATCHDOG_PID=781 WATCHDOG_U
 782 ?        Ss     0:00 /usr/lib/systemd/systemd --user LANG=en_US.UTF-8 PATH=/usr/local/lb/ADC/bin:/usr/local/lb/Button/bin:/usr/local/lb/DAC/bin:/usr/local/lb/LEDcolor/bin:/usr/local/lb/cloud_client/bi
 784 ?        S      0:00  \_ (sd-pam)   HOME=/ TERM=linux
 811 ?        Ss     0:01 wpa_supplicant -B -P /run/wpa_supplicant_wlan0.pid -i wlan0 -D nl80211,wext -c/etc/wpa_supplicant/cloudbit.conf OLDPWD=/ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin PWD
 947 ?        Ss     0:00 dhcpcd -4qL -t 30 wlan0 OLDPWD=/ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin PWD=/ LANG=en_US.UTF-8 SHLVL=1 _=/usr/sbin/dhcpcd
 977 ?        Ss     0:04 /usr/local/lb/cloud_client/bin/cloud_client LANG=en_US.UTF-8 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
 980 ?        Ss     0:00 /usr/local/lb/LEDcolor/bin/LEDcolor.d LANG=en_US.UTF-8 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
 981 ?        Ss     0:27 /bin/bash /usr/local/lb/bit-util/monitorNetctl.sh &> /dev/null & LANG=en_US.UTF-8 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
3225 ?        S      0:00  \_ sleep 5 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin PWD=/ LANG=en_US.UTF-8 SHLVL=1 _=/usr/sbin/sleep
[root@alarm etc]#

Set output level

  • Set output to max /usr/local/lb/DAC/bin/setDAC ffff
  • Set output to min /usr/local/lb/DAC/bin/setDAC 0

Query ADC

[root@alarm /]# /usr/local/lb/ADC/bin/getADC -1
126
15
[root@alarm /]# /usr/local/lb/ADC/bin/getADC -1
0
0

Other commands

[root@alarm /]# tree /usr/local/lb
+---lb
| +---ADC
| | +---bin
| +---Button
| | +---bin
| +---DAC
| | +---bin
| +---LEDcolor
| | +---bin
| +---bit-util
| +---cloud_client
| | +---bin
| +---comm-util
| +---etc
| | +---hostapd
| | +---iptables
| | +---lighttpd
| | +---systemd
| +---hw_util
| | +---bin
| +---mfg_test
| | +---ADCtoDAC
| | | +---bin
| | +---RGBcycle
| | | +---bin
Total directories = 25

Cloud Client Conf

#Cloud Client Conf
[cloud_parameters]
cloud_host = cloud.littlebits.cc
cloud_port = 9480
setup_version = 1.0.0
protocol_version = 1.1.0
use_ssl = 1
dont_ignore_pings = 1 #switch to 1 if you want to connect to staging, this switches ping styles

[daemon_parameters]
adc_host = /var/lb/ADC_socket
dac_host = /var/lb/DAC_socket
led_host = /var/lb/SET_COLOR_socket

[client_parameters]
mac_file = /var/lb/mac
hash_id_file = /var/lb/id
ssid_file = /var/lb/current_ssid
device = littlebits-module-cloud
current_ssid = /var/lb/current_ssid
#this (and other parameters) should be pulled from the same place as the scripts do
firmware_version=1.0.140611a
ping_timeout = 2400
ping_maxmiss = 3
rx_buff_len = 100
tx_buff_len = 1000
token_len = 11

Scripts Conf

#!/usr/bin/env

# GENERAL
WADAP=wlan0
LB_WWW="www.littlebits.cc"
LB_DOM="littlebits.cc"
NTP_SERVER="pool.ntp.org"
TMP_DIR="/var/lb"
PM_MODE="/var/lb/power_mode"
CLOUDID="/var/lb/id"
MACADDR="/var/lb/mac"
SALT="/var/salt"

# LED COLORS
DEFAULT_COLOR="violet"
COMMISSION_COLOR="blue"
CONNECTING_COLOR="yellow"
CONNECTED_COLOR="green"
NOT_CONNECTED_COLOR="red"

# COMMISSIONING
GATEWAYIP=10.0.0.1
NETMASK=255.255.255.0
DOMAIN="cloudsetup.cc"
NETCTL_CONFIG="/etc/netctl/cloudbit"
WPA_CONFIG="/etc/wpa_supplicant/cloudbit.conf"
HOSTAPD_CONFIG="/etc/hostapd/hostapd.conf"
DNS_CONFIG="/etc/dnsmasq.conf"
COMM_LOG="/var/log/commissioning"

# DAEMON PATHS
CCPATH=/usr/local/lb/cloud_client/bin
BUTTONPATH=/usr/local/lb/Button/bin
ADCPATH=/usr/local/lb/ADC/bin
DACPATH=/usr/local/lb/DAC/bin
LEDPATH=/usr/local/lb/LEDcolor/bin

# SCRIPT PATHS
TESTPATH=/usr/local/lb/mfg_test
CUTILPATH=/usr/local/lb/comm-util

References

results matching ""

    No results matching ""