示例#1
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')
示例#2
0
 def connect_to_server(self, token, iotname):
     if token:
         credential = token.split('|')
         url = credential[0]
         token = credential[1]
         if len(credential) > 2:
             # IoT Box send token with db_uuid and enterprise_code only since V13
             db_uuid = credential[2]
             enterprise_code = credential[3]
             helpers.add_credential(db_uuid, enterprise_code)
     else:
         url = helpers.get_odoo_server_url()
         token = helpers.get_token()
     reboot = 'reboot'
     subprocess.check_call([get_resource_path('point_of_sale', 'tools/posbox/configuration/connect_to_server.sh'), url, iotname, token, reboot])
     return 'http://' + helpers.get_ip() + ':8069'