Example #1
0
    def __init__(self):
        self.bttn1_value = False

        # Catch CNTRL-C signel
        signal.signal(signal.SIGINT, self.signal_cntrl_c)
        self.shutdown = False
        args = self.parse_commandline_arguments()
        self.init_logging(args.logfilename, args.verbose)

        logging.info("Connecting to server: %s", args.server)
        logging.info("       Connection ID: %s", args.connection)
        logging.info("       Control topic: %s/%s/%s/control", args.username,
                     args.connection, args.device_id)
        logging.info("          Data topic: %s/%s/%s/data", args.username,
                     args.connection, args.device_id)

        device = dashio.dashDevice(args.connection, args.device_id,
                                   args.device_name)
        dash_conn = dashio.dashConnection(args.username, args.password)
        dash_conn.add_device(device)

        el = dashio.EventLog("ELTest")
        el_page = dashio.Page("el_page", "Event Log Test")
        el_page.add_control(el)
        device.add_control(el)
        device.add_control(el_page)

        self.connection = args.connection
        count = 1
        while not self.shutdown:
            time.sleep(5)
            el.add_event_data("Hello:{}".format(count), "Testing")
            count += 1
        device.close()
Example #2
0
def main():
    # Catch CNTRL-C signel
    global shutdown
    signal.signal(signal.SIGINT, signal_cntrl_c)

    args = parse_commandline_arguments()
    print("Connecting to server: {}".format(args.server))
    print("       Connection ID: {}".format(args.connection))
    print("       Control topic: %s/%s/%s/control", args.username,
          args.connection, args.device_id)
    print("          Data topic: %s/%s/%s/data", args.username,
          args.connection, args.device_id)

    device = dashio.dashDevice(args.connection, args.device_id,
                               args.device_name)
    dash_conn = dashio.dashConnection(args.username, args.password)
    dash_conn.add_device(device)

    my_map = dashio.Map("MAP1")
    my_map.title = "A cool map"
    myloc = dashio.MapLocation("James Peak", -45.237101516008835,
                               168.84818243505748)
    my_map.add_location(myloc)
    device.add_control(my_map)

    while not shutdown:
        time.sleep(1)

    device.close()
Example #3
0
    def __init__(self):

        # Catch CNTRL-C signel
        signal.signal(signal.SIGINT, self.signal_cntrl_c)
        self.shutdown = False
        args = self.parse_commandline_arguments()
        self.init_logging(args.logfilename, args.verbose)

        logging.info("   Serving on: %s", args.server)
        logging.info("  Device Type: %s", args.device_type)
        logging.info("    Device ID: %s", args.device_id)
        logging.info("  Device Name: %s", args.device_name)

        self.device = dashio.dashDevice(args.device_type, args.device_id, args.device_name)
        #self.tcp_con = dashio.tcpConnection(port=args.port)
        self.dash_con = dashio.dashConnection(args.username, args.password)
        #self.tcp_con.add_device(self.device)
        self.dash_con.add_device(self.device)
        self._init_knobs()
        self._init_buttons()
        self._init_dials()
        self._init_event_log()
        self._init_graph()
        self._init_labels()
        self._init_map()
        self._init_menu()
        self._init_selector()
        self._init_text_box()
        self._init_time_graph()
        while not self.shutdown:
            time.sleep(5)
            self.compass.direction_value = random.random() * 360
            ed = dashio.EventData("Compass Direction", "{:.2f}".format(self.compass.direction_value))
            self.event_log.add_event_data(ed)
            if len(self.event_log.log_list) > 15:
                self.event_log.log_list.pop(0)
            self.dial_std.dial_value = random.random() * 100
            self.dial_inv.dial_value = random.random() * 100

        self.device.send_popup_message("TestControls", "Shutting down", "Goodbye")
        self.device.close()
    def __init__(self):
        self.bttn1_value = False

        # Catch CNTRL-C signel
        signal.signal(signal.SIGINT, self.signal_cntrl_c)
        self.shutdown = False
        args = self.parse_commandline_arguments()
        self.init_logging(args.logfilename, args.verbose)

        logging.info("Connecting to server: %s", args.server)
        logging.info("         Device Type: %s", args.device_type)
        logging.info("       Control topic: %s/%s/control", args.username,
                     args.device_id)
        logging.info("          Data topic: %s/%s/data", args.username,
                     args.device_id)

        device = dashio.dashDevice(args.device_type, args.device_id,
                                   args.device_name)

        while not self.shutdown:
            time.sleep(5)

        device.close()
