ke-twitter-demo

module
v0.0.0-...-dd67137 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 24, 2022 License: Apache-2.0

README

KubeEdge Twitter Demo

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.

Prerequisites

Hardware Prerequisites
  • 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.
Software Prerequisites
  • 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.

Steps to run the demo

Get demo code

Clone this github repo.

Create the device model and device instance for the speaker

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.

Create Secret for Twitter Credentials
  • 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 Secrettwittersecret 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>
Run the ke-tweeeter app
  • 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
Build the track player app
  • 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
Run the track player app
  • 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
Tweet to play track
  • 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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL