-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPoC_tewa.py
100 lines (75 loc) · 2.44 KB
/
PoC_tewa.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# -*- coding: utf-8 -*-
"""
Created on Tue Dec 20 09:50:58 2022
@author: pc1
"""
import signal
import sys
import time
from functools import partial
import zmq
from PyQt6.QtWidgets import (
QApplication,
QLabel,
QPushButton,
QVBoxLayout,
QWidget,
)
run = True
def signal_handler(signal, frame):
global run
print("Stopping")
run = not run
signal.signal(signal.SIGINT, signal_handler)
def greet(name):
global run
count = 1
while run:
string = sock_tewa_sub.recv_string()
zipcode, pub_time, temperature, relative_humidity = string.split()
# total_temp = int(temperature)
# From Cluster
try:
string = sock_cluster_sub.recv_string(flags=zmq.NOBLOCK)
zip_filter, pub_time, CLUSTER, relative_humidity = string.split()
rec_2.append([pub_time, time.time_ns(), zip_filter, CLUSTER, relative_humidity])
# print(f"Cluster Feedback: {pub_time} {time.time_ns()} {zip_filter}")
rec_1.append([pub_time, time.time_ns(), zip_filter, temperature, relative_humidity])
# print(f"From Data Received: {zipcode} {pub_time} {temperature}")
sock_gui_pub.send_string(f"{zipcode} {pub_time} {temperature} {relative_humidity}")
print(f"Counted packets {count}")
count += 1
except zmq.Again:
pass
run = not run
print("TEWA Module Stopped")
app = QApplication([])
window = QWidget()
window.resize(300, 300)
window.setWindowTitle("TEWA Module")
layout = QVBoxLayout()
button = QPushButton("TEWA")
button.clicked.connect(partial(greet, "World!"))
layout.addWidget(button)
message = QLabel("")
layout.addWidget(message)
window.setLayout(layout)
ctx = zmq.Context()
# Collecting updates from weather server...
sock_tewa_sub = ctx.socket(zmq.SUB)
print("Collecting updates from weather server...")
sock_tewa_sub.connect("tcp://localhost:5557")
# Subscribe to data_rec, default is TEWA, 10002
zip_filter = sys.argv[1] if len(sys.argv) > 1 else "10002"
sock_tewa_sub.setsockopt_string(zmq.SUBSCRIBE, zip_filter)
# Be publisher if temperature is greater than 120
sock_gui_pub = ctx.socket(zmq.PUB)
sock_gui_pub.bind("tcp://*:5560")
# Getting Feedback from client 'Cluster' if temperature is high
sock_cluster_sub = ctx.socket(zmq.SUB)
sock_cluster_sub.connect("tcp://localhost:5570")
sock_cluster_sub.setsockopt_string(zmq.SUBSCRIBE, '')
rec_1 = []
rec_2 = []
window.show()
sys.exit(app.exec())