Example #5
0
    def __init__(self):

        # Catch CNTRL-C signel
        signal.signal(signal.SIGINT, self.signal_cntrl_c)
        self.shutdown = False
        args = self.parse_commandline_arguments()
        self.init_logging(args.logfilename, args.verbose)

        logging.info("   Serving on: ZMQ")
        logging.info("Connection ID: %s", args.connection)
        logging.info("    Device ID: %s", args.device_id)
        logging.info("  Device Name: %s", args.device_name)

        self.device = dashio.dashDevice(args.connection, args.device_id,
                                        args.device_name)
        time.sleep(1)
        self.zmq_con = dashio.zmqConnection(pub_port=args.pub_port,
                                            sub_port=args.sub_port)
        time.sleep(1)
        self.zmq_con.add_device(self.device)

        self.connection = args.connection
        self.page_name = "TestZMQ: " + platform.node()

        self.page_test = dashio.Page("TestZMQ", self.page_name, 1)
        self.up_btn = dashio.Button("UP_BTN",
                                    control_position=dashio.ControlPosition(
                                        0.02, 0.01, 0.22, 0.12))
        self.up_btn.btn_state = dashio.ButtonState.OFF
        self.up_btn.icon_name = dashio.Icon.UP
        self.up_btn.on_color = dashio.Color.GREEN
        self.up_btn.text = ""
        self.up_btn.text_color = dashio.Color.WHITE
        self.up_btn.title = "Up"
        self.up_btn.message_rx_event += self.up_btn_event_handler
        self.page_test.add_control(self.up_btn)

        self.down_btn = dashio.Button("DOWN_BTN",
                                      control_position=dashio.ControlPosition(
                                          0.02, 0.78, 0.22, 0.12))
        self.down_btn.btn_state = dashio.ButtonState.OFF
        self.down_btn.icon_name = dashio.Icon.DOWN
        self.down_btn.on_color = dashio.Color.GREEN
        self.down_btn.text = ""
        self.down_btn.text_color = dashio.Color.WHITE
        self.down_btn.title = "Down"
        self.down_btn.message_rx_event += self.down_btn_event_handler
        self.page_test.add_control(self.down_btn)

        self.sldr_cntrl = dashio.SliderSingleBar(
            "SLDR",
            control_position=dashio.ControlPosition(0.02, 0.13, 0.22, 0.65))
        self.sldr_cntrl.title = "Slider"
        self.sldr_cntrl.max = 10
        self.sldr_cntrl.slider_enabled = True
        self.sldr_cntrl.red_value
        self.sldr_cntrl.message_rx_event += self.slider_event_handler
        self.page_test.add_control(self.sldr_cntrl)

        self.sldr_dbl_cntrl = dashio.SliderDoubleBar(
            "SLDR_DBL",
            control_position=dashio.ControlPosition(0.78, 0.01, 0.2, 0.89))
        self.sldr_dbl_cntrl.title = "Slider Double"
        self.sldr_dbl_cntrl.max = 5
        self.sldr_dbl_cntrl.slider_enabled = True
        self.sldr_dbl_cntrl.red_value
        self.sldr_dbl_cntrl.message_rx_event += self.slider_dbl_event_handler
        self.page_test.add_control(self.sldr_dbl_cntrl)

        self.knb_control = dashio.Knob("KNB",
                                       control_position=dashio.ControlPosition(
                                           0.24, 0.14, 0.54, 0.21))
        self.knb_control.title = "A Knob"
        self.knb_control.max = 10
        self.knb_control.red_value = 10
        self.knb_control.message_rx_event += self.knob_event_handler
        self.page_test.add_control(self.knb_control)

        self.dl_control = dashio.Dial("DIAL1",
                                      control_position=dashio.ControlPosition(
                                          0.24, 0.57, 0.54, 0.21))
        self.dl_control.title = "A Dial"
        self.dl_control.max = 10
        self.page_test.add_control(self.dl_control)

        self.text_cntrl = dashio.TextBox(
            "TXT1",
            control_position=dashio.ControlPosition(0.24, 0.78, 0.54, 0.12))
        self.text_cntrl.text = "Hello"
        self.text_cntrl.title = "A text control"
        self.text_cntrl.keyboard_type = dashio.Keyboard.ALL_CHARS
        self.text_cntrl.close_key_board_on_send = True
        self.text_cntrl.message_rx_event += self.text_cntrl_message_handler
        self.page_test.add_control(self.text_cntrl)

        self.alarm_ctrl = dashio.Alarm("TestingAlarms", "Test Alarms", "Hello",
                                       "Test of Shared Alarms")
        self.device.add_control(self.alarm_ctrl)
        self.comp_control = dashio.Compass(
            "COMP1",
            control_position=dashio.ControlPosition(0.24, 0.35, 0.54, 0.22))
        self.comp_control.title = "A compass"
        self.page_test.add_control(self.comp_control)

        self.selector_ctrl = dashio.Selector(
            "TestSelector",
            "A Selector",
            control_position=dashio.ControlPosition(0.24, 0.01, 0.54, 0.13))
        self.selector_ctrl.message_rx_event += self.selector_ctrl_handler
        self.selector_ctrl.add_selection("First")
        self.selector_ctrl.add_selection("Second")
        self.selector_ctrl.add_selection("Third")
        self.selector_ctrl.add_selection("Forth")
        self.selector_ctrl.add_selection("Fifth")

        self.page_test.add_control(self.selector_ctrl)

        self.label_ctrl = dashio.Label(
            "LabelID",
            "A label",
            style=dashio.LabelStyle.GROUP,
            color=dashio.Color.BLUE,
            control_position=dashio.ControlPosition(0.0, 0.0, 1.0, 0.93),
        )
        self.page_test.add_control(self.label_ctrl)

        self.device.add_control(self.label_ctrl)
        self.device.add_control(self.page_test)
        self.device.add_control(self.selector_ctrl)
        self.device.add_control(self.comp_control)
        self.device.add_control(self.text_cntrl)
        self.device.add_control(self.dl_control)
        self.device.add_control(self.knb_control)
        self.device.add_control(self.sldr_dbl_cntrl)
        self.device.add_control(self.sldr_cntrl)
        self.device.add_control(self.down_btn)
        self.device.add_control(self.up_btn)

        while not self.shutdown:
            time.sleep(5)
            self.comp_control.direction_value = random.random() * 360

        self.device.send_popup_message("TestControls", "Shutting down",
                                       "Goodbye")
        time.sleep(1)
        self.device.close()
        self.zmq_con.close()
