From fb81292d312c75f515359ab2b4def9ceaa9d1471 Mon Sep 17 00:00:00 2001 From: lejeune quentin Date: Tue, 10 Sep 2019 12:26:18 +0000 Subject: [PATCH 1/6] [IMP] point_of_sale: Use last version of Raspbian for the build of IoT Box We use the last version of Raspbian; Strech for the build of IoT Box --- addons/point_of_sale/tools/posbox/posbox_download_images.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/point_of_sale/tools/posbox/posbox_download_images.sh b/addons/point_of_sale/tools/posbox/posbox_download_images.sh index 939e9879c2c..780835953fe 100755 --- a/addons/point_of_sale/tools/posbox/posbox_download_images.sh +++ b/addons/point_of_sale/tools/posbox/posbox_download_images.sh @@ -1,6 +1,6 @@ #!/bin/sh -wget 'http://downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-2018-11-15/2018-11-13-raspbian-stretch-lite.zip' -O raspbian.img.zip +wget 'http://downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-2019-04-09/2019-04-08-raspbian-stretch-lite.zip' -O raspbian.img.zip unzip raspbian.img.zip wget 'https://github.com/dhruvvyas90/qemu-rpi-kernel/raw/master/kernel-qemu-4.14.79-stretch' -O kernel-qemu wget 'https://github.com/dhruvvyas90/qemu-rpi-kernel/raw/master/versatile-pb.dtb' From d098981b4658976954d8d972f2e65f8811d4e47c Mon Sep 17 00:00:00 2001 From: lejeune quentin Date: Tue, 10 Sep 2019 12:52:37 +0000 Subject: [PATCH 2/6] [FIX] hw_drivers: Use helper for Keyboard driver We have implemented helpers that are not used in the KeyboardUSBDriver --- addons/hw_drivers/drivers/KeyboardUSBDriver.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/addons/hw_drivers/drivers/KeyboardUSBDriver.py b/addons/hw_drivers/drivers/KeyboardUSBDriver.py index 6c61a59307d..0e61f73903f 100644 --- a/addons/hw_drivers/drivers/KeyboardUSBDriver.py +++ b/addons/hw_drivers/drivers/KeyboardUSBDriver.py @@ -181,9 +181,7 @@ class KeyboardUSBDriver(Driver): else: data = {} data[self.device_identifier] = layout - subprocess.check_call(["sudo", "mount", "-o", "remount,rw", "/"]) - file_path.write_text(json.dumps(data)) - subprocess.check_call(["sudo", "mount", "-o", "remount,ro", "/"]) + helpers.write_file('odoo-keyboard-layouts.conf', json.dumps(data)) def load_layout(self): """Read the layout from the saved filed and set it as current layout. From 9433151fcf1475e559cd7cbc66891f7a82e7c0ef Mon Sep 17 00:00:00 2001 From: lejeune quentin Date: Tue, 10 Sep 2019 12:54:16 +0000 Subject: [PATCH 3/6] [FIX] point_of_sale: Remove useless wget We remove 2 wget which have become useless --- .../tools/posbox/configuration/connect_to_server_wifi.sh | 1 - .../point_of_sale/tools/posbox/configuration/connect_to_wifi.sh | 1 - 2 files changed, 2 deletions(-) diff --git a/addons/point_of_sale/tools/posbox/configuration/connect_to_server_wifi.sh b/addons/point_of_sale/tools/posbox/configuration/connect_to_server_wifi.sh index 2d5978b36e3..12c74f6173e 100755 --- a/addons/point_of_sale/tools/posbox/configuration/connect_to_server_wifi.sh +++ b/addons/point_of_sale/tools/posbox/configuration/connect_to_server_wifi.sh @@ -117,7 +117,6 @@ function connect () { if [ ${WIFI_WAS_LOST} -eq 0 ] ; then touch "${LOST_WIFI_FILE}" fi - wget -q "http://localhost:8069/hw_drivers/send_iot_box" -O /dev/null logger -t posbox_connect_to_wifi "Starting wifi keep alive script" /home/pi/odoo/addons/point_of_sale/tools/posbox/configuration/keep_wifi_alive.sh & diff --git a/addons/point_of_sale/tools/posbox/configuration/connect_to_wifi.sh b/addons/point_of_sale/tools/posbox/configuration/connect_to_wifi.sh index 264f569a609..c843d6053fa 100755 --- a/addons/point_of_sale/tools/posbox/configuration/connect_to_wifi.sh +++ b/addons/point_of_sale/tools/posbox/configuration/connect_to_wifi.sh @@ -81,7 +81,6 @@ function connect () { if [ ${WIFI_WAS_LOST} -eq 0 ] ; then touch "${LOST_WIFI_FILE}" fi - wget -q "http://localhost:8069/hw_drivers/send_iot_box" -O /dev/null logger -t posbox_connect_to_wifi "Starting wifi keep alive script" /home/pi/odoo/addons/point_of_sale/tools/posbox/configuration/keep_wifi_alive.sh & From aa18bcc14d2c9be939a9debcee441464274f27e2 Mon Sep 17 00:00:00 2001 From: lejeune quentin Date: Tue, 10 Sep 2019 13:00:42 +0000 Subject: [PATCH 4/6] [FIX] hw_posbox_homepage: Removes unnecessary POS devices Previously, we showed POS and IoT devices. Now all POS devices are converted to IoT devices. So the 'get_pos_devices_status' function is useless --- addons/hw_posbox_homepage/controllers/main.py | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/addons/hw_posbox_homepage/controllers/main.py b/addons/hw_posbox_homepage/controllers/main.py index 8a5ca64be87..0bfd7d06b28 100644 --- a/addons/hw_posbox_homepage/controllers/main.py +++ b/addons/hw_posbox_homepage/controllers/main.py @@ -49,12 +49,6 @@ list_credential_template = jinja_env.get_template('list_credential.html') class IoTboxHomepage(web.Home): - def get_pos_device_status(self): - statuses = {} - for driver in hw_proxy.drivers: - statuses[driver] = hw_proxy.drivers[driver].get_status() - return statuses - def get_six_terminal(self): terminal_id = helpers.read_file_first_line('odoo-six-payment-terminal.conf') return terminal_id or 'Not Configured' @@ -75,18 +69,7 @@ class IoTboxHomepage(web.Home): 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']), From 9c10d7a28e8fba59df9da78747c992e4fa944c9d Mon Sep 17 00:00:00 2001 From: lejeune quentin Date: Tue, 10 Sep 2019 13:06:45 +0000 Subject: [PATCH 5/6] [FIX] hw_drivers: Fix unmount of cups folder To add or modify printer the /root_bypass_ramdisks/etc/cups/ need be writeable. And /root_bypass_ramdisks/etc/cups/ = /etc/cups/ But when we make 'sudo mount -o remount,ro /' we put the /etc/cups/ and so /root_bypass_ramdisks/etc/cups/ folder on read-only. After all 'read-only' command we make another command to put cups folder writeable --- addons/hw_drivers/tools/helpers.py | 4 ++++ addons/hw_posbox_homepage/controllers/main.py | 2 -- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/addons/hw_drivers/tools/helpers.py b/addons/hw_drivers/tools/helpers.py index 9cc25440304..9a1b5e2064a 100644 --- a/addons/hw_drivers/tools/helpers.py +++ b/addons/hw_drivers/tools/helpers.py @@ -109,6 +109,7 @@ def load_certificate(): Path('/root_bypass_ramdisks/etc/ssl/private/nginx-cert.key').write_text(result['private_key_pem']) subprocess.check_call(["sudo", "mount", "-o", "remount,ro", "/"]) subprocess.check_call(["sudo", "mount", "-o", "remount,ro", "/root_bypass_ramdisks/"]) + subprocess.check_call(["sudo", "mount", "-o", "remount,rw", "/root_bypass_ramdisks/etc/cups"]) subprocess.check_call(["sudo", "service", "nginx", "restart"]) def download_drivers(auto=True): @@ -127,6 +128,7 @@ def download_drivers(auto=True): zip_file = zipfile.ZipFile(io.BytesIO(resp.data)) zip_file.extractall(get_resource_path('hw_drivers', 'drivers')) subprocess.check_call(["sudo", "mount", "-o", "remount,ro", "/"]) + subprocess.check_call(["sudo", "mount", "-o", "remount,rw", "/root_bypass_ramdisks/etc/cups"]) except Exception as e: _logger.error('Could not reach configured server') _logger.error('A error encountered : %s ' % e) @@ -145,9 +147,11 @@ def unlink_file(filename): if path.exists(): path.unlink() subprocess.check_call(["sudo", "mount", "-o", "remount,ro", "/"]) + subprocess.check_call(["sudo", "mount", "-o", "remount,rw", "/root_bypass_ramdisks/etc/cups"]) def write_file(filename, text): subprocess.check_call(["sudo", "mount", "-o", "remount,rw", "/"]) path = Path.home() / filename path.write_text(text) subprocess.check_call(["sudo", "mount", "-o", "remount,ro", "/"]) + subprocess.check_call(["sudo", "mount", "-o", "remount,rw", "/root_bypass_ramdisks/etc/cups"]) diff --git a/addons/hw_posbox_homepage/controllers/main.py b/addons/hw_posbox_homepage/controllers/main.py index 0bfd7d06b28..e9344ae616e 100644 --- a/addons/hw_posbox_homepage/controllers/main.py +++ b/addons/hw_posbox_homepage/controllers/main.py @@ -140,11 +140,9 @@ class IoTboxHomepage(web.Home): @http.route('/clear_credential', type='http', auth='none', cors='*', csrf=False) def clear_credential(self): - subprocess.check_call(["sudo", "mount", "-o", "remount,rw", "/"]) helpers.unlink_file('odoo-db-uuid.conf') helpers.unlink_file('odoo-enterprise-code.conf') subprocess.check_call(["sudo", "service", "odoo", "restart"]) - subprocess.check_call(["sudo", "mount", "-o", "remount,ro", "/"]) return "" def get_wifi_essid(self): From d4fa24c2bce7bfb0b01d244a66aed14542ed1bbb Mon Sep 17 00:00:00 2001 From: lejeune quentin Date: Tue, 10 Sep 2019 13:13:22 +0000 Subject: [PATCH 6/6] [IMP] hw_drivers: Add possibility to choose a wifi network on IoT Box Previously if you are wired connected we don't scan wifi network. Now we scan the wifi network and add possibiliyt to select a network and use them. --- addons/hw_drivers/tools/helpers.py | 12 +++- addons/hw_posbox_homepage/controllers/main.py | 25 +++------ .../tools/posbox/configuration/wireless_ap.sh | 55 ++++++++----------- 3 files changed, 42 insertions(+), 50 deletions(-) diff --git a/addons/hw_drivers/tools/helpers.py b/addons/hw_drivers/tools/helpers.py index 9a1b5e2064a..158e3022f07 100644 --- a/addons/hw_drivers/tools/helpers.py +++ b/addons/hw_drivers/tools/helpers.py @@ -74,7 +74,17 @@ def get_token(): return read_file_first_line('token') def get_version(): - return '19_07' + return '19.07' + +def get_wifi_essid(self): + wifi_options = [] + process_iwlist = subprocess.Popen(['sudo', 'iwlist', 'wlan0', 'scan'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + process_grep = subprocess.Popen(['grep', 'ESSID:"'], stdin=process_iwlist.stdout, stdout=subprocess.PIPE).stdout.readlines() + for ssid in process_grep: + essid = ssid.decode('utf-8').split('"')[1] + if essid not in wifi_options: + wifi_options.append(essid) + return wifi_options def load_certificate(): """ diff --git a/addons/hw_posbox_homepage/controllers/main.py b/addons/hw_posbox_homepage/controllers/main.py index e9344ae616e..0a940f3861f 100644 --- a/addons/hw_posbox_homepage/controllers/main.py +++ b/addons/hw_posbox_homepage/controllers/main.py @@ -97,7 +97,7 @@ class IoTboxHomepage(web.Home): 'title': 'Configure IoT Box', 'breadcrumb': 'Configure IoT Box', 'loading_message': 'Configuring your IoT Box', - 'ssid': self.get_wifi_essid(), + 'ssid': helpers.get_wifi_essid(), 'server': helpers.get_odoo_server_url(), 'hostname': subprocess.check_output('hostname').decode('utf-8'), }) @@ -145,27 +145,13 @@ class IoTboxHomepage(web.Home): subprocess.check_call(["sudo", "service", "odoo", "restart"]) return "" - def get_wifi_essid(self): - wifi_options = [] - try: - f = open('/tmp/scanned_networks.txt', 'r') - for line in f: - line = line.rstrip() - line = misc.html_escape(line) - if line not in wifi_options: - wifi_options.append(line) - f.close() - except IOError: - _logger.warning("No /tmp/scanned_networks.txt") - return wifi_options - @http.route('/wifi', type='http', auth='none', website=True) def wifi(self): return wifi_config_template.render({ 'title': 'Wifi configuration', 'breadcrumb': 'Configure Wifi', 'loading_message': 'Connecting to Wifi', - 'ssid': self.get_wifi_essid(), + 'ssid': helpers.get_wifi_essid(), }) @http.route('/wifi_connect', type='http', auth='none', cors='*', csrf=False) @@ -185,6 +171,11 @@ class IoTboxHomepage(web.Home): 'url': server, 'message': 'Redirect to Odoo Server' } + else: + res_payload['server'] = { + 'url': 'http://' + helpers.get_ip() + ':8069', + 'message': 'Redirect to IoT Box' + } return json.dumps(res_payload) @@ -229,7 +220,7 @@ class IoTboxHomepage(web.Home): 'title': 'Configure IoT Box', 'breadcrumb': 'Configure IoT Box', 'loading_message': 'Configuring your IoT Box', - 'ssid': self.get_wifi_essid(), + 'ssid': helpers.get_wifi_essid(), 'server': helpers.get_odoo_server_url(), 'hostname': subprocess.check_output('hostname').decode('utf-8').strip('\n'), }) diff --git a/addons/point_of_sale/tools/posbox/configuration/wireless_ap.sh b/addons/point_of_sale/tools/posbox/configuration/wireless_ap.sh index 1c6367c5b1c..2dbe31b938a 100755 --- a/addons/point_of_sale/tools/posbox/configuration/wireless_ap.sh +++ b/addons/point_of_sale/tools/posbox/configuration/wireless_ap.sh @@ -4,43 +4,34 @@ FORCE_HOST_AP="${1}" WIRED_IP=$(python3 -c "import netifaces as ni; print(ni.ifaddresses('eth0').get(ni.AF_INET) and ni.ifaddresses('eth0')[ni.AF_INET][0]['addr'] or '')") WIFI_NETWORK_FILE="/home/pi/wifi_network.txt" + +ifconfig wlan0 down +ifconfig wlan0 up + +# wait for wlan0 to come up +sleep 5 + # if there is no wired ip, attempt to start an AP through wireless interface if [ -z "${WIRED_IP}" ] ; then logger -t posbox_wireless_ap "No wired IP" - ifconfig wlan0 down - ifconfig wlan0 up - - # wait for wlan0 to come up - sleep 5 - - # we cannot scan for networks while in Master mode - # so first scan and save the networks to a list - iwlist wlan0 scan | grep 'ESSID:' | sed 's/.*ESSID:"\(.*\)"/\1/' > /tmp/scanned_networks.txt - - # only do it when there is a wireless interface - if [ -n "$(iw list)" ] ; then - if [ -f "${WIFI_NETWORK_FILE}" ] && [ -z "${FORCE_HOST_AP}" ] ; then - logger -t posbox_wireless_ap "Loading persistently saved setting" - /home/pi/odoo/addons/point_of_sale/tools/posbox/configuration/connect_to_wifi.sh & - else - logger -t posbox_wireless_ap "Starting AP" - - service hostapd restart - - ip addr add 10.11.12.1/24 dev wlan0 - - service dnsmasq restart - - service nginx stop - # We start nginx in another configuration than the default one with https - # as it needs to do redirect instead in case the IoT Box acts as an ap - nginx -c /home/pi/odoo/addons/point_of_sale/tools/posbox/configuration/nginx_ap.conf - - service odoo restart - fi - # no wired, no wireless + if [ -f "${WIFI_NETWORK_FILE}" ] && [ -z "${FORCE_HOST_AP}" ] ; then + logger -t posbox_wireless_ap "Loading persistently saved setting" + /home/pi/odoo/addons/point_of_sale/tools/posbox/configuration/connect_to_wifi.sh & else + logger -t posbox_wireless_ap "Starting AP" + + service hostapd restart + + ip addr add 10.11.12.1/24 dev wlan0 + + service dnsmasq restart + + service nginx stop + # We start nginx in another configuration than the default one with https + # as it needs to do redirect instead in case the IoT Box acts as an ap + nginx -c /home/pi/odoo/addons/point_of_sale/tools/posbox/configuration/nginx_ap.conf + service odoo restart fi # wired