Prepare ActionMethod scripts

#!/bin/bash## DESCRIPTION:# This is a Custom Actions program that gets the state in which the LEDs are in.## PRE-REQUISITES:# For this script to work the "dataplicity" user has to be added# to "gpio" group. This can be done from sudo account such as "pi"# with the use of the following command:# "sudo usermod -a -G gpio dataplicity"## Check if "dataplicity" user is in "gpio" groupgrep gpio /etc/group | grep dataplicity > /dev/null
if [[ $?-eq1 ]]; thenecho"Can't run script, Please add \"dataplicity\" user to \"gpio\" group."exit1fi# Enforce user to supply one argumentif [[ $#-ne1 ]]; thenecho"[$0] Incorrect amount of arguments, 1 required."echo"Argument 1 must be: \"red\" or \"green\"."exit1fi# Check if LED_PIN argument is correct
case $1in
red)
LED_PIN=23
;;
green)
LED_PIN=24
;;
*)
echo"[$0] Incorrect argument - \"red\" or \"green\" expected."exit1
;;
esac# Check if LED GPIO pin was previously initializedls /sys/class/gpio/ | grep gpio$LED_PIN > /dev/null
# If not initialized return error, else return current stateif [[ $?-eq1 ]]; thenecho"[[[ReturnError:LED Not Initialized]]]"elseecho"[[[ReturnOK:$(cat /sys/class/gpio/gpio$LED_PIN/value)]]]"fi

In /home/dataplicity/actions/on-off/leds place the file below named control-state .

Control the LEDs from your mobile

When everything is in place, open your device in the Dataplicity Mobile App and select "Custom Actions" from the drop down menu. From there, the new interface you have designed should appear, and should allow you to control the GPIOs you have wired up.