Example #6
0
    def __init__(self):

        # Catch CNTRL-C signel
        signal.signal(signal.SIGINT, self.signal_cntrl_c)
        self.shutdown = False
        args = self.parse_commandline_arguments()
        self.init_logging(args.logfilename, args.verbose)

        logging.info("Connecting to server: %s", args.server)
        logging.info("       Connection ID: %s", args.connection)
        logging.info("       Control topic: %s/%s/%s/control", args.username,
                     args.connection, args.device_id)
        logging.info("          Data topic: %s/%s/%s/data", args.username,
                     args.connection, args.device_id)

        device = dashio.dashDevice(args.connection, args.device_id,
                                   args.device_name)
        dash_conn = dashio.dashConnection(args.username, args.password)
        dash_conn.add_device(device)

        self.page_test = dashio.Page("TestPage", "Testing Pages", 1)
        self.up_btn = dashio.Button("UP_BTN")
        self.up_btn.btn_state = dashio.ButtonState.OFF
        self.up_btn.icon_name = dashio.Icon.UP
        self.up_btn.on_color = dashio.Color.GREEN
        self.up_btn.text = ""
        self.up_btn.text_color = dashio.Color.WHITE
        self.up_btn.title = "Up"
        self.up_btn.message_rx_event += self.up_btn_event_handler
        device.add_control(self.up_btn)
        self.page_test.add_control(self.up_btn)

        self.down_btn = dashio.Button("DOWN_BTN")
        self.down_btn.btn_state = dashio.ButtonState.OFF
        self.down_btn.icon_name = dashio.Icon.DOWN
        self.down_btn.on_color = dashio.Color.GREEN
        self.down_btn.text = ""
        self.down_btn.text_color = dashio.Color.WHITE
        self.down_btn.title = "Down"
        self.down_btn.message_rx_event += self.down_btn_event_handler
        device.add_control(self.down_btn)
        self.page_test.add_control(self.down_btn)

        self.sldr_cntrl = dashio.SliderSingleBar("SLDR")
        self.sldr_cntrl.title = "Slider"
        self.sldr_cntrl.max = 10
        self.sldr_cntrl.slider_enabled = True
        self.sldr_cntrl.red_value
        self.sldr_cntrl.message_rx_event += self.slider_event_handler
        device.add_control(self.sldr_cntrl)
        self.page_test.add_control(self.sldr_cntrl)

        self.sldr_dbl_cntrl = dashio.SliderDoubleBar("SLDR_DBL")
        self.sldr_dbl_cntrl.title = "Slider Double"
        self.sldr_dbl_cntrl.max = 5
        self.sldr_dbl_cntrl.slider_enabled = True
        self.sldr_dbl_cntrl.red_value
        self.sldr_dbl_cntrl.message_rx_event += self.slider_dbl_event_handler
        device.add_control(self.sldr_dbl_cntrl)
        self.page_test.add_control(self.sldr_dbl_cntrl)

        self.knb_control = dashio.Knob("KNB")
        self.knb_control.title = "A Knob"
        self.knb_control.max = 10
        self.knb_control.red_value = 10
        self.knb_control.message_rx_event += self.knob_event_handler
        device.add_control(self.knb_control)
        self.page_test.add_control(self.knb_control)

        self.dl_control = dashio.Dial("DIAL1")
        self.dl_control.title = "A Dial"
        self.dl_control.max = 10
        device.add_control(self.dl_control)
        self.page_test.add_control(self.dl_control)

        self.text_cntrl = dashio.TextBox("TXT1")
        self.text_cntrl.text = "Hello"
        self.text_cntrl.title = "A text control"
        self.text_cntrl.keyboard_type = dashio.Keyboard.ALL_CHARS
        self.text_cntrl.close_key_board_on_send = True
        self.text_cntrl.message_rx_event += self.text_cntrl_message_handler
        device.add_control(self.text_cntrl)
        self.page_test.add_control(self.text_cntrl)

        self.alarm_ctrl = dashio.Alarm("TestingAlarms", "Test Alarms", "Hello",
                                       "Test of Shared Alarms")
        device.add_control(self.alarm_ctrl)
        self.comp_control = dashio.Compass("COMP1")
        self.comp_control.title = "A compass"
        device.add_control(self.comp_control)
        self.page_test.add_control(self.comp_control)

        self.selector_ctrl = dashio.Selector("TestSelector", "A Selector")
        self.selector_ctrl.message_rx_event += self.selector_ctrl_handler
        self.selector_ctrl.add_selection("First")
        self.selector_ctrl.add_selection("Second")
        self.selector_ctrl.add_selection("Third")
        self.selector_ctrl.add_selection("Forth")
        self.selector_ctrl.add_selection("Fifth")
        device.add_control(self.selector_ctrl)
        self.page_test.add_control(self.selector_ctrl)

        self.label_ctrl = dashio.Label("LabelID",
                                       "A label",
                                       color=dashio.Color.BLUE)
        device.add_control(self.label_ctrl)
        self.page_test.add_control(self.label_ctrl)
        device.add_control(self.page_test)

        while not self.shutdown:
            time.sleep(5)

            self.comp_control.direction_value = random.random() * 360

        device.send_popup_message("TestControls", "Shutting down", "Goodbye")
        device.close()
