removed schedule library from gateway process in myems-bacnet service
parent
050304256f
commit
6f92e88ece
|
@ -10,8 +10,6 @@ bacpypes
|
||||||
|
|
||||||
mysql.connector
|
mysql.connector
|
||||||
|
|
||||||
Schedule
|
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
Download and install MySQL Connector:
|
Download and install MySQL Connector:
|
||||||
|
@ -38,14 +36,6 @@ Download and install bacpypes library
|
||||||
$ sudo ufw allow 47808
|
$ sudo ufw allow 47808
|
||||||
```
|
```
|
||||||
|
|
||||||
Download and install Schedule
|
|
||||||
```
|
|
||||||
$ cd ~/tools
|
|
||||||
$ git clone https://github.com/dbader/schedule.git
|
|
||||||
$ cd ~/tools/schedule
|
|
||||||
$ sudo python3 setup.py install
|
|
||||||
```
|
|
||||||
|
|
||||||
Install myems-bacnet service
|
Install myems-bacnet service
|
||||||
```
|
```
|
||||||
$ cd ~
|
$ cd ~
|
||||||
|
|
|
@ -12,22 +12,27 @@ import schedule
|
||||||
########################################################################################################################
|
########################################################################################################################
|
||||||
|
|
||||||
|
|
||||||
def job(logger, ):
|
def process(logger, ):
|
||||||
|
cnx_system_db = None
|
||||||
|
cursor_system_db = None
|
||||||
|
while True:
|
||||||
|
# the outermost while loop
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
# Step 1: Verify Gateway Token
|
# Step 1: Verify Gateway Token
|
||||||
################################################################################################################
|
################################################################################################################
|
||||||
cnx_system_db = None
|
while not cnx_system_db or not cnx_system_db.is_connected():
|
||||||
cursor_system_db = None
|
|
||||||
try:
|
try:
|
||||||
cnx_system_db = mysql.connector.connect(**config.myems_system_db)
|
cnx_system_db = mysql.connector.connect(**config.myems_system_db)
|
||||||
cursor_system_db = cnx_system_db.cursor()
|
cursor_system_db = cnx_system_db.cursor()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("Error in step 1.1 of Gateway process " + str(e))
|
logger.error("Error to connect to myems_system_db in step 1.1 of gateway process " + str(e))
|
||||||
if cursor_system_db:
|
if cursor_system_db:
|
||||||
cursor_system_db.close()
|
cursor_system_db.close()
|
||||||
if cnx_system_db:
|
if cnx_system_db:
|
||||||
cnx_system_db.close()
|
cnx_system_db.close()
|
||||||
return
|
print("Failed to connect to myems_system_db, sleep a minute and retry...")
|
||||||
|
time.sleep(60)
|
||||||
|
continue
|
||||||
|
|
||||||
# TODO: choose a more secure method to verify gateway token
|
# TODO: choose a more secure method to verify gateway token
|
||||||
try:
|
try:
|
||||||
|
@ -42,16 +47,13 @@ def job(logger, ):
|
||||||
cursor_system_db.close()
|
cursor_system_db.close()
|
||||||
if cnx_system_db:
|
if cnx_system_db:
|
||||||
cnx_system_db.close()
|
cnx_system_db.close()
|
||||||
return
|
time.sleep(60)
|
||||||
|
continue
|
||||||
|
|
||||||
if row is None:
|
if row is None:
|
||||||
logger.error("Error in step 1.3 of gateway process: Not Found ")
|
logger.error("Error in step 1.3 of gateway process: Gateway Not Found ")
|
||||||
if cursor_system_db:
|
time.sleep(60)
|
||||||
cursor_system_db.close()
|
continue
|
||||||
if cnx_system_db:
|
|
||||||
cnx_system_db.close()
|
|
||||||
return
|
|
||||||
|
|
||||||
############################################################################################################
|
############################################################################################################
|
||||||
# Step 2: Collect Gateway Information
|
# Step 2: Collect Gateway Information
|
||||||
############################################################################################################
|
############################################################################################################
|
||||||
|
@ -68,18 +70,14 @@ def job(logger, ):
|
||||||
cursor_system_db.execute(update_row, (config.gateway['id'], ))
|
cursor_system_db.execute(update_row, (config.gateway['id'], ))
|
||||||
cnx_system_db.commit()
|
cnx_system_db.commit()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("Error in step 3.1 of gateway process " + str(e))
|
logger.error("Error in step 3.2 of gateway process " + str(e))
|
||||||
return
|
|
||||||
finally:
|
|
||||||
if cursor_system_db:
|
if cursor_system_db:
|
||||||
cursor_system_db.close()
|
cursor_system_db.close()
|
||||||
if cnx_system_db:
|
if cnx_system_db:
|
||||||
cnx_system_db.close()
|
cnx_system_db.close()
|
||||||
|
|
||||||
|
|
||||||
def process(logger, ):
|
|
||||||
schedule.every(1).minutes.do(job, logger,)
|
|
||||||
|
|
||||||
while True:
|
|
||||||
schedule.run_pending()
|
|
||||||
time.sleep(60)
|
time.sleep(60)
|
||||||
|
continue
|
||||||
|
|
||||||
|
# sleep some seconds
|
||||||
|
time.sleep(60)
|
||||||
|
# end of the outermost while loop
|
||||||
|
|
Loading…
Reference in New Issue