Controlling the green LED on T.A.R.A.S

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):

  1. Open up Thonny from Application Menu | Programming | Thonny Python IDE
  2. Click on the New icon to create a new file
  3. 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, ...

Get Internet of Things Programming Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.