Example #7
0
    def __init__(self):
        self.shutdown = False

        signal.signal(signal.SIGINT, self.signal_cntrl_c)
        args = self.parse_commandline_arguments()

        self.init_logging(args.logfilename, args.verbose)

        logging.info("Connecting to server: %s", args.server)
        logging.info("       Connection ID: %s", args.connection)
        logging.info("       Control topic: %s/%s/%s/control", args.username,
                     args.connection, args.device_id)
        logging.info("          Data topic: %s/%s/%s/data", args.username,
                     args.connection, args.device_id)

        device = dashio.dashDevice(args.connection, args.device_id,
                                   args.device_name)
        dash_conn = dashio.dashConnection(args.username, args.password)
        dash_conn.add_device(device)

        self.tapage = dashio.Page("testAlarm", "Test Alarm")
        self.alarm_btn1 = dashio.Button("ALARM_BTN1")
        self.tapage.add_control(self.alarm_btn1)
        self.alarm_btn1.title = "A1"
        self.alarm_btn1.btn_state = dashio.ButtonState.OFF
        self.alarm_btn1.icon_name = dashio.Icon.BELL
        self.alarm_btn1.on_color = dashio.Color.RED
        self.alarm_btn1.text_color = dashio.Color.BLUE
        self.alarm_btn1.message_rx_event += self.alarm_btn1_handler
        device.add_control(self.alarm_btn1)

        self.alarm_btn2 = dashio.Button("ALARM_BTN2")
        self.alarm_btn2.title = "A2"
        self.alarm_btn2.btn_state = dashio.ButtonState.OFF
        self.alarm_btn2.icon_name = dashio.Icon.BELL
        self.alarm_btn2.on_color = dashio.Color.RED
        self.alarm_btn2.text_color = dashio.Color.BLUE
        self.alarm_btn2.message_rx_event += self.alarm_btn2_handler
        device.add_control(self.alarm_btn2)
        self.tapage.add_control(self.alarm_btn2)

        self.alarm_btn3 = dashio.Button("ALARM_BTN3")
        self.alarm_btn3.title = "A3"
        self.alarm_btn3.btn_state = dashio.ButtonState.OFF
        self.alarm_btn3.icon_name = dashio.Icon.BELL
        self.alarm_btn3.on_color = dashio.Color.RED
        self.alarm_btn3.text_color = dashio.Color.BLUE
        self.alarm_btn3.message_rx_event += self.alarm_btn3_handler
        device.add_control(self.alarm_btn3)
        self.tapage.add_control(self.alarm_btn3)

        self.alarm1_ctrl = dashio.Alarm("TestingAlarms1", "Alarm1",
                                        "Hello from Alarm1", "Alarm1")
        self.alarm2_ctrl = dashio.Alarm("TestingAlarms2", "Alarm2",
                                        "Hello from Alarm2", "Alarm2")
        self.alarm3_ctrl = dashio.Alarm("TestingAlarms3", "Alarm3",
                                        "Hello from Alarm3", "Alarm3")
        device.add_control(self.alarm1_ctrl)
        device.add_control(self.alarm2_ctrl)
        device.add_control(self.alarm3_ctrl)
        self.tapage.add_control(self.alarm1_ctrl)
        self.tapage.add_control(self.alarm2_ctrl)
        self.tapage.add_control(self.alarm3_ctrl)
        device.add_control(self.tapage)

        while not self.shutdown:
            time.sleep(1)

        device.close()
