<s> """<STR_LIT>""" <EOL> import paho . mqtt . client as mqtt <EOL> import RPi . GPIO as GPIO <EOL> from time import sleep <EOL> pinLedSw = <NUM_LIT> <EOL> pinLedRd = <NUM_LIT> <EOL> GPIO . setmode ( GPIO . BCM ) <EOL> GPIO . setup ( pinLedSw , GPIO . OUT ) <EOL> GPIO . setup ( pinLedRd , GPIO . IN ) <EOL> def pinSet ( pin , setLed ) : <EOL> """<STR_LIT>""" <EOL> GPIO . output ( pin , setLed ) <EOL> def pinRead ( pin ) : <EOL> """<STR_LIT>""" <EOL> return GPIO . input ( pin ) <EOL> def on_connect ( client , userdata , flags , rc ) : <EOL> print ( "<STR_LIT>" + str ( rc ) ) <EOL> client . subscribe ( "<STR_LIT>" ) <EOL> def on_message ( client , userdata , msg ) : <EOL> print ( msg . topic + "<STR_LIT:U+0020>" + str ( msg . payload ) ) <EOL> if '<STR_LIT>' in msg . payload : <EOL> pinSet ( pinLedSw , True ) <EOL> if '<STR_LIT>' in msg . payload : <EOL> pinSet ( pinLedSw , False ) <EOL> sleep ( <NUM_LIT:0.1> ) <EOL> state = pinRead ( pinLedRd ) <EOL> if state : <EOL> sstate = <NUM_LIT:1> <EOL> else : <EOL> sstate = <NUM_LIT:0> <EOL> client . publish ( "<STR_LIT>" , sstate ) <EOL> client = mqtt . Client ( ) <EOL> client . on_connect = on_connect <EOL> client . on_message = on_message <EOL> client . connect ( host = "<STR_LIT>" , port = <NUM_LIT> , keepalive = <NUM_LIT> ) <EOL> client . loop_forever ( ) </s>
