Jun-29-2022, 01:10 PM
Hello,
I am having trouble using an Emulator and mqtt broker.
When one click button lumiere entree or lumiere salon "ON" the GPIO in the emulator should be red.
Instead i get an error message i dont know what it means.
Also i dont know where to implement the mttq broker, so that when we click the button it send the info.
Any idea how to solve those issues?
Thank you
I am having trouble using an Emulator and mqtt broker.
When one click button lumiere entree or lumiere salon "ON" the GPIO in the emulator should be red.
Instead i get an error message i dont know what it means.
Also i dont know where to implement the mttq broker, so that when we click the button it send the info.
Any idea how to solve those issues?
Thank you
from tkinter import * import datetime ct = datetime.datetime.now() from RPiSim import GPIO from time import sleep import RPi.GPIO as GPIO GPIO.setmode(GPIO.BOARD) import paho.mqtt.client as mqtt from random import randrange, uniform import time LED1= 22 LED2=18 mqttBroker ="mqtt.eclipseprojects.io" client = mqtt.Client("Alarme") client.connect(mqttBroker) root = Tk() root.title('Ma console') root.geometry('430x800') title = Label(root, text="Alarme", bg="grey", font=("bold", 20)) title.pack() c = Canvas(root, width=330, height=160, bg="grey") c.place(x=50, y=50) def push(): arme = Label(root, text="Arm�", bg="red", font=("bold", 20)).place(x = 170, y = 210) print("Alarme arm�e:-", ct) client.publish("Alarme", ct) <----------------------------------------Mttq broker? print("Just published " + str(ct) + " to topic ALARME") btn = Button(root, text='On', width=10, height=5, bd='10', command = push) def pushOff(): arme = Label(root, text=" ", bg="grey", font=("normal", 20)).place(x = 160, y = 210) print("Alarme d�sarm�e:-", ct) btn1 = Button(root, text='Off', width=10, height=5, bd='10', command = pushOff) btn.place(x=65, y=70) btn1.place(x=225, y=70) #2e paire de boutons c1 = Canvas(root, width=330, height=200, bg="grey") c1.place(x=50, y=250) def pushOn(): arme = Label(root, text="On", bg="red", font=("bold", 20)).place(x = 190, y = 420) GPIO.setup(LED1,GPIO.OUT) <-----------------------------GPIO? wrong place? print("Lumi�re entr�e allum�e:-", ct) btn2 = Button(root, text='On', width=10, height=5, bd='10', command = pushOn) def pushOff(): arme = Label(root, text="Off", bg="red", font=("bold", 20)).place(x = 190, y = 420) print("Lumi�re entr�e ferm�e:-", ct) btn3 = Button(root, text='Off', width=10, height=5, bd='10', command = pushOff) btn2.place(x=65, y=300) btn3.place(x=225, y=300) title1 = Label(root, text="Lumi�re entr�e", bg="grey", font=("bold", 20)).place(x = 110, y = 255) #title1.pack() #3e paire de boutons c2 = Canvas(root, width=330, height=280, bg="grey") c2.place(x=50, y=450) def pushOn1(): arme = Label(root, text="On", bg="red", font=("bold", 20)).place(x = 190, y = 620) GPIO.setup(LED2,GPIO.OUT) print("Lumi�re salon allum�e:-", ct) btn4 = Button(root, text='On', width=10, height=5, bd='10', command = pushOn1) def pushOff1(): arme = Label(root, text="Off", bg="red", font=("bold", 20)).place(x = 190, y = 620) print("Lumi�re salon ferm�e:-", ct) btn5 = Button(root, text='Off', width=10, height=5, bd='10', command = pushOff1) btn4.place(x=65, y=500) btn5.place(x=225, y=500) title2 = Label(root, text="Lumi�re salon", bg="grey", font=("bold", 20)).place(x = 110, y = 460) #title2.pack() #3e Bouton historique c3 = Canvas(root, width=330, height=280, bg="grey") c3.place(x=50, y=650) def Histo(): root = Tk() root.title('Historique') root.geometry('630x450') resultat = Text(root) #resultat.config(width=630, height = 450) #resultat.insert(Insert, "Date\ tHeure\ t�v�nement\n==============\n") resultat.grid(row = 0, column = 0, columnspan = 2) bouton = Button(root, text = "Quitter", command = root.destroy) bouton.grid(row = 1, column = 1) root.mainloop() btn6 = Button(root, text='Afficher', width=28, height=3, bd='10', command = Histo) btn6.place(x=65, y=700) title3 = Label(root, text="Historique", bg="grey", font=("bold", 20)).place(x = 150, y = 660) #title3.pack() root.mainloop()