Example #8
0
    def __init__(self):
        self.bttn1_value = False
        LOGGER_PERIOD = 5
        # Catch CNTRL-C signel
        signal.signal(signal.SIGINT, self.signal_cntrl_c)
        self.shutdown = False
        args = self.parse_commandline_arguments()
        self.init_logging(args.logfilename, args.verbose)

        logging.info("Connecting to server: %s", args.server)
        logging.info("       Connection ID: %s", args.connection)
        logging.info("       Control topic: %s/%s/%s/control", args.username,
                     args.connection, args.device_id)
        logging.info("          Data topic: %s/%s/%s/data", args.username,
                     args.connection, args.device_id)

        device = dashio.dashDevice(args.connection, args.device_id,
                                   args.device_name)
        dash_conn = dashio.dashConnection(args.username, args.password)
        dash_conn.add_device(device)

        self.gph_15_minutes = dashio.TimeGraph("TestGraph")
        self.gph_15_minutes.title = "Test: {}".format(args.connection)
        self.gph_15_minutes.time_scale = dashio.TimeGraphTimeScale.FIFTEENMINS
        self.gph_15_minutes.y_axis_label = "Units"
        self.gph_15_minutes.y_axis_min = -10.0
        self.gph_15_minutes.y_axis_max = 10.0
        self.gph_15_minutes.y_axis_num_bars = 9
        self.line_15_minutes = dashio.TimeGraphLine(
            "Line",
            dashio.TimeGraphLineType.LINE,
            color=dashio.Color.BLACK,
            max_data_points=15 * 60 / LOGGER_PERIOD)
        self.bar_15_minutes = dashio.TimeGraphLine(
            "Bar",
            dashio.TimeGraphLineType.BAR,
            transparency=0.45,
            color=dashio.Color.ORANGE,
            max_data_points=15 * 60 / LOGGER_PERIOD,
        )
        self.bin_15_minutes = dashio.TimeGraphLine(
            "Bin",
            dashio.TimeGraphLineType.BOOL,
            transparency=0.45,
            color=dashio.Color.YELLOW,
            max_data_points=15 * 60 / LOGGER_PERIOD,
        )
        self.am_pm_15_minutes = dashio.TimeGraphLine(
            "Hour",
            dashio.TimeGraphLineType.BOOL,
            transparency=0.30,
            color=dashio.Color.SILVER,
            max_data_points=15 * 60 / LOGGER_PERIOD,
        )
        self.gph_15_minutes.add_line("line", self.line_15_minutes)
        self.gph_15_minutes.add_line("Bar", self.bar_15_minutes)
        self.gph_15_minutes.add_line("Bin", self.bin_15_minutes)
        self.gph_15_minutes.add_line("Hour", self.am_pm_15_minutes)
        self.gph_15_minutes.message_rx_event += self.gph_15_minutes_event_handler
        device.add_control(self.gph_15_minutes)

        line_data = 0
        bar_data = 0
        line_dir_up = True
        bar_dir_up = False
        bin_data = False
        am_pm_data = True
        t = datetime.datetime.now()
        if (t.hour % 2) == 0:
            am_pm_data = True
        else:
            am_pm_data = False
        while not self.shutdown:
            if line_data > 9.5:
                line_dir_up = False
            elif line_data < -9.5:
                line_dir_up = True
            if line_dir_up:
                line_data += random.random()
            else:
                line_data -= random.random()
            if bar_data > 9.5:
                bar_dir_up = False
            elif bar_data < -9.5:
                bar_dir_up = True
            if bar_dir_up:
                bar_data += random.random()
            else:
                bar_data -= random.random()
            if line_data > bar_data:
                bin_data = True
            else:
                bin_data = False
            if (t.hour % 2) == 0:
                am_pm_data = True
            else:
                am_pm_data = False
            self.am_pm_15_minutes.add_data_point(am_pm_data)
            self.line_15_minutes.add_data_point(line_data)
            self.bar_15_minutes.add_data_point(bar_data)
            self.bin_15_minutes.add_data_point(bin_data)
            self.gph_15_minutes.send_data()

            tstamp = datetime.datetime.now()
            seconds_left = tstamp.second + tstamp.microsecond / 1000000.0
            div, sleep_time = divmod(seconds_left, LOGGER_PERIOD)
            sleep_time = LOGGER_PERIOD - sleep_time
            time.sleep(sleep_time)

        device.close()
