import paho.mqtt.client as mqttClient import time, random, RPi.GPIO as GPIO GPIO.setwarnings(False) GPIO.setmode(GPIO.BOARD) def on_connect(client, userdata, flags, rc): if rc == 0: print("Connected to broker") global Connected Connected = True else: print("Connection failed") Connected = False def setupgpio(): GPIO.setup(LED_RED, GPIO.OUT) GPIO.setup(LED_yellow, GPIO.OUT) GPIO.setup(LED_GREEN, GPIO.OUT) def alloff (val): GPIO.output (LED_RED, LEDOFF) GPIO.output (LED_yellow, LEDOFF) GPIO.output (LED_GREEN, LEDOFF) time.sleep(val) def allon (val): GPIO.output (LED_RED, LEDON) GPIO.output (LED_yellow, LEDON) GPIO.output (LED_GREEN, LEDON) time.sleep(val) def red (val): GPIO.output (LED_RED, LEDON) GPIO.output (LED_yellow, LEDOFF) GPIO.output (LED_GREEN, LEDOFF) time.sleep(val) def redamber (val): GPIO.output (LED_RED, LEDON) GPIO.output (LED_yellow, LEDON) GPIO.output (LED_GREEN, LEDOFF) time.sleep(val) def yellow (val): GPIO.output (LED_RED, LEDOFF) GPIO.output (LED_yellow, LEDOFF) GPIO.output (LED_GREEN, LEDON) time.sleep(val) def green (val): GPIO.output (LED_RED, LEDOFF) GPIO.output (LED_yellow, LEDOFF) GPIO.output (LED_GREEN, LEDON) time.sleep(val) broker_address= "broker name" port = 1883 user = "user name" password = "pwd" LED_RED = 7 LED_yellow = 11 LED_GREEN = 13 LEDOFF = 0 LEDON = 1 client = mqttClient.Client() client.username_pw_set(user, password=password) client.on_connect= on_connect client.connect(broker_address, port=port) client.loop_start() while Connected != True: time.sleep(0) def basicSequence (val): count=0 while count <val: red (3) print("sig: " +str(count)) client.publish("/topic/signals", count) time.sleep(0) def basicSequence (val): collect= 0 while collect <val: redamber (1) print("sign: " +str(collect)) client.publish("/topic/signals", collect) time.sleep(0) def basicSequence (val): conn= 0 while conn <val: green (5) print("signa: " +str(conn)) client.publish("/topic/signals", conn) time.sleep(0) def basicSequence (val): coy= 0 while coy <val: yellow (3) print("signal: " +str(coy)) client.publish("/topic/signals", coy) time.sleep(0) try: while True: setupgpio() alloff(0) basicSequence (5) except KeyboardInterrupt: GPIO.cleanup() exit()
please help me in loop i am trying to run this program in raspberry pi by sending msg
Messages In This Thread |
please help me in loop i am trying to run this program in raspberry pi by sending msg - by saifullahbhutta - Jan-27-2020, 02:17 PM
RE: please help me in loop i am trying to run this program in raspberry pi by sending msg - by buran - Jan-27-2020, 02:20 PM
RE: please help me in loop i am trying to run this program in raspberry pi by sending msg - by saifullahbhutta - Jan-27-2020, 02:32 PM
|
Possibly Related Threads… | |||||
Thread | Author | Replies | Views | Last Post | |
Noob here. Random quiz program. Using a while loop function and alot of conditionals. | monkeydesu | 6 | 1,410 |
Sep-07-2022, 02:01 AM Last Post: kaega2 |
|
Try-except in while loop: error with closing program | Lupin_III | 7 | 2,895 |
Jul-03-2020, 10:57 AM Last Post: Lupin_III |
|
Port my python program to Raspberry pi seamlessly | Hassibayub | 1 | 1,951 |
Jun-29-2020, 12:58 PM Last Post: snippsat |
|
While loop won't restart program :( | TheDovah77 | 4 | 4,238 |
Apr-04-2019, 07:37 PM Last Post: TheDovah77 |
|
How to rerun the program in a loop with different input? | bharaths | 3 | 3,783 |
Nov-23-2018, 09:36 AM Last Post: bharaths |
|
Nested while loop in pyramid program. | raj55 | 2 | 5,753 |
May-04-2018, 10:05 AM Last Post: ThiefOfTime |
|
WHILE LOOP in my program | kurokszxcky | 1 | 3,323 |
Oct-02-2017, 03:45 PM Last Post: ichabod801 |
|
sending data from my raspberry pi to my website | mohitsangavikar | 2 | 17,828 |
Sep-05-2017, 06:55 PM Last Post: wrybread |
Users browsing this thread: 2 Guest(s)