def __init__(self): MQTT_Client.__init__(self) self.sensor = W1ThermSensor() self.current_temp = 0.0 # self.my_topic = ("TEMP", QOS_1) self.my_topic = TOPICS['temp'] # The frequency of sampling the temperature self.sampling_period = 3 * 60 self.id = 3
def __init__(self): # Setup the MQTT stuff from parent # Initialize the MQTT_client parent class MQTT_Client.__init__(self) # Store what topics to listen to self.my_topics = [TOPICS['temp'], TOPICS['temp_setpoint'], TOPICS['ping']] # Subscribe to the topics. This is done by letter asyncio-loop run that co-routine until completion # I.e. we will do that before continuting to the rest of the program. self.loop.run_until_complete(self.subscribe_to(self.my_topics)) self.id = 1 self.remote_poll_interval = 60
def __init__(self): # Setup the MQTT stuff from parent # Initialize the MQTT_client parent class MQTT_Client.__init__(self) # Define my_topic #self.my_topic = [("TEMP", QOS_1)] self.my_topic = [TOPICS['temp']] # Subscribe to the topic. This is done by letter asyncio-loop run that co-routine until completion # I.e. we will do that before continuting to the rest of the program. self.loop.run_until_complete(self.subscribe_to(self.my_topic)) self.id = 2
def __init__(self): # Setup the MQTT stuff from parent # Initialize the MQTT_client parent class MQTT_Client.__init__(self) # Define my_topic self.my_topic = [TOPICS['temp_setpoint'], TOPICS['temp']] # Subscribe to the topic. This is done by letter asyncio-loop run that co-routine until completion # I.e. we will do that before continuting to the rest of the program. self.loop.run_until_complete(self.subscribe_to(self.my_topic)) self.current_control_policy = logger.get_current_control_policy() self.current_temp = logger.get_current_temp() self.current_hour = datetime.now().hour self.id = 4
class IoT_Device(TaskSet): def on_start(self): self.device_id = random.randint(1, 101) self.client_mqtt = MQTT_Client() self.client_mqtt.connect() @seq_task(1) @task(2) def loop(self): self.client_mqtt.loop() @seq_task(2) @task(1) def publish(self): self.client_mqtt.publishing()
class IoT_Device(TaskSet): def on_start(self): self.device_id = cache.next_device_id() self.client_mqtt = MQTT_Client(self.device_id, filename_dir) self.client_mqtt.connect() self.init_time = 0.0 @task def publish(self): if time.time() - self.init_time >= 30.0: self.init_time = time.time() self.client_mqtt.publishing(self.device_id) self.client_mqtt.loop(0.05)
def __init__(self, *args, **kwargs): ##MQTT STUFF # Setup the MQTT stuff from parent # Initialize the MQTT_client parent class MQTT_Client.__init__(self) # Define my_topic #self.my_topic = [("TEMP", QOS_1)] self.my_topic = [ TOPICS['temp'], TOPICS['temp_setpoint'], TOPICS['controller'] ] # Subscribe to the topic. This is done by letter asyncio-loop run that co-routine until completion # I.e. we will do that before continuting to the rest of the program. self.loop.run_until_complete(self.subscribe_to(self.my_topic)) self.id = 2 self.current_temp = logger.get_current_temp() self.current_control = logger.get_current_control_policy() self.heater = "N/A" self.ac = "N/A" ## TKINTER STUFF self.root = tk.Tk() h = self.root.winfo_screenheight() w = self.root.winfo_screenwidth() self.root.overrideredirect(True) self.root.geometry("{0}x{1}+0+0".format(w, h)) self.tk_interval = 0.05 self.root.pack_propagate(0) self.root.grid_propagate(0) # Make the root container which contains menu and page main_window = tk.Frame(self.root, height=h, width=w) main_window.pack(side=tk.TOP, anchor=tk.N, fill=tk.BOTH, expand=False) # make the menu frame menu = tk.Frame(master=main_window, bg='lightblue', width=w, height=MENU_BUTTON_HEIGHT) page = tk.Frame(master=main_window, width=w, height=h - MENU_BUTTON_HEIGHT) # Make buttons in menu self.button_dashboard = tk.Button( menu, text="Dashboard", bg=MENU_COLOR_RGB, font=MENU_BUTTON_FONT, width=MENU_BUTTON_WIDTH, fg=MENU_COLOR_FG_RGB, height=MENU_BUTTON_HEIGHT, command=lambda: self.show_frame(Dashboard), relief=tk.SUNKEN) self.button_dashboard.pack(side=tk.LEFT) self.button_control = tk.Button( menu, text="Control Policy", bg=MENU_COLOR_RGB, font=MENU_BUTTON_FONT, fg=MENU_COLOR_FG_RGB, width=MENU_BUTTON_WIDTH, height=MENU_BUTTON_HEIGHT, command=lambda: self.show_frame(UpdateControlPolicy), relief=tk.RAISED) self.button_control.pack(side=tk.LEFT) self.button_statistics = tk.Button( menu, text="Statistics", bg=MENU_COLOR_RGB, font=MENU_BUTTON_FONT, width=MENU_BUTTON_WIDTH, fg=MENU_COLOR_FG_RGB, height=MENU_BUTTON_HEIGHT, command=lambda: self.show_frame(Statistics), relief=tk.RAISED) self.button_statistics.pack(side=tk.LEFT) self.button_about = tk.Button(menu, text="About", bg=MENU_COLOR_RGB, fg=MENU_COLOR_FG_RGB, font=MENU_BUTTON_FONT, width=MENU_BUTTON_WIDTH, height=MENU_BUTTON_HEIGHT, command=lambda: self.show_frame(About), relief=tk.RAISED) self.button_about.pack(side=tk.LEFT) self.button_quit = tk.Button(menu, text="Quit", bg=MENU_COLOR_RGB, fg=MENU_COLOR_FG_RGB, font=MENU_BUTTON_FONT, width=MENU_BUTTON_WIDTH, height=MENU_BUTTON_HEIGHT, command=lambda: self.shut_down(), relief=tk.RAISED) self.button_quit.pack(side=tk.LEFT) # Pack menu and page menu.pack(side=tk.TOP, fill=tk.BOTH, expand=False) page.pack(side=tk.TOP, fill=tk.BOTH, expand=False) # Make all the frames and stack them ontop of each other self.frames = {} for F in (Dashboard, UpdateControlPolicy, Statistics, About): frame = F(page, self) self.frames[F] = frame frame.grid(row=0, column=0, sticky="wens") # Current page=button is pressed self.menu_button_map = { 'Dashboard': self.button_dashboard, 'UpdateControlPolicy': self.button_control, 'Statistics': self.button_statistics, 'About': self.button_about } self.current_button = self.button_dashboard self.show_frame(Dashboard)
def on_start(self): self.device_id = random.randint(1, 101) self.client_mqtt = MQTT_Client() self.client_mqtt.connect()
def on_start(self): self.device_id = cache.next_device_id() self.client_mqtt = MQTT_Client(self.device_id, filename_dir) self.client_mqtt.connect() self.init_time = 0.0