Split into two different python packages.
This commit is contained in:
21
__init__.py
21
__init__.py
@@ -1,21 +0,0 @@
|
||||
import threading
|
||||
from plc_to_mongo import PLC_to_Mongo
|
||||
from poc_to_modbus import ModbusTCPMongoServer
|
||||
|
||||
PLC_IP_ADDRESS = 'denise1601.henryres.poconsole.net'
|
||||
|
||||
scraper_thread = PLC_to_Mongo(PLC_IP_ADDRESS)
|
||||
server_thread = ModbusTCPMongoServer()
|
||||
|
||||
|
||||
def main():
|
||||
scraper_thread.start()
|
||||
server_thread.start()
|
||||
|
||||
|
||||
def justscrape():
|
||||
scraper_thread.start()
|
||||
|
||||
|
||||
def justserve():
|
||||
server_thread.start()
|
||||
22932
currentValues.csv
22932
currentValues.csv
File diff suppressed because it is too large
Load Diff
10
poc_modbus_server/__init__.py
Normal file
10
poc_modbus_server/__init__.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from poc_to_modbus import ModbusTCPMongoServer
|
||||
|
||||
|
||||
def main():
|
||||
modbus_tcp_server = ModbusTCPMongoServer()
|
||||
modbus_tcp_server.run()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -22,6 +22,7 @@ import pymongo
|
||||
from pymongo import MongoClient
|
||||
from pycomm_helper import utils as plc
|
||||
from time import time as now
|
||||
from os import getenv
|
||||
import struct
|
||||
import threading
|
||||
# ---------------------------------------------------------------------------#
|
||||
@@ -32,6 +33,11 @@ logging.basicConfig()
|
||||
log = logging.getLogger()
|
||||
log.setLevel(logging.INFO)
|
||||
|
||||
PLC_IP_ADDRESS = getenv("PLC_IP_ADDRESS")
|
||||
print(PLC_IP_ADDRESS)
|
||||
if not PLC_IP_ADDRESS:
|
||||
exit("No PLC_IP_ADDRESS set in the environment variables")
|
||||
|
||||
|
||||
def float_to_bytes(float_val):
|
||||
'''
|
||||
@@ -247,7 +253,7 @@ def getTagsFromDB():
|
||||
return {'di': di_tags, 'co': co_tags, 'ir': ir_tags, 'hr': hr_tags}
|
||||
|
||||
|
||||
class ModbusTCPMongoServer(threading.Thread):
|
||||
class ModbusTCPMongoServer():
|
||||
def __init__(self):
|
||||
# ---------------------------------------------------------------------------#
|
||||
# initialize your data store
|
||||
@@ -275,4 +281,7 @@ class ModbusTCPMongoServer(threading.Thread):
|
||||
# ---------------------------------------------------------------------------#
|
||||
# run the server you want
|
||||
# ---------------------------------------------------------------------------#
|
||||
StartTcpServer(self.context, identity=self.identity, address=("0.0.0.0", 502))
|
||||
SERVER = "0.0.0.0"
|
||||
PORT = 502
|
||||
print("Starting a Modbus TCP Server on {} port {}...".format(SERVER, PORT))
|
||||
StartTcpServer(self.context, identity=self.identity, address=(SERVER, PORT))
|
||||
@@ -10,10 +10,9 @@ with open(os.path.join(here, 'CHANGES.md')) as f:
|
||||
|
||||
requires = [
|
||||
'pymongo',
|
||||
'pycomm',
|
||||
'pymodbus',
|
||||
'cryptography',
|
||||
'pyasn1'
|
||||
'pyasn1',
|
||||
]
|
||||
|
||||
tests_require = [
|
||||
@@ -21,7 +20,7 @@ tests_require = [
|
||||
]
|
||||
|
||||
setup(
|
||||
name='poc_to_modbustcp',
|
||||
name='poc_modbus_server',
|
||||
version='0.0',
|
||||
description='Modbus TCP Server for Henry POC',
|
||||
long_description=README + '\n\n' + CHANGES,
|
||||
@@ -44,9 +43,7 @@ setup(
|
||||
install_requires=requires,
|
||||
entry_points={
|
||||
'console_scripts': [
|
||||
'poc_to_modbustcp = poc_to_modbustcp.__init__:main',
|
||||
'poc_to_modbustcp_justscrape = poc_to_modbustcp.__init__:justscrape',
|
||||
'poc_to_modbustcp_justserve = poc_to_modbustcp.__init__:justserve',
|
||||
'poc_modbus_server = poc_modbus_server.__init__:main',
|
||||
],
|
||||
},
|
||||
)
|
||||
4
poc_scraper/CHANGES.md
Normal file
4
poc_scraper/CHANGES.md
Normal file
@@ -0,0 +1,4 @@
|
||||
0.0
|
||||
---
|
||||
|
||||
- Initial version.
|
||||
18
poc_scraper/README.md
Normal file
18
poc_scraper/README.md
Normal file
@@ -0,0 +1,18 @@
|
||||
# Modbus Register Map
|
||||
|
||||
## Coils
|
||||
|
||||
Reg. # | Description | Access |
|
||||
1 |
|
||||
|
||||
|
||||
# Installation
|
||||
|
||||
```
|
||||
sudo apt-get install python-dev libssl-dev
|
||||
pip install pymongo
|
||||
|
||||
|
||||
|
||||
|
||||
```
|
||||
16
poc_scraper/__init__.py
Normal file
16
poc_scraper/__init__.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from plc_to_mongo import PLC_to_Mongo
|
||||
from os import getenv
|
||||
from sys import exit
|
||||
|
||||
PLC_IP_ADDRESS = getenv("PLC_IP_ADDRESS")
|
||||
if not PLC_IP_ADDRESS:
|
||||
exit("No PLC_IP_ADDRESS set in the environment variables")
|
||||
|
||||
|
||||
def main():
|
||||
scraper_thread = PLC_to_Mongo(PLC_IP_ADDRESS)
|
||||
scraper_thread.run()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -4,26 +4,26 @@ from time import sleep
|
||||
from time import time as now
|
||||
from pymongo import MongoClient
|
||||
import pycomm_helper.utils as plc
|
||||
import threading
|
||||
import os
|
||||
|
||||
|
||||
class PLC_to_Mongo(threading.Thread):
|
||||
class PLC_to_Mongo():
|
||||
def __init__(self, plc_address):
|
||||
super(PLC_to_Mongo, self).__init__()
|
||||
client = MongoClient()
|
||||
self.db = client.tag_data
|
||||
self.tag_vals = self.db.tag_vals
|
||||
self.PLC_IP_ADDRESS = plc_address
|
||||
|
||||
def run(self):
|
||||
script_path = os.path.dirname(os.path.realpath(__file__))
|
||||
print("THERE ARE ALREADY {} VALUES IN tag_vals".format(self.tag_vals.count()))
|
||||
with open('analog.json', 'rb') as analogfile:
|
||||
with open(script_path + '/analog.json', 'rb') as analogfile:
|
||||
analog_list = json.loads(analogfile.read())
|
||||
|
||||
with open('digital.json', 'rb') as digitalfile:
|
||||
with open(script_path + '/digital.json', 'rb') as digitalfile:
|
||||
digital_list = json.loads(digitalfile.read())
|
||||
|
||||
with open('arraylist.json', 'rb') as arrayfile:
|
||||
with open(script_path + '/arraylist.json', 'rb') as arrayfile:
|
||||
arr_list = json.loads(arrayfile.read())
|
||||
|
||||
for entry in analog_list + digital_list + arr_list:
|
||||
49
poc_scraper/setup.py
Normal file
49
poc_scraper/setup.py
Normal file
@@ -0,0 +1,49 @@
|
||||
import os
|
||||
|
||||
from setuptools import setup, find_packages
|
||||
|
||||
here = os.path.abspath(os.path.dirname(__file__))
|
||||
with open(os.path.join(here, 'README.md')) as f:
|
||||
README = f.read()
|
||||
with open(os.path.join(here, 'CHANGES.md')) as f:
|
||||
CHANGES = f.read()
|
||||
|
||||
requires = [
|
||||
'pymongo',
|
||||
'pycomm',
|
||||
'pycomm_helper',
|
||||
]
|
||||
|
||||
tests_require = [
|
||||
'pytest',
|
||||
]
|
||||
|
||||
setup(
|
||||
name='poc_scraper',
|
||||
version='0.0',
|
||||
description='Modbus TCP Server for Henry POC',
|
||||
long_description=README + '\n\n' + CHANGES,
|
||||
classifiers=[
|
||||
'Programming Language :: Python',
|
||||
'Framework :: Pyramid',
|
||||
'Topic :: Internet :: WWW/HTTP',
|
||||
'Topic :: Internet :: WWW/HTTP :: WSGI :: Application',
|
||||
],
|
||||
dependency_links=['https://github.com/Henry-Pump/Pycomm-Helper/tarball/master#egg=pycomm_helper'],
|
||||
author='',
|
||||
author_email='',
|
||||
url='',
|
||||
keywords='web',
|
||||
packages=find_packages(),
|
||||
include_package_data=True,
|
||||
zip_safe=False,
|
||||
extras_require={
|
||||
'testing': tests_require,
|
||||
},
|
||||
install_requires=requires,
|
||||
entry_points={
|
||||
'console_scripts': [
|
||||
'poc_scraper = poc_scraper:main',
|
||||
],
|
||||
},
|
||||
)
|
||||
Reference in New Issue
Block a user