From 20eb5675fc120605b3078c448bb419ee1b4cf912 Mon Sep 17 00:00:00 2001 From: TrystanLea Date: Wed, 15 Jul 2020 17:42:42 +0100 Subject: [PATCH 1/3] include pi serial number in node name --- src/emonhub_interfacer.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/emonhub_interfacer.py b/src/emonhub_interfacer.py index 7446519e..29bbd40a 100644 --- a/src/emonhub_interfacer.py +++ b/src/emonhub_interfacer.py @@ -83,6 +83,30 @@ def __init__(self, name): # create a stop self.stop = False + + # Read RaspberryPi serial number if applicable + pi_serial = False + try: + f = open('/proc/cpuinfo','r') + for line in f: + if line[0:6]=='Serial': + length=len(line) + pi_serial = line[11:length-1] + f.close() + except: + pi_serial = False + + if pi_serial: + pi_serial_short = "" + zero_flag = 1 + for i in range(0,len(pi_serial)): + if pi_serial[i]!='0': + zero_flag = 0 + if not zero_flag: + pi_serial_short += pi_serial[i] + self._settings['serial_num'] = pi_serial_short.upper()+"_" + else: + self._settings['serial_num'] = "" @log_exceptions_from_class_method def run(self): @@ -418,7 +442,7 @@ def _process_rx(self, cargo): nodename = False if node in ehc.nodelist and 'nodename' in ehc.nodelist[node]: nodename = ehc.nodelist[node]['nodename'] - rxc.nodename = nodename + rxc.nodename = self._settings['serial_num']+nodename if not rxc: return False From 45cb180c9fe5b31851641583f10a4e7458b0cf73 Mon Sep 17 00:00:00 2001 From: TrystanLea Date: Thu, 16 Jul 2020 18:36:14 +0100 Subject: [PATCH 2/3] fix error --- src/emonhub_interfacer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/emonhub_interfacer.py b/src/emonhub_interfacer.py index 29bbd40a..b1c41cb6 100644 --- a/src/emonhub_interfacer.py +++ b/src/emonhub_interfacer.py @@ -442,7 +442,7 @@ def _process_rx(self, cargo): nodename = False if node in ehc.nodelist and 'nodename' in ehc.nodelist[node]: nodename = ehc.nodelist[node]['nodename'] - rxc.nodename = self._settings['serial_num']+nodename + rxc.nodename = str(self._settings['serial_num'])+str(nodename) if not rxc: return False From c1101a979f5c05145434b1249f1437ca949060bd Mon Sep 17 00:00:00 2001 From: TrystanLea Date: Thu, 16 Jul 2020 18:47:55 +0100 Subject: [PATCH 3/3] include serial in http buffer --- src/emonhub_interfacer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/emonhub_interfacer.py b/src/emonhub_interfacer.py index b1c41cb6..70370645 100644 --- a/src/emonhub_interfacer.py +++ b/src/emonhub_interfacer.py @@ -161,7 +161,7 @@ def add(self, cargo): f = [] try: f.append(cargo.timestamp) - f.append(cargo.nodeid) + f.append(str(self._settings['serial_num'])+str(cargo.nodeid)) # FIXME replace with f.extend(cargo.realdata) for i in cargo.realdata: f.append(i)