diff --git a/docs/index.md b/docs/index.md index 69bc073..fc2e7aa 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,3 +1,11 @@ # Rig Water Pump ### Developed by @patrickjmcd, @Henry-Pump + +## Automatic Control Modes + +### Pressure Control + +### Flow Control + +## Manual Control Mode diff --git a/rigpump/html-templates/Device.html b/rigpump/html-templates/Device.html new file mode 100644 index 0000000..7b76f5d --- /dev/null +++ b/rigpump/html-templates/Device.html @@ -0,0 +1,42 @@ +
+
+

Public IP Address

+

<%= channels["rigpump.public_ip_address"].value %>

+

+
+ + diff --git a/rigpump/python-driver/config.txt b/rigpump/python-driver/config.txt index efb87c2..7f4dca5 100644 --- a/rigpump/python-driver/config.txt +++ b/rigpump/python-driver/config.txt @@ -3,7 +3,7 @@ "driverFileName":"rigpump.py", "deviceName":"rigpump", "driverId":"0150", -"releaseVersion":"1", +"releaseVersion":"5", "files": { "file1":"rigpump.py", "file2":"Channel.py", diff --git a/rigpump/python-driver/modbusMap.p b/rigpump/python-driver/modbusMap.p index 344b259..28cc57d 100644 --- a/rigpump/python-driver/modbusMap.p +++ b/rigpump/python-driver/modbusMap.p @@ -19,92 +19,92 @@ p9 V2-2 p11 (dp12 -Val +Vah p13 V p14 -sVah -p15 -g14 sVbytary +p15 +NsVal p16 -NsVvm +g14 +sVvn p17 -NsVvn -p18 VVFD Current -p19 +p18 sVct -p20 +p19 Vnumber -p21 +p20 sVle -p22 +p21 V16 -p23 +p22 sVgrp -p24 +p23 V3600 -p25 +p24 sVla -p26 -F0.0 +p25 +F52.357959747314453 sVchn -p27 +p26 Vvfd_current -p28 +p27 sVun -p29 +p28 V1 -p30 +p29 sVdn -p31 +p30 Vrigpump +p31 +sVvm p32 -sVda +NsVlrt p33 -V300 +F1507133764.2258689 +sVda p34 -sVlrt +V300 p35 -F1504128305.682013 -sVr -p36 -V0-250 -p37 sVa -p38 +p36 VVFD_OutCurrent -p39 +p37 sVc -p40 +p38 V1.0 -p41 +p39 sVmisc_u -p42 +p40 VAmps -p43 +p41 sVf -p44 -g30 +p42 +g29 sVmrt -p45 +p43 V60 -p46 +p44 sVm -p47 +p45 Vnone -p48 +p46 sS'm1ch' -p49 +p47 g11 +sVmv +p48 +V0 +p49 sVs p50 VOn p51 -sVmv +sVr p52 -V0 +V0-250 p53 sVt p54 @@ -113,800 +113,811 @@ p55 ssV2-3 p56 (dp57 -Vah +g52 +V0-75 p58 +sVah +p59 g14 sVbytary -p59 -NsVal p60 +NsVal +p61 g14 sVvn -p61 -VVFD Frequency p62 -sVct +VVFD Frequency p63 -Vnumber +sVct p64 -sVle +Vnumber p65 -V16 +sVle p66 -sVgrp +V16 p67 -V3600 +sVgrp p68 -sVla +V3600 p69 -F0.0 -sVchn +sVla p70 -Vvfd_frequency +F55.608009338378906 +sVchn p71 -sVun +Vvfd_frequency p72 -g30 -sVdn +sVun p73 -Vrigpump +g29 +sVdn p74 -sVvm +Vrigpump p75 -NsVlrt +sVvm p76 -F1504129549.8809668 -sVda +NsVlrt p77 -V300 +F1507133769.354713 +sVda p78 -sg38 -VVFD_SpeedFdbk +V300 p79 -sg40 -V0.5 +sg36 +VVFD_SpeedFdbk p80 -sVmisc_u +sg38 +V0.5 p81 -VHz +sVmisc_u p82 -sg44 -g30 -sVmrt +VHz p83 -V60 +sg42 +g29 +sVmrt p84 -sg47 -Vnone +V60 p85 -sVm1ch +sg45 +Vnone p86 -g56 -sVmv +sVm1ch p87 -g53 +g56 sg50 VOn p88 -sg36 -V0-75 +sVmv p89 +g49 sg54 Vint p90 ssV2-1 p91 (dp92 -Val +Vah p93 g14 -sVah -p94 -g14 sVbytary +p94 +NsVal p95 -NsVvm +g14 +sVvn p96 -NsVvn -p97 VDischarge Pressure -p98 +p97 sVct -p99 +p98 Vnumber -p100 +p99 sVle -p101 +p100 V16 -p102 +p101 sVgrp -p103 +p102 V3600 -p104 +p103 sVla -p105 +p104 F0.0 sVchn -p106 +p105 Vdischarge_pressure -p107 +p106 sVun -p108 -g30 +p107 +g29 sVdn -p109 +p108 Vrigpump +p109 +sVvm p110 -sVda +NsVlrt p111 -V300 +F1507133774.5094061 +sVda p112 -sVlrt +V300 p113 -F1504129459.392449 sg36 -V0-500 +Vval_DischargePressure p114 sg38 -Vval_DischargePressure -p115 -sg40 V5.0 -p116 +p115 sVmisc_u -p117 +p116 VPSI -p118 -sg44 -g30 +p117 +sg42 +g29 sVmrt -p119 +p118 V60 +p119 +sg45 +Vnone p120 sg47 -Vnone -p121 -sg49 g91 +sVmv +p121 +g49 sg50 VOn p122 -sVmv +sg52 +V0-500 p123 -g53 sg54 Vint p124 ssV2-6 p125 (dp126 -Val +Vah p127 g14 -sVah -p128 -g14 sVbytary +p128 +NsVal p129 -NsVvm +g14 +sVvn p130 -NsVvn -p131 VDischarge Pressure Setpoint -p132 +p131 sVct -p133 +p132 Vnumber -p134 +p133 sVle -p135 +p134 V16 -p136 +p135 sVgrp -p137 +p136 V3600 -p138 +p137 sVla -p139 -F30.0 +p138 +F60.0 sVchn -p140 +p139 Vdischarge_pressure_setpoint -p141 +p140 sVun -p142 -g30 +p141 +g29 sVdn -p143 +p142 Vrigpump +p143 +sVvm p144 -sVda +NsVlrt p145 -V300 +F1507133779.6010119 +sVda p146 -sVlrt +V300 p147 -F1504128306.392521 sg36 -V0-500 +Vcfg_PID_DischargePressureSP p148 sg38 -Vcfg_PID_DischargePressureSP -p149 -sg40 V0.5 -p150 +p149 sVmisc_u -p151 +p150 VPSI -p152 -sg44 -g30 +p151 +sg42 +g29 sVmrt -p153 +p152 V60 +p153 +sg45 +Vnone p154 sg47 -Vnone -p155 -sg49 g125 +sVmv +p155 +g49 sg50 VOn p156 -sVmv +sg52 +V0-500 p157 -g53 sg54 Vint p158 ssV2-7 p159 (dp160 -Val +Vah p161 g14 -sVah -p162 -g14 sVbytary +p162 +NsVal p163 -NsVvm +g14 +sVvn p164 -NsVvn -p165 VVFD Frequency Setpoint -p166 +p165 sVct -p167 +p166 Vnumber -p168 +p167 sVle -p169 +p168 V16 -p170 +p169 sVgrp -p171 +p170 V3600 -p172 +p171 sVla -p173 -F55.0 +p172 +F60.0 sVchn -p174 +p173 Vvfd_frequency_setpoint -p175 +p174 sVun -p176 -g30 +p175 +g29 sVdn -p177 +p176 Vrigpump +p177 +sVvm p178 -sVda +NsVlrt p179 -V300 +F1507133723.4260002 +sVda p180 -sVlrt +V300 p181 -F1504128306.597828 sg36 -V0-75 +Vcfg_PID_ManualSP p182 sg38 -Vcfg_PID_ManualSP -p183 -sg40 V0.5 -p184 +p183 sVmisc_u -p185 +p184 VHz -p186 -sg44 -g30 +p185 +sg42 +g29 sVmrt -p187 +p186 V60 +p187 +sg45 +Vnone p188 sg47 -Vnone -p189 -sg49 g159 +sVmv +p189 +g49 sg50 VOn p190 -sVmv +sg52 +V0-75 p191 -g53 sg54 Vint p192 ssV2-4 p193 (dp194 -Val +Vah p195 g14 -sVah -p196 -g14 sVbytary +p196 +NsVal p197 -NsVvm +g14 +sVvn p198 -(dp199 -g30 -VRunning -p200 -sV128 -p201 -VOverpressure -p202 -sV64 -p203 -VIdle -p204 -sV1024 -p205 -VFaulted -p206 -ssVvn -p207 VDevice Status -p208 +p199 sVct -p209 +p200 Vnumber -p210 +p201 sVle -p211 +p202 V16 -p212 +p203 sVgrp -p213 +p204 V3600 -p214 +p205 sVla -p215 -I64 +p206 +I1 sVchn -p216 +p207 Vdevice_status -p217 +p208 sVun -p218 -g30 +p209 +g29 sVdn -p219 +p210 Vrigpump +p211 +sVvm +p212 +(dp213 +g29 +VRunning +p214 +sV128 +p215 +VOverpressure +p216 +sV64 +p217 +VIdle +p218 +sV1024 +p219 +VFaulted p220 -sVda +ssVlrt p221 -V300 +F1507133728.5280639 +sVda p222 -sVlrt +V300 p223 -F1504128306.7821309 sg36 -V0-32768 +VRigPump.State p224 sg38 -VRigPump.State -p225 -sg40 -g30 +g29 sVmisc_u -p226 +p225 g14 -sg44 -g30 +sg42 +g29 sVmrt -p227 +p226 V60 +p227 +sg45 +Vnone p228 sg47 -Vnone -p229 -sg49 g193 +sVmv +p229 +g49 sg50 VOn p230 -sVmv +sg52 +V0-32768 p231 -g53 sg54 Vint p232 ssV2-5 p233 (dp234 -Val +Vah p235 g14 -sVah -p236 -g14 sVbytary +p236 +NsVal p237 -NsVvm +g14 +sVvn p238 -NsVvn -p239 VFlow Rate Setpoint -p240 +p239 sVct -p241 +p240 Vnumber -p242 +p241 sVle -p243 +p242 V16 -p244 +p243 sVgrp -p245 +p244 V3600 -p246 +p245 sVla -p247 -F50.0 +p246 +F55.0 sVchn -p248 +p247 Vflow_rate_setpoint -p249 +p248 sVun -p250 -g30 +p249 +g29 sVdn -p251 +p250 Vrigpump +p251 +sVvm p252 -sVda +NsVlrt p253 -V300 +F1507133733.768225 +sVda p254 -sVlrt +V300 p255 -F1504128306.9468218 sg36 -V0-5000 +Vcfg_PID_FlowSP p256 sg38 -Vcfg_PID_FlowSP -p257 -sg40 V0.1 -p258 +p257 sVmisc_u -p259 +p258 VBPM -p260 -sg44 -g30 +p259 +sg42 +g29 sVmrt -p261 +p260 V60 +p261 +sg45 +Vnone p262 sg47 -Vnone -p263 -sg49 g233 +sVmv +p263 +g49 sg50 VOn p264 -sVmv +sg52 +V0-5000 p265 -g53 sg54 Vint p266 ssV2-8 p267 (dp268 -Val +Vr p269 -g14 -sVah +V0-1 p270 +sVah +p271 g14 sVbytary -p271 -NsVvm p272 -(dp273 -g30 -VAuto +NsVal +p273 +V0 p274 -sg53 -VManual +sVvn p275 -ssVvn -p276 VAuto/Manual Mode -p277 +p276 sVct -p278 +p277 Vnumber -p279 +p278 sVle -p280 +p279 V16 -p281 +p280 sVgrp -p282 +p281 V3600 -p283 +p282 sVla -p284 -I0 +p283 +g14 sVchn -p285 +p284 Vauto_manual -p286 +p285 sVun +p286 +V1 p287 -g30 sVdn p288 Vrigpump p289 -sVda +sVvm p290 -V300 -p291 -sVlrt +(dp291 +g287 +VAuto p292 -F1504128307.132611 -sg36 -V0-1 +sg274 +VManual p293 -sg38 -Vmode_Auto +ssVlrt p294 -sg40 -g53 -sVmisc_u +F1507133507.0949212 +sVda p295 -g14 -sg44 -g30 -sVmrt +V300 p296 -V60 +sVa p297 -sg47 -Vnone +Vmode_Auto p298 -sg49 -g267 -sg50 -VOn +sVc p299 -sVmv +g274 +sVmisc_u p300 -g53 -sg54 -Vint +g14 +sVf p301 -ssV2-9 +g287 +sVmrt p302 -(dp303 -Vah +V60 +p303 +sVm p304 +Vnone +p305 +sVm1ch +p306 +g267 +sVs +p307 +VOn +p308 +sVmv +p309 +g274 +sVt +p310 +Vint +p311 +ssV2-9 +p312 +(dp313 +Vah +p314 g14 sVbytary -p305 +p315 NsVal -p306 +p316 +g274 +sVvn +p317 +VControl Mode +p318 +sVct +p319 +Vnumber +p320 +sVle +p321 +V16 +p322 +sVgrp +p323 +V3600 +p324 +sVla +p325 +g14 +sVchn +p326 +Vauto_control_mode +p327 +sVun +p328 +g287 +sVdn +p329 +Vrigpump +p330 +sVda +p331 +V300 +p332 +sVlrt +p333 +g274 +sg297 +VcontrolMode +p334 +sg299 +g274 +sVmisc_u +p335 +g14 +sg301 +g287 +sVmrt +p336 +V60 +p337 +sg304 +Vnone +p338 +sVm1ch +p339 +g312 +sVmv +p340 +g274 +sg307 +VOn +p341 +sg269 +V0-1 +p342 +sg310 +Vint +p343 +sVvm +p344 +(dp345 +g287 +VFlow +p346 +sg274 +VPressure +p347 +sssV2-11 +p348 +(dp349 +Vah +p350 +g14 +sVbytary +p351 +NsVal +p352 g14 sVvn -p307 -VControl Mode -p308 -sVct -p309 -Vnumber -p310 -sVle -p311 -V16 -p312 -sVgrp -p313 -V3600 -p314 -sVla -p315 -NsVchn -p316 -Vauto_control_mode -p317 -sVun -p318 -g30 -sVdn -p319 -Vrigpump -p320 -sVvm -p321 -(dp322 -g30 -VFlow -p323 -sg53 -VPressure -p324 -ssVlrt -p325 -g53 -sVda -p326 -V300 -p327 -sg38 -Vauto_control_mode -p328 -sg40 -g53 -sVmisc_u -p329 -g14 -sg44 -g30 -sVmrt -p330 -V60 -p331 -sg47 -Vnone -p332 -sVm1ch -p333 -g302 -sVmv -p334 -g53 -sg50 -VOn -p335 -sg36 -V0-1 -p336 -sg54 -Vint -p337 -ssV2-11 -p338 -(dp339 -Val -p340 -g14 -sVah -p341 -g14 -sVbytary -p342 -NsVvm -p343 -NsVvn -p344 +p353 VFlow Rate -p345 +p354 sVct -p346 +p355 Vnumber -p347 +p356 sVle -p348 +p357 V16 -p349 +p358 sVgrp -p350 +p359 V3600 -p351 +p360 sVla -p352 +p361 F0.0 sVchn -p353 -Vflow_rate -p354 -sVun -p355 -g30 -sVdn -p356 -Vrigpump -p357 -sVda -p358 -g9 -sVlrt -p359 -F1504128307.4822289 -sg36 -V0-50000 -p360 -sg38 -Vval_Flowmeter -p361 -sg40 -V5.0 p362 -sVmisc_u +Vflow_rate p363 -VBPM +sVun p364 -sg44 -g30 -sVmrt +g29 +sVdn p365 -V60 +Vrigpump p366 -sg47 -Vnone +sVvm p367 -sg49 -g338 +NsVlrt +p368 +F1507133810.3850061 +sVda +p369 +g9 +sg36 +Vval_Flowmeter +p370 +sg38 +V5.0 +p371 +sVmisc_u +p372 +VBPM +p373 +sg42 +g29 +sVmrt +p374 +V60 +p375 +sg45 +Vnone +p376 +sg47 +g348 +sVmv +p377 +g49 sg50 VOn -p368 -sVmv -p369 -g53 +p378 +sg52 +V0-50000 +p379 sg54 Vint -p370 +p380 ssssS'f' -p371 +p381 VOff -p372 +p382 sS'p' -p373 +p383 g14 sS's' -p374 -g30 +p384 +g287 ssS'2' -p375 -(dp376 +p385 +(dp386 g3 VM1-232 -p377 +p387 sg5 V9600 -p378 +p388 sg7 -(dp379 -sg371 +(dp389 +sg381 VOff -p380 -sg373 +p390 +sg383 g14 -sg374 -g30 +sg384 +g287 ss. \ No newline at end of file diff --git a/rigpump/python-driver/rigpump.py b/rigpump/python-driver/rigpump.py index 21b331b..cdb755c 100644 --- a/rigpump/python-driver/rigpump.py +++ b/rigpump/python-driver/rigpump.py @@ -1,4 +1,4 @@ -"""Driver for rigpump""" +"""Driver for rigpump.""" import threading from device_base import deviceBase @@ -7,6 +7,7 @@ from Maps import rigpump_map as maps from random import randint import json import time +import socket _ = None @@ -16,7 +17,7 @@ try: except Exception: persist = {} -plc_ip_address = "192.168.1.10" +PLC_IP_ADDRESS = "192.168.1.10" def reverse_map(value, map_): @@ -27,6 +28,15 @@ def reverse_map(value, map_): return None +def get_public_ip_address(): + """Find the public IP Address of the host device.""" + s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + s.connect(("8.8.8.8", 80)) + ip = s.getsockname()[0] + s.close() + return ip + + channels = [] @@ -39,7 +49,7 @@ class start(threading.Thread, deviceBase): deviceBase.__init__(self, name=name, number=number, mac=mac, Q=Q, mcu=mcu, companyId=companyId, offset=offset, mqtt=mqtt, Nodes=Nodes) self.daemon = True - self.version = "3" + self.version = "5" self.finished = threading.Event() self.forceSend = False threading.Thread.start(self) @@ -54,7 +64,7 @@ class start(threading.Thread, deviceBase): def run(self): """Actually run the driver.""" global persist - watchdog = self.rigpump_watchdog() + wait_sec = 60 for i in range(0, wait_sec): print("rigpump driver will start in {} seconds".format(wait_sec - i)) @@ -63,7 +73,14 @@ class start(threading.Thread, deviceBase): # after its booted up assuming that M1 is now reading modbus data # we can replace the reference made to this device name to the M1 driver with this # driver. The 01 in the 0199 below is the device number you referenced in the modbus wizard - self.nodes["rigpump_0199"] = self + # self.nodes["rigpump_0199"] = self + + public_ip_address = get_public_ip_address() + self.sendtodbDev(1, 'public_ip_address', public_ip_address, 0, 'rigpump') + + watchdog = self.rigpump_watchdog() + self.sendtodbDev(1, 'watchdog', watchdog, 0, 'rigpump') + send_loops = 0 watchdog_loops = 0 watchdog_check_after = 5000 @@ -88,17 +105,25 @@ class start(threading.Thread, deviceBase): if (watchdog_loops >= watchdog_check_after): test_watchdog = self.rigpump_watchdog() if not test_watchdog == watchdog: - self.sendtodb('watchdog', test_watchdog, 0) + self.sendtodbDev(1, 'watchdog', test_watchdog, 0, 'rigpump') watchdog = test_watchdog + + test_public_ip = get_public_ip_address() + if not test_public_ip == public_ip_address: + self.sendtodbDev(1, 'public_ip_address', test_public_ip, 0, 'rigpump') + public_ip_address = test_public_ip watchdog_loops = 0 def rigpump_watchdog(self): """Write a random integer to the PLC and then 1 seconds later check that it has been decremented by 1.""" randval = randint(0, 32767) - write_tag(str(plc_ip_address), 'watchdog_INT', randval) + write_tag(str(PLC_IP_ADDRESS), 'watchdog_INT', randval) time.sleep(1) - watchdog_val = read_tag(str(plc_ip_address), 'watchdog_INT') - return (randval - 1) == watchdog_val[0] + watchdog_val = read_tag(str(PLC_IP_ADDRESS), 'watchdog_INT') + try: + return (randval - 1) == watchdog_val[0] + except (KeyError, TypeError): + return False def rigpump_sync(self, name, value): """Sync all data from the driver.""" @@ -111,7 +136,7 @@ class start(threading.Thread, deviceBase): new_val = json.loads(str(value).replace("'", '"')) tag_n = str(new_val['tag']) # "cmd_Start" val_n = new_val['val'] - w = write_tag(str(plc_ip_address), tag_n, val_n) + w = write_tag(str(PLC_IP_ADDRESS), tag_n, val_n) print("Result of rigpump_writeplctag(self, {}, {}) = {}".format(name, value, w)) if w is None: w = "Error writing to PLC..."