Example #9
0
    def __init__(self):

        # Catch CNTRL-C signel
        signal.signal(signal.SIGINT, self.signal_cntrl_c)
        self.shutdown = False
        args = self.parse_commandline_arguments()
        self.init_logging(args.logfilename, args.verbose)

        logging.info("Connecting to server: %s", args.server)
        logging.info("       Connection ID: %s", args.connection)
        logging.info("       Control topic: %s/%s/%s/control", args.username,
                     args.connection, args.device_id)
        logging.info("          Data topic: %s/%s/%s/data", args.username,
                     args.connection, args.device_id)

        device = dashio.dashDevice(args.connection, args.device_id,
                                   args.device_name)
        dash_conn = dashio.dashConnection(args.username, args.password)
        dash_conn.add_device(device)

        self.tmpage = dashio.Page("tmpage", "Test Alarm")
        self.test_menu = dashio.Menu("TestTheMenu",
                                     control_position=dashio.ControlPosition(
                                         0.3, 0.5, 0.5, 0.5))
        self.test_page = dashio.Page("TestCFG", "Test the Menus")
        device.add_control(self.test_page)

        self.up_btn = dashio.Button("UP_BTN")
        self.up_btn.btn_state = dashio.ButtonState.OFF
        self.up_btn.icon_name = dashio.Icon.UP
        self.up_btn.on_color = dashio.Color.GREEN
        self.up_btn.text = "Up Button"
        self.up_btn.text_color = dashio.Color.WHITE
        self.up_btn.title = "Up"
        device.add_control(self.up_btn)
        self.test_menu.add_control(self.up_btn)

        self.down_btn = dashio.Button("DOWN_BTN")
        self.down_btn.btn_state = dashio.ButtonState.OFF
        self.down_btn.icon_name = dashio.Icon.DOWN
        self.down_btn.on_color = dashio.Color.GREEN
        self.down_btn.text = ""
        self.down_btn.text_color = dashio.Color.WHITE
        self.down_btn.title = "Down"
        device.add_control(self.down_btn)
        self.test_menu.add_control(self.down_btn)

        self.sldr_cntrl = dashio.SliderSingleBar("SLDR")
        self.sldr_cntrl.title = "Slider"
        self.sldr_cntrl.max = 10
        self.sldr_cntrl.slider_enabled = True
        self.sldr_cntrl.red_value
        device.add_control(self.sldr_cntrl)
        self.test_menu.add_control(self.sldr_cntrl)

        self.text_cntrl1 = dashio.TextBox("TXT1")
        self.text_cntrl1.text = "Test box1"
        self.text_cntrl1.title = "TextBx1"
        self.text_cntrl1.keyboard_type = dashio.Keyboard.ALL_CHARS
        self.text_cntrl1.close_key_board_on_send = True
        device.add_control(self.text_cntrl1)
        self.test_menu.add_control(self.text_cntrl1)

        self.text_cntrl2 = dashio.TextBox("TXT2")
        self.text_cntrl2.text = "Test box2"
        self.text_cntrl2.title = "TextBx2"
        self.text_cntrl2.keyboard_type = dashio.Keyboard.ALL_CHARS
        self.text_cntrl2.close_key_board_on_send = True
        device.add_control(self.text_cntrl2)
        self.test_menu.add_control(self.text_cntrl2)

        self.selector_ctrl = dashio.Selector("TestSelector", "A Selector")
        self.selector_ctrl.message_rx_event += self.selector_ctrl_handler
        self.selector_ctrl.add_selection("First")
        self.selector_ctrl.add_selection("Second")
        self.selector_ctrl.add_selection("Third")
        self.selector_ctrl.add_selection("Forth")
        self.selector_ctrl.add_selection("Fifth")
        device.add_control(self.selector_ctrl)
        self.test_menu.add_control(self.selector_ctrl)
        self.test_page.add_control(self.test_menu)
        self.button_group_test = dashio.ButtonGroup("TestButtonGRP",
                                                    "A group of buttons")
        self.test_page.add_control(self.button_group_test)
        self.button_group_test.add_button(self.up_btn)
        self.button_group_test.add_button(self.down_btn)
        device.add_control(self.test_menu)
        device.add_control(self.button_group_test)

        while not self.shutdown:
            time.sleep(5)

        device.close()
