From 546a1d4a32063a47069a36c44987b2a130a47aee Mon Sep 17 00:00:00 2001
From: Joren Van Onder
Date: Wed, 7 Oct 2015 14:49:28 +0200
Subject: [PATCH] [IMP] point_of_sale: support Wi-Fi on the posbox
This allows people to connect the posbox to networks using a wireless
network adapter.
When plugging in a USB Wi-Fi adapter and no network cable, the posbox
will boot and host its own Access Point called "Posbox". Users can
connect their device to this network and can then connect to the posbox
the usual way.
An interface for has been provided that also allows users to instruct
the posbox to connect to a different Wi-Fi network. This is useful when
the client is not running Odoo locally.
It is also possible to make this configuration persistent. With a
persistent Wi-Fi network configuration, the posbox will always try to
connect to the specified network after a reboot.
Attempts have been made to make the Wi-Fi connection as robust as
possible. Upon connection loss, the posbox will automatically attempt to
reconnect.
---
addons/hw_escpos/controllers/main.py | 7 ++
addons/hw_posbox_homepage/controllers/main.py | 103 +++++++++++++++-
.../configuration/clear_wifi_configuration.sh | 6 +
.../posbox/configuration/connect_to_wifi.sh | 69 +++++++++++
.../posbox/configuration/keep_wifi_alive.sh | 17 +++
.../tools/posbox/configuration/wireless_ap.sh | 44 +++++++
.../overwrite_after_init/etc/default/hostapd | 20 ++++
.../overwrite_after_init/etc/default/ifplugd | 17 +++
.../overwrite_after_init/etc/dhcp/dhcpd.conf | 113 ++++++++++++++++++
.../overwrite_after_init/etc/dhcpcd.conf | 45 +++++++
.../etc/hostapd/hostapd.conf | 3 +
.../posbox/overwrite_after_init/etc/rc.local | 1 +
.../etc/init_posbox_image.sh | 5 +-
.../tools/posbox/posbox_create_image.sh | 1 -
14 files changed, 447 insertions(+), 4 deletions(-)
create mode 100755 addons/point_of_sale/tools/posbox/configuration/clear_wifi_configuration.sh
create mode 100755 addons/point_of_sale/tools/posbox/configuration/connect_to_wifi.sh
create mode 100755 addons/point_of_sale/tools/posbox/configuration/keep_wifi_alive.sh
create mode 100755 addons/point_of_sale/tools/posbox/configuration/wireless_ap.sh
create mode 100644 addons/point_of_sale/tools/posbox/overwrite_after_init/etc/default/hostapd
create mode 100644 addons/point_of_sale/tools/posbox/overwrite_after_init/etc/default/ifplugd
create mode 100644 addons/point_of_sale/tools/posbox/overwrite_after_init/etc/dhcp/dhcpd.conf
create mode 100644 addons/point_of_sale/tools/posbox/overwrite_after_init/etc/dhcpcd.conf
create mode 100644 addons/point_of_sale/tools/posbox/overwrite_after_init/etc/hostapd/hostapd.conf
diff --git a/addons/hw_escpos/controllers/main.py b/addons/hw_escpos/controllers/main.py
index 77ae2a59db2..c91d17364ce 100644
--- a/addons/hw_escpos/controllers/main.py
+++ b/addons/hw_escpos/controllers/main.py
@@ -193,6 +193,8 @@ class EscposDriver(Thread):
def print_status(self,eprint):
localips = ['0.0.0.0','127.0.0.1','127.0.1.1']
+ hosting_ap = os.system('pgrep hostapd') == 0
+ ssid = subprocess.check_output('iwconfig 2>&1 | grep \'ESSID:"\' | sed \'s/.*"\\(.*\\)"/\\1/\'', shell=True).rstrip()
ips = [ c.split(':')[1].split(' ')[0] for c in commands.getoutput("/sbin/ifconfig").split('\n') if 'inet addr' in c ]
ips = [ ip for ip in ips if ip not in localips ]
eprint.text('\n\n')
@@ -201,6 +203,11 @@ class EscposDriver(Thread):
eprint.text('\n')
eprint.set(align='center')
+ if hosting_ap:
+ eprint.text('Wireless network:\nPosbox\n\n')
+ elif ssid:
+ eprint.text('Wireless network:\n' + ssid + '\n\n')
+
if len(ips) == 0:
eprint.text('ERROR: Could not connect to LAN\n\nPlease check that the PosBox is correc-\ntly connected with a network cable,\n that the LAN is setup with DHCP, and\nthat network addresses are available')
elif len(ips) == 1:
diff --git a/addons/hw_posbox_homepage/controllers/main.py b/addons/hw_posbox_homepage/controllers/main.py
index a021986bee7..26509d8d58a 100644
--- a/addons/hw_posbox_homepage/controllers/main.py
+++ b/addons/hw_posbox_homepage/controllers/main.py
@@ -2,6 +2,8 @@
import logging
import os
import time
+import werkzeug
+import subprocess
from os import listdir
import openerp
@@ -43,6 +45,9 @@ index_template = """
to the hardware status page.
+ Wi-Fi can be configured by visiting the Wi-Fi configuration page.
+
+
The PosBox software installed on this posbox is version 13,
the posbox version number is independent from Odoo. You can upgrade
the software on the upgrade page.
@@ -60,4 +65,100 @@ class PosboxHomepage(openerp.addons.web.controllers.main.Home):
def index(self):
#return request.render('hw_posbox_homepage.index',mimetype='text/html')
return index_template
-
+
+ @http.route('/wifi', type='http', auth='none', website=True)
+ def wifi(self):
+ wifi_template = """
+
+
+
+ Wifi configuration
+
+
+
+ Configure wifi
+
+ Here you can configure how the posbox should connect to wireless networks.
+ Currently only Open and WPA networks are supported. When enabling the persistent checkbox,
+ the chosen network will be saved and the posbox will attempt to connect to it every time it boots.
+
+
+
+ You can clear the persistent configuration by clicking below:
+
+
+