Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions dicts/ras_dic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# the memory of the device
WORK_DIR = "/home/pi/ras/"

#network interface: wlan0 (WLAN), eth0 (Ethernet)
NET_INTERFACE = 'eth0'

# SSID when resetting the WiFi
SSID_reset = "__RAS__"

Expand Down
8 changes: 2 additions & 6 deletions lib/CardReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,11 +492,7 @@ def scan_card(self):

# If we have the UID, continue
if status == self.MI_OK:
card = (
hex(int(uid[0])).split("x")[-1]
+ hex(int(uid[1])).split("x")[-1]
+ hex(int(uid[2])).split("x")[-1]
+ hex(int(uid[3])).split("x")[-1]
)
card = '{:02x}{:02x}{:02x}{:02x}'.format(
uid[0], uid[1], uid[2], uid[3])

return card
60 changes: 49 additions & 11 deletions lib/Clocking.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import time
import subprocess
import logging
from dicts.ras_dic import NET_INTERFACE

_logger = logging.getLogger(__name__)

Expand All @@ -14,7 +15,10 @@ def __init__(self, odoo, hardware):
self.Disp = hardware[1] # Display
self.Reader = hardware[2] # Card Reader

self.net_interface = NET_INTERFACE # wlan0 or eth0
self.wifi = False
self.interface_stable = False
self.interface_msg = 'Unknown'

self.card_logging_time_min = 1.5
# minimum amount of seconds allowed for
Expand Down Expand Up @@ -51,6 +55,19 @@ def wifi_active(self):
wifi_active = True
return wifi_active

def interface_active(self):
if self.net_interface == 'wlan0':
interface_active = self.wifi_active()
elif self.net_interface == 'eth0':
ifconfig_out = subprocess.check_output(
'ifconfig eth0', shell=True).decode('utf-8')
if 'UP' in ifconfig_out:
interface_active = True
else:
interface_active = False
_logger.warning('Ethernet Active is %s' % interface_active)
return interface_active