Example #10
0
def main():
    # Catch CNTRL-C signel
    global shutdown
    signal.signal(signal.SIGINT, signal_cntrl_c)

    no_datapoints = 60
    args = parse_commandline_arguments()
    init_logging(args.logfilename, args.verbose)

    logging.info("Connecting to server: %s", args.server)
    logging.info("       Connection ID: %s", args.connection)
    logging.info("       Control topic: %s/%s/%s/control", args.username,
                 args.connection, args.device_id)
    logging.info("          Data topic: %s/%s/%s/data", args.username,
                 args.connection, args.device_id)

    device = dashio.dashDevice(args.connection, args.device_id,
                               args.device_name)
    dash_conn = dashio.dashConnection(args.username, args.password)
    dash_conn.add_device(device)

    monitor_page = dashio.Page("monpg", "Dash Server Moniter")
    gph_network = dashio.TimeGraph("NETWORKGRAPH")
    gph_network.title = "Server Network Traffic: {}".format(args.connection)
    gph_network.y_axis_label = "Kbytes"
    gph_network.y_axis_min = 0.0
    gph_network.y_axis_max = 1000.0
    gph_network.y_axis_num_bars = 11
    Network_Rx = dashio.TimeGraphLine("RX",
                                      dashio.TimeGraphLineType.LINE,
                                      color=dashio.Color.FUSCIA,
                                      max_data_points=no_datapoints)
    Network_Tx = dashio.TimeGraphLine("TX",
                                      dashio.TimeGraphLineType.LINE,
                                      color=dashio.Color.AQUA,
                                      max_data_points=no_datapoints)

    gph_network.add_line("NET_RX", Network_Rx)
    gph_network.add_line("NET_TX", Network_Tx)
    last_Tx, last_Rx = get_network_rx_tx()

    gph_cpu = dashio.TimeGraph("CPULOAD")
    gph_cpu.title = "CPU load: {}".format(args.connection)
    gph_cpu.y_axis_label = "Percent"
    gph_cpu.y_axis_max = 100
    gph_cpu.y_axis_min = 0
    gph_cpu.y_axis_num_bars = 8
    monitor_page.add_control(gph_network)
    monitor_page.add_control(gph_cpu)
    device.add_control(gph_network)
    device.add_control(gph_cpu)
    number_of_cores = psutil.cpu_count()

    cpu_core_line_array = []
    cpu_data = psutil.cpu_percent(percpu=True)
    for cpu in range(0, number_of_cores):
        line = dashio.TimeGraphLine(
            name="CPU:{}".format(cpu),
            line_type=dashio.TimeGraphLineType.LINE,
            color=dashio.Color(cpu + 1),
            transparency=1.0,
            max_data_points=no_datapoints,
        )
        cpu_core_line_array.append(line)
        gph_cpu.add_line("CPU:{}".format(cpu), line)

    hd_dial = dashio.Dial("HD_USAGE")
    hd_dial.title = "Disk Usage"
    hd_dial.dial_value = psutil.disk_usage("/").percent
    hd_dial.min = 0.0
    hd_dial.max = 100.0
    hd_dial.red_value = 95.0
    hd_dial.show_min_max = True

    device.add_control(hd_dial)
    monitor_page.add_control(hd_dial)
    device.add_control(monitor_page)
    while not shutdown:
        time.sleep(10)

        Tx, Rx = get_network_rx_tx()

        Network_Rx.add_data_point(Tx - last_Tx)
        Network_Tx.add_data_point(Rx - last_Rx)

        last_Tx = Tx
        last_Rx = Rx

        gph_network.send_data()

        cpu_data = psutil.cpu_percent(percpu=True)

        i = 0
        for line in cpu_core_line_array:
            line.add_data_point(cpu_data[i])
            i += 1
        gph_cpu.send_data()
        hd_dial.dial_value = psutil.disk_usage("/").percent

    device.close()
