To control the green LED on T.A.R.A.S, we will need to write some code to the Raspberry Pi on T.A.R.A.S. We will need the access token for our dashboard (see Chapter 15, Connecting Sensory Inputs from the Robot Car to the Web, on how to get that):
- Open up Thonny from Application Menu | Programming | Thonny Python IDE
- Click on the New icon to create a new file
- Type the following:
import paho.mqtt.client as mqttfrom gpiozero import LEDimport jsonTHINGSBOARD_HOST = 'demo.thingsboard.io'ACCESS_TOKEN = '<<access token>>'green_led=LED(21)def on_connect(client, userdata, rc, *extra_params): print('Connected with result code ' + str(rc)) client.subscribe('v1/devices/me/rpc/request/+')def on_message(client, ...