def get_status(self):
iwresult = subprocess.check_output(
"iwconfig wlan0", shell=True
Expand Down Expand Up @@ -104,18 +121,43 @@ def wifi_signal_msg(self):
self.wifi = True
return msg

def get_interface_msg(self):
if self.net_interface == 'wlan0':
return self.wifi_signal_msg()
elif self.net_interface == 'eth0':
ifconfig_out = subprocess.check_output(
'ifconfig eth0', shell=True).decode('utf-8')
if 'RUNNING' in ifconfig_out:
return ' Ethernet OK'
else:
return ' NO Ethernet'

def interface_running(self):
if self.net_interface == 'wlan0':
self.interface_stable = self.wifi_stable()
elif self.net_interface == 'eth0':
ifconfig_out = subprocess.check_output(
'ifconfig eth0', shell=True).decode('utf-8')
if 'RUNNING' in ifconfig_out:
self.interface_stable = True # stable in the case of ethernet
# means 'running'
else:
self.interface_stable = False
return self.interface_stable

def wifi_stable(self):
msg = self.wifi_signal_msg()
return self.wifi

def odoo_msg(self):
msg = "NO Odoo connected"
self.odoo_conn = False
if self.wifi_stable():
if self.interface_running():
if self.Odoo._get_user_id():
msg = " Odoo OK"
self.odoo_conn = True
return msg
else:
msg = "NO Odoo connected"
self.odoo_conn = False
_logger.warn(msg)
return msg

Expand Down Expand Up @@ -143,12 +185,8 @@ def clock_sync(self):
_logger.info("Clocking sync returns: %s" % self.msg)

def get_messages(self):
self.wifi_m = self.wifi_signal_msg() # get wifi strength signal
if not self.wifi:
self.odoo_m = "NO Odoo connected"
self.odoo_conn = False
else:
self.odoo_m = self.odoo_msg() # get odoo connection msg
self.odoo_m = self.odoo_msg()
self.interface_msg = self.get_interface_msg()

def clocking(self):
# Main Functions of the Terminal:
Expand Down Expand Up @@ -182,9 +220,9 @@ def clocking(self):

begin_card_logging = time.perf_counter()
# store the time when the card logging process begin
self.wifi_m = self.wifi_signal_msg()
self.wifi_m = self.get_interface_msg()

if not self.wifi:
if not self.interface_running():
self.msg = "ContactAdm"
else:
self.clock_sync() # synchronous: when odoo not
Expand Down
43 changes: 30 additions & 13 deletions lib/OdooXMLrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import time
import json
import logging
import requests

from dicts import tz_dic
from dicts.ras_dic import WORK_DIR
Expand Down Expand Up @@ -42,13 +43,17 @@ def set_params(self):
self.https_on = False
self.url_template = False
self.uid = False
self.iot_call = False
else:
self.db = self.j_data["db"][0]
self.user = self.j_data["user_name"][0]
self.pswd = self.j_data["user_password"][0]
self.host = self.j_data["odoo_host"][0]
self.port = self.j_data["odoo_port"][0]

if "iot_call" in self.j_data:
self.iot_call = True
else:
self.iot_call = False
self.adm = self.j_data["admin_id"][0]
self.tz = self.j_data["timezone"][0]

Expand All @@ -59,20 +64,22 @@ def set_params(self):
self.https_on = False
else:
self.https_on = True

if self.https_on:
if self.port:
self.url_template = "https://%s:%s" % (
self.host,
self.port,
)
else:
self.url_template = "https://%s" % self.host
if self.iot_call:
self.url_template = self.host
else:
if self.port:
self.url_template = "http://%s:%s" % (self.host, self.port)
if self.https_on:
if self.port:
self.url_template = "https://%s:%s" % (
self.host,
self.port,
)
else:
self.url_template = "https://%s" % self.host
else:
self.url_template = "http://%s" % self.host
if self.port:
self.url_template = "http://%s:%s" % (self.host, self.port)
else:
self.url_template = "http://%s" % self.host

self.uid = self._get_user_id()

Expand All @@ -87,6 +94,8 @@ def _get_object_facade(self, url):

def _get_user_id(self):
try:
if self.iot_call:
return True
login_facade = self._get_object_facade("/xmlrpc/common")
user_id = login_facade.login(self.db, self.user, self.pswd)
if user_id:
Expand All @@ -101,6 +110,14 @@ def _get_user_id(self):

def check_attendance(self, card):
try:
if self.iot_call:
return json.loads(requests.post(
'%s/iot/%s/action' % (self.url_template, self.user),
data={
'passphrase': self.pswd,
'value': card,
},
).content.decode('utf-8'))
object_facade = self._get_object_facade("/xmlrpc/object")
if object_facade:
res = object_facade.execute(
Expand Down
4 changes: 2 additions & 2 deletions lib/Tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def __init__(self, Odoo, Hardware):
# 'are you sure?' upon selection
self.get_ip = routes.get_ip
self.can_connect = Odoo.can_connect
self.wifi_active = self.Clock.wifi_active
self.wifi_stable = self.Clock.wifi_stable
self.wifi_active = self.Clock.interface_active
self.wifi_stable = self.Clock.interface_running

# Menu vars
self.begin_option = 0 # the Terminal begins with this option
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ Flask
luma.oled
spi
psutil
RPi.GPIO
RPi.GPIO
requests
2 changes: 2 additions & 0 deletions templates/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ <h1>Configuration portal</h1>
<label for="https">Click the checkbox if your Odoo employs HTTPS:</label>
<span>If you use default HTTPS port 443 leave port field empty</span>
<input type="checkbox" id="https" value="https" name="https"><label class="light" for="https"></label><br>
<label for="iot_call">Click the checkbox if your Odoo employs IOT Calls: </label>
<input type="checkbox" id="iot_call" value="iot_call" name="iot_call"><label class="light" for="iot_call"></label><br>
<label for="user">Username (*)</label>
<input type="text" id="user" name="user_name" placeholder="rfid_attendance" required>
<label for="password">Password (*)</label>
Expand Down