A user tweets kubeedge play <track>
to play the track. The tweet metadata is pushed to the edge node and the track is played on the speaker connected to the edge node.
- RaspBerry-Pi (RaspBerry-Pi 3 has been used for this demo). This will be the edge node to which the speaker will be connected.
- A speaker for playing the track.
- A running Kubernetes cluster.
- KubeEdge v1.5.0+
- In order to control the speaker and play the desired track , we need to manage the speaker connected to the rpi. KubeEdge allows us to manage devices using K8S custom resource definitions. The design proposal is here. Apply the CRD schema yamls available here using kubectl.
Clone this github repo.
With the Device CRD APIs now installed in the cluster , we now create the device model and instance for the speaker using the yaml files under examples/crds
.
- The cloud app in the demo needs to watch KubeEdge tweets. For this the application needs to sign the requests with a Twitter account.
Follow the steps mentioned here Guide for reference to generate the OAuth credentials. Create a Kubernetes Secret
twittersecret
with the credentials as below :
kubectl create secret generic twittersecret --from-literal=CONSUMER_KEY=<your_consumer_key> --from-literal=CONSUMER_SECRET=<your_consumer_secret> --from-literal=ACCESS_TOKEN=<your_access_token> --from-literal=ACCESS_TOKEN_SECRET=<your_access_token_secret>
- The ke-tweeter-app runs in a VM on the cloud and watches for KubeTweets. It can deployed using a Kubernetes deployment yaml
$ cd $GOPATH/github.com/ke-twitter-demo/ke-tweeter/deployments/
$ kubectl create -f ke-tweeter.yaml
- Cross-complie the PiApp which will run on the RPi and play the desired track.
~/go/src/github.com/ke-twitter-demo$export GOARCH=arm
~/go/src/github.com/ke-twitter-demo$export GOOS="linux"
~/go/src/github.com/ke-twitter-demo$export GOARM=6 #Pls give the appropriate arm version of your device
~/go/src/github.com/ke-twitter-demo$export CGO_ENABLED=1
~/go/src/github.com/ke-twitter-demo$export CC=arm-linux-gnueabi-gcc
~/go/src/github.com/ke-twitter-demo$ go build Pi_app/trackplayer.go
- Copy the trackplayer binary to the rpi. Make sure the MQTT broker is running on the rpi.
Run the binary. The app will subscribe to the
$hw/events/device/speaker-01/twin/update/document
topic and when it receives the desired track on the topic, it will play it on the speaker.
$ ./trackplayer
- Login to twitter and tweet the track name you wish to play. Please tweet in the following format :
kubeedge play <track>
The track info is pushed to the rpi and the track is played on the speaker.