class ServerGui(Tk.Tk, object): def __init__(self): super(ServerGui, self).__init__() self.title('Distributed Systems - 802.15.1') frame_main = Tk.Frame(self) frame_main.grid(sticky='nswe', padx=15, pady=15) frame_list = Tk.LabelFrame(frame_main, text='Rede Bluetooth') frame_list.grid(sticky='we') self.list = Tk.Listbox(frame_list, height=39, width=70) self.list.grid(row=0, column=0, sticky='we') scrollbar_list = Tk.Scrollbar(frame_list, command=self.list.yview) scrollbar_list.grid(row=0, column=1, sticky='nsew') self.list['yscrollcommand'] = scrollbar_list.set self.pi = Pi() self.pi.start() self.after(1000, self.keep_updating) def update_list(self): counter = sorted(self.pi.devices.items(), key=operator.itemgetter(0)) self.list.delete(0, Tk.END) if counter: for device, level in counter: self.list.insert(Tk.END, device + ' ' + str(level)) else: self.list.insert(Tk.END, 'There are no active devices') def keep_updating(self): self.update_list() self.after(1000, self.keep_updating)
def __init__(self): Pi.__init__(self) self.self_map = ("B", "R") self.intersock = CN_Sockets.socket(2,2) self.intersock.bind(("192.168.128.104",2048)) # changed to pi IP address and port 2048 self.routing_Thread = threading.Thread(target = self.route_packets) self.routing_Thread.start() self.sock.close() # router doesn't run internal morse server
def __init__(self): Pi.__init__(self) self.self_map = ("B", "R") self.intersock = CN_Socketssocket(2, 2) self.intersock.bind(("192.168.128.102", 2048)) # changed to pi IP address and port 2048 self.routing_Thread = threading.Thread(target=self.route_packets) self.routing_Thread.start() self.sock.close() # router doesn't run internal morse server
def main(): init() t = 0.5 # Tell user we are starting onebyone(0.15) onebyone(0.15, False) off() sleep(1.5) pi = Pi() for c in pi.generator(): number(c, t)
def __init__(self): self.pis = {} self.is_enabled = {} for pi in Pi.get_pis(): ps = pi.get("status") if (ps.code == 0): self.pis[ps.content["feeder_status"]["feeder_number"]] = pi
def __init__(self): self.pis = {} for pi in Pi.get_pis(): ps = pi.get("status") if (ps.code == 0): doors_status = ps.content["door_status"] for door_status in doors_status: self.pis[door_status["door_number"]] = pi
class PiProxy(ICyfryPi): """ Proxy wirtualne dla klasy Pi """ def __init__(self): """ Konstruktor inicjalizujący proxy pi""" self.__pi = None def cyfra(self, pozycja: int) -> str: """ Funkcja zwracająca cyfrę liczby pi na danej pozycji """ if self.__pi == None: from pi import Pi self.__pi = Pi() return self.__pi.cyfra(pozycja) def cyfry(self, od: int, do: int) -> str: """ Funkcja zwracająca cyfry o pozycjach [od, do) """ if self.__pi == None: from pi import Pi self.__pi = Pi() return self.__pi.cyfry(od, do)
def pi(): pi_id = request.args.get('pi_id', None) user_id = request.args.get('user_id', None) location = request.args.get('location', None) serial_number = request.args.get('serial_number', None) if (pi_id == None) and (user_id == None) and (location == None) and (serial_number == None): data = request.get_json() if request.method in {'GET', 'PUT', 'DELETE'}: pi_id = data['pi_id'] if request.method in {'PUT', 'POST'}: user_id = data['user_id'] location = data['location'] serial_number = data['serial_number'] # Get a specific pi based on pi id if request.method == 'GET': pi = session.query(Pi).filter_by(pi_id=pi_id).one() return pi_schema.jsonify(pi) # Update a specific pi based on pi id and information given if request.method == 'PUT': updatedPi = session.query(Pi).filter_by(pi_id=pi_id).one() updatedPi.user_id = user_id updatedPi.location = location session.commit() return pi_schema.jsonify(updatedPi) # Create a new pi in the database if request.method == 'POST': newPi = Pi(user_id, location, serial_number) session.add(newPi) session.commit() return pi_schema.jsonify(newPi) # Delete an existing pi from the database if request.method == 'DELETE': deletedPi = session.query(Pi).filter_by(pi_id=pi_id).one() session.delete(deletedPi) session.commit() return pi_schema.jsonify(deletedPi) return
class Pot(object): server = "covfefemat" version = 0.01 host = 'localhost' port = 80 logging.basicConfig(format='%(asctime)s $(levelname)s: %(message)s') logging.info("Initialising: %s/%d %s:%d", server, version, host, port) response = flask.Response() response.headers['Server'] = server + "/" + str(version) + " Python" + "/" + str(platform.python_version()) global control def __init__(self, name), gpio_port): self.name = name self.gpio_port = gpio_port control = Pi("Pi") gpio_port)
def __init__(self): super(ServerGui, self).__init__() self.title('Distributed Systems - 802.15.1') frame_main = Tk.Frame(self) frame_main.grid(sticky='nswe', padx=15, pady=15) frame_list = Tk.LabelFrame(frame_main, text='Rede Bluetooth') frame_list.grid(sticky='we') self.list = Tk.Listbox(frame_list, height=39, width=70) self.list.grid(row=0, column=0, sticky='we') scrollbar_list = Tk.Scrollbar(frame_list, command=self.list.yview) scrollbar_list.grid(row=0, column=1, sticky='nsew') self.list['yscrollcommand'] = scrollbar_list.set self.pi = Pi() self.pi.start() self.after(1000, self.keep_updating)
def status(self): s = self.experiment.status() if s.code == 0: message = s.message for pi in Pi.get_pis(): message += "\nPi at %s: " % pi.address ps = pi.get("status") if ps.code: message += "error\n" else: message += "ok\n" for door_status in ps.content["door_status"]: message += ("door %d: " % door_status["door_number"] ) + door_status["state"] + "\n" message += ("feeder %d: " % ps.content["feeder_status"]["feeder_number"] ) + ps.content["feeder_status"]["state"] return Result(0, message) else: return s
def cyfra(self, pozycja: int) -> str: """ Funkcja zwracająca cyfrę liczby pi na danej pozycji """ if self.__pi == None: from pi import Pi self.__pi = Pi() return self.__pi.cyfra(pozycja)
def cyfry(self, od: int, do: int) -> str: """ Funkcja zwracająca cyfry o pozycjach [od, do) """ if self.__pi == None: from pi import Pi self.__pi = Pi() return self.__pi.cyfry(od, do)
def set_image(self, screen): self.screen = screen def show(self): filename = f"img/{self.times}-{uuid.uuid4().hex}.png" if self.screen: self.screen.save(filename) self.times += 1 # 212x104 if __name__ == "__main__": logging.basicConfig(filename='info.log', filemode='w', level=logging.DEBUG) inky = InkyPHAT('black') if RUNNING_ON_PI else InkyMock() pi = Pi(inky) # 10 x 6 GRID upscale = CONFIG["UPSCALE"] TOP_HALF = Position.grid_to_pixels("FIRST_10", "FIRST_3", border=1, upscale=upscale) BOTTOM = Position.grid_to_pixels("LAST_10", "LAST_2", border=1, upscale=upscale) # BOTTOM_LEFT = Position.grid_to_pixels("FIRST_4", "LAST_2", border = 1, upscale = upscale) MIDDLE_LEFT = Position.grid_to_pixels("FIRST_4", "FROM_3_TO_4", border=1, upscale=upscale)