Light Mapper contains code to control an LED light connected to a raspberry Pi through gpio.
The following diagram has been followed to make the connection with the LED in this case :-
Here we are using a push button switch to test the working condition of the LED, through an independent circuit.
Depending on the expected state of the light, the program controls whether or not to provide power in pin-18 of the gpio. When power is provided in the pin, the LED glows (ON State) and when no power is provided on it then it does not glow (OFF state).
- RaspBerry-Pi (RaspBerry-Pi 3 has been used for this demo)
- GPIO
- Breadboard along with wires
- LED light
- Push Button switch (to test the working condition of the light, this can be skipped if needed)
- Golang 1.14+
- KubeEdge 1.5+
-
Connect the LED to the RaspBerry-Pi using the GPIO as shown in the circuit diagram above.
-
Clone and run KubeEdge. Please ensure that the kubeedge setup is up and running before execution of step 4 (mentioned below).
-
Clone the kubeedge/examples repository.
git clone https://github.com/kubeedge/examples.git $GOPATH/src/github.com/kubeedge/examples
- Create the LED device model and device instance.
cd $GOPATH/src/github.com/kubeedge/examples/led-raspberrypi/crds
kubectl apply -f led-light-device-model.yaml
kubectl apply -f led-light-device-instance.yaml
# Note: You need to modify led-light-device-instance.yaml: replace string litearl 'edge-node1' with your edge node name at spec.nodeSelector.nodeSelectorTerms.matchExpressions.values
# Note: You can change the CRDs to match your requirement
- Update the name of the device (device instance name) created using the device CRD in the previous step along with the MQTT URL using which edge_core is running in the configuration file present at
$GOPATH/src/github.com/kubeedge/examples/led-raspberrypi/configuration/config.yaml
- Build the mapper to run in RaspBerry-Pi.
cd $GOPATH/src/github.com/kubeedge/examples/led-raspberrypi/
make # or `make led_light_mapper`
docker tag led-light-mapper:v1.1 <your_dockerhub_username>/led-light-mapper:v1.1
docker push <your_dockerhub_username>/led-light-mapper:v1.1
# Note: Before trying to push the docker image to the remote repository please ensure that you have signed into docker from your node, if not please type the followig command to sign in
docker login
# Please enter your username and password when prompted
- Deploy the light mapper.
cd $GOPATH/src/github.com/kubeedge/examples/led-raspberrypi/
# Please enter the following details in the deployment.yaml :-
# 1. Replace <edge_node_name> with the name of your edge node at spec.template.spec.voluems.configMap.name
# 2. Replace <your_dockerhub_username> with your dockerhub username at spec.template.spec.containers.image
kubectl create -f deployment.yaml
- Change the device Twin attribute (expected value) "power-state" of the device to "ON" to turn on the light, and "OFF" to turn off the light using the device CRDs. The mapper will control the LED to match the state mentioned in the cloud and also report back the actual state of the light to the cloud after updating.