示例#1
0
    def get_homepage_data(self):
        hostname = str(socket.gethostname())
        ssid = helpers.get_ssid()
        wired = subprocess.check_output(['cat', '/sys/class/net/eth0/operstate']).decode('utf-8').strip('\n')
        if wired == 'up':
            network = 'Ethernet'
        elif ssid:
            if helpers.access_point():
                network = 'Wifi access point'
            else:
                network = 'Wifi : ' + ssid
        else:
            network = 'Not Connected'

        iot_device = []
        for device in iot_devices:
            iot_device.append({
                'name': iot_devices[device].device_name + ' : ' + str(iot_devices[device].data['value']),
                'type': iot_devices[device].device_type.replace('_', ' '),
                'message': iot_devices[device].device_identifier + iot_devices[device].get_message()
            })

        return {
            'hostname': hostname,
            'ip': helpers.get_ip(),
            'mac': helpers.get_mac_address(),
            'iot_device_status': iot_device,
            'server_status': helpers.get_odoo_server_url() or 'Not Configured',
            'six_terminal': self.get_six_terminal(),
            'network_status': network,
            'version': helpers.get_version(),
            }
示例#2
0
文件: main.py 项目: yasminejamal/odoo
    def get_homepage_data(self):
        hostname = str(socket.gethostname())
        mac = get_mac()
        h = iter(hex(mac)[2:].zfill(12))
        ssid = subprocess.check_output(
            'iwconfig 2>&1 | grep \'ESSID:"\' | sed \'s/.*"\\(.*\\)"/\\1/\'',
            shell=True).decode('utf-8').rstrip()
        wired = subprocess.check_output('cat /sys/class/net/eth0/operstate',
                                        shell=True).decode('utf-8').strip('\n')
        if wired == 'up':
            network = 'Ethernet'
        elif ssid:
            if helpers.access_point():
                network = 'Wifi access point'
            else:
                network = 'Wifi : ' + ssid
        else:
            network = 'Not Connected'

        pos_device = self.get_pos_device_status()
        iot_device = []

        if not iot_devices:
            for status in pos_device:
                if pos_device[status]['status'] == 'connected':
                    iot_device.append({
                        'name':
                        status,
                        'type':
                        'device',
                        'message':
                        ' '.join(pos_device[status]['messages'])
                    })

        for device in iot_devices:
            iot_device.append({
                'name':
                iot_devices[device].device_name + ' : ' +
                str(iot_devices[device].data['value']),
                'type':
                iot_devices[device].device_type,
                'message':
                iot_devices[device].device_identifier +
                iot_devices[device].get_message()
            })

        return {
            'hostname': hostname,
            'ip': helpers.get_ip(),
            'mac': ":".join(i + next(h) for i in h),
            'iot_device_status': iot_device,
            'server_status': helpers.get_odoo_server_url() or 'Not Configured',
            'six_terminal': self.get_six_terminal(),
            'network_status': network,
            'version': helpers.get_version(),
        }
示例#3
0
 def send_alldevices(self):
     """
     This method send IoT Box and devices informations to Odoo database
     """
     server = helpers.get_odoo_server_url()
     if server:
         subject = helpers.read_file_first_line('odoo-subject.conf')
         if subject:
             domain = helpers.get_ip().replace('.',
                                               '-') + subject.strip('*')
         else:
             domain = helpers.get_ip()
         iot_box = {
             'name': socket.gethostname(),
             'identifier': helpers.get_mac_address(),
             'ip': domain,
             'token': helpers.get_token(),
             'version': helpers.get_version(),
         }
         devices_list = {}
         for device in iot_devices:
             identifier = iot_devices[device].device_identifier
             devices_list[identifier] = {
                 'name': iot_devices[device].device_name,
                 'type': iot_devices[device].device_type,
                 'manufacturer': iot_devices[device].device_manufacturer,
                 'connection': iot_devices[device].device_connection,
             }
         data = {
             'params': {
                 'iot_box': iot_box,
                 'devices': devices_list,
             }
         }
         # disable certifiacte verification
         urllib3.disable_warnings()
         http = urllib3.PoolManager(cert_reqs='CERT_NONE')
         try:
             http.request(
                 'POST',
                 server + "/iot/setup",
                 body=json.dumps(data).encode('utf8'),
                 headers={
                     'Content-type': 'application/json',
                     'Accept': 'text/plain',
                 },
             )
         except Exception as e:
             _logger.error('Could not reach configured server')
             _logger.error('A error encountered : %s ' % e)
     else:
         _logger.warning('Odoo server not set')
示例#4
0
 def upgrade(self):
     commit = subprocess.check_output(["git", "--work-tree=/home/pi/odoo/", "--git-dir=/home/pi/odoo/.git", "log", "-1"]).decode('utf-8').replace("\n", "<br/>")
     flashToVersion = helpers.check_image()
     actualVersion = helpers.get_version()
     if flashToVersion:
         flashToVersion = '%s.%s' % (flashToVersion.get('major', ''), flashToVersion.get('minor', ''))
     return upgrade_page_template.render({
         'title': "Odoo's IoTBox - Software Upgrade",
         'breadcrumb': 'IoT Box Software Upgrade',
         'loading_message': 'Updating IoT box',
         'commit': commit,
         'flashToVersion': flashToVersion,
         'actualVersion': actualVersion,
     })
示例#5
0
 def check_version(self):
     return helpers.get_version()