Example #11
0
    def __init__(self):
        LOGGER_PERIOD = 15
        DIV = 1.0

        ADC.setup()

        # Catch CNTRL-C signel
        signal.signal(signal.SIGINT, self.signal_cntrl_c)
        self.shutdown = False
        args = self.parse_commandline_arguments()
        self.init_logging(args.logfilename, args.verbose)

        logging.info("Connecting to server: %s", args.server)
        logging.info("       Device ID: %s", args.device_id)
        logging.info("       Control topic: %s/%s/control", args.username, args.device_id)
        logging.info("          Data topic: %s/%s/data", args.username, args.device_id)

        dash_con = dashio.dashConnection(args.username, args.password)
        device = dashio.dashDevice(args.device_type, args.device_id, args.device_name)
        dash_con.add_device(device)

        gph_15_minutes = dashio.TimeGraph("Temperature15M")
        gph_15_minutes.title = "Temp15M:{}".format(args.device_name)
        gph_15_minutes.time_scale = dashio.TimeGraphTimeScale.FIFTEENMINS
        gph_15_minutes.y_axis_label = "Degrees C"
        gph_15_minutes.y_axis_min = 0.0
        gph_15_minutes.y_axis_max = 50.0
        gph_15_minutes.y_axis_num_bars = 5
        line_15_minutes = dashio.TimeGraphLine(
            "DegC", dashio.TimeGraphLineType.LINE, color=dashio.Color.BLACK, max_data_points=15 * 60 / LOGGER_PERIOD
        )
        gph_15_minutes.add_line("DegC", line_15_minutes)

        gph_1_day = dashio.TimeGraph("Temperature1D")
        gph_1_day.title = "Temp1D:{}".format(args.device_name)
        gph_1_day.time_scale = dashio.TimeGraphTimeScale.ONEDAY
        gph_1_day.y_axis_label = "Degrees C"
        gph_1_day.y_axis_min = 0.0
        gph_1_day.y_axis_max = 50.0
        gph_1_day.y_axis_num_bars = 5
        line_1_day = dashio.TimeGraphLine(
            "DegC", dashio.TimeGraphLineType.LINE, color=dashio.Color.BLACK, max_data_points=24 * 4
        )
        gph_1_day.add_line("DegC", line_1_day)

        gph_1_week = dashio.TimeGraph("Temperature1W")
        gph_1_week.title = "Temp1W:{}".format(args.device_name)
        gph_1_week.time_scale = dashio.TimeGraphTimeScale.ONEWEEK
        gph_1_week.y_axis_label = "Degrees C"
        gph_1_week.y_axis_min = 0.0
        gph_1_week.y_axis_max = 50.0
        gph_1_week.y_axis_num_bars = 5
        line_1_week = dashio.TimeGraphLine(
            "DegC", dashio.TimeGraphLineType.LINE, color=dashio.Color.BLACK, max_data_points=24 * 4 * 7
        )
        gph_1_week.add_line("DegC", line_1_week)

        gph_1_year = dashio.TimeGraph("Temperature1Y")
        gph_1_year.title = "Temp1Y:{}".format(args.device_name)
        gph_1_year.time_scale = dashio.TimeGraphTimeScale.ONEYEAR
        gph_1_year.y_axis_label = "Degrees C"
        gph_1_year.y_axis_min = 0.0
        gph_1_year.y_axis_max = 50.0
        gph_1_year.y_axis_num_bars = 5
        line_1_year = dashio.TimeGraphLine(
            "DegC", dashio.TimeGraphLineType.LINE, color=dashio.Color.BLACK, max_data_points=360
        )
        gph_1_year.add_line("DegC", line_1_year)

        dl_temperature_ctrl = dashio.Dial("TemperatureDial")
        dl_temperature_ctrl.title = "Temperature"
        dl_temperature_ctrl.max = 50

        dl_daily_max_ctrl = dashio.Dial("TemperatureMaxDial")
        dl_daily_max_ctrl.title = "Daily Max"
        dl_daily_max_ctrl.max = 50

        dl_daily_min_ctrl = dashio.Dial("TemperatureMinDial")
        dl_daily_min_ctrl.title = "Daily Min"
        dl_daily_min_ctrl.max = 50

        self.page = dashio.Page("tmppage", "Temperatures", 1)
        device.add_control(self.page)
        device.add_control(dl_temperature_ctrl)
        self.page.add_control(dl_temperature_ctrl)
        device.add_control(dl_daily_max_ctrl)
        self.page.add_control(dl_daily_max_ctrl)
        device.add_control(dl_daily_min_ctrl)
        self.page.add_control(dl_daily_min_ctrl)
        device.add_control(gph_15_minutes)
        self.page.add_control(gph_15_minutes)
        device.add_control(gph_1_day)
        self.page.add_control(gph_1_day)
        device.add_control(gph_1_week)
        self.page.add_control(gph_1_week)
        device.add_control(gph_1_year)
        self.page.add_control(gph_1_year)

        temperature = self.read_sensor()
        daily_temperature_max = temperature
        daily_temperature_min = temperature

        while not self.shutdown:
            temperature = self.read_sensor()
            if temperature < daily_temperature_min:
                daily_temperature_min = temperature
                dl_daily_min_ctrl.dial_value = temperature
            if temperature > daily_temperature_max:
                daily_temperature_max = temperature
                dl_daily_max_ctrl.dial_value = temperature
            dl_temperature_ctrl.dial_value = temperature
            line_15_minutes.add_data_point(temperature)
            gph_15_minutes.send_data()
            t = datetime.datetime.now()
            if (t.minute == 0 or t.minute == 15 or t.minute == 30 or t.minute == 45) and (t.second < 5):
                total = 0
                for d in line_15_minutes.data:
                    temps = d.data_point
                    total += float(temps)
                avg = total / len(line_15_minutes.data)
                avg_str = "{:.2f}".format(avg)
                line_1_day.add_data_point(avg_str)
                line_1_week.add_data_point(avg_str)
                gph_1_day.send_data()
                gph_1_week.send_data()
                if t.hour == 12 and t.minute == 0 and t.second < 10:
                    daily_temperature_max = temperature
                    daily_temperature_min = temperature
                    line_1_year.add_data_point(avg_str)
                    gph_1_year.send_data()
            t = datetime.datetime.now()

            seconds_left = t.second + t.microsecond / 1000000.0
            div, sleep_time = divmod(seconds_left, LOGGER_PERIOD)
            sleep_time = LOGGER_PERIOD - sleep_time
            time.sleep(sleep_time)
        device.close()