Exemple #1
0
 def send_alldevices(self):
     """
     This method send IoT Box and devices informations to Flectra database
     """
     server = helpers.get_flectra_server_url()
     if server:
         subject = helpers.read_file_first_line('flectra-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('Flectra server not set')
Exemple #2
0
 def index(self):
     wifi = Path.home() / 'wifi_network.txt'
     remote_server = Path.home() / 'flectra-remote-server.conf'
     if (wifi.exists() == False or remote_server.exists() == False) and helpers.access_point():
         return "<meta http-equiv='refresh' content='0; url=http://" + helpers.get_ip() + ":7073/steps'>"
     else:
         return homepage_template.render(self.get_homepage_data())
Exemple #3
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('_', ' '),
                'identifier': iot_devices[device].device_identifier,
            })

        return {
            'hostname': hostname,
            'ip': helpers.get_ip(),
            'mac': helpers.get_mac_address(),
            'iot_device_status': iot_device,
            'server_status': helpers.get_flectra_server_url() or 'Not Configured',
            'six_terminal': self.get_six_terminal(),
            'network_status': network,
            'version': helpers.get_version(),
            }
Exemple #4
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_flectra_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() + ':7073'
Exemple #5
0
    def connect_to_wifi(self, essid, password, persistent=False):
        if persistent:
                persistent = "1"
        else:
                persistent = ""

        subprocess.check_call([get_resource_path('point_of_sale', 'tools/posbox/configuration/connect_to_wifi.sh'), essid, password, persistent])
        server = helpers.get_flectra_server_url()
        res_payload = {
            'message': 'Connecting to ' + essid,
        }
        if server:
            res_payload['server'] = {
                'url': server,
                'message': 'Redirect to Flectra Server'
            }
        else:
            res_payload['server'] = {
                'url': 'http://' + helpers.get_ip() + ':7073',
                'message': 'Redirect to IoT Box'
            }

        return json.dumps(res_payload)
Exemple #6
0
 def clear_six_payment_terminal(self):
     helpers.unlink_file('flectra-six-payment-terminal.conf')
     subprocess.check_call(["sudo", "service", "flectra", "restart"])
     return "<meta http-equiv='refresh' content='0; url=http://" + helpers.get_ip() + ":7073'>"
Exemple #7
0
 def add_six_payment_terminal(self, terminal_id):
     helpers.write_file('flectra-six-payment-terminal.conf', terminal_id)
     subprocess.check_call(["sudo", "service", "flectra", "restart"])
     return 'http://' + helpers.get_ip() + ':7073'
Exemple #8
0
 def clear_handlers_list(self):
     for directory in ['drivers', 'interfaces']:
         for file in os.listdir(get_resource_path('hw_drivers', 'iot_handlers', directory)):
             if file != '__pycache__':
                 helpers.unlink_file(get_resource_path('hw_drivers', 'iot_handlers', directory, file))
     return "<meta http-equiv='refresh' content='0; url=http://" + helpers.get_ip() + ":7073/list_handlers'>"
Exemple #9
0
 def clear_server_configuration(self):
     helpers.unlink_file('flectra-remote-server.conf')
     return "<meta http-equiv='refresh' content='0; url=http://" + helpers.get_ip() + ":7073'>"
Exemple #10
0
 def clear_wifi_configuration(self):
     helpers.unlink_file('wifi_network.txt')
     return "<meta http-equiv='refresh' content='0; url=http://" + helpers.get_ip() + ":7073'>"
Exemple #11
0
 def clear_credential(self):
     helpers.unlink_file('flectra-db-uuid.conf')
     helpers.unlink_file('flectra-enterprise-code.conf')
     subprocess.check_call(["sudo", "service", "flectra", "restart"])
     return "<meta http-equiv='refresh' content='20; url=http://" + helpers.get_ip() + ":7073'>"
Exemple #12
0
 def save_credential(self, db_uuid, enterprise_code):
     helpers.add_credential(db_uuid, enterprise_code)
     subprocess.check_call(["sudo", "service", "flectra", "restart"])
     return "<meta http-equiv='refresh' content='20; url=http://" + helpers.get_ip() + ":7073'>"
Exemple #13
0
 def load_iot_handlers(self):
     helpers.download_iot_handlers(False)
     subprocess.check_call(["sudo", "service", "flectra", "restart"])
     return "<meta http-equiv='refresh' content='20; url=http://" + helpers.get_ip() + ":7073/list_handlers'>"