Compare commits
2 Commits
c1fa662552
...
29a5cc6f47
| Author | SHA1 | Date | |
|---|---|---|---|
| 29a5cc6f47 | |||
| 25008d7845 |
100
taosTest.py
Normal file
100
taosTest.py
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
import taosws
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
|
def create_connection():
|
||||||
|
host = "192.168.1.87"
|
||||||
|
port = 6041
|
||||||
|
|
||||||
|
conn = taosws.connect(
|
||||||
|
host=host,
|
||||||
|
port=port,
|
||||||
|
user="root",
|
||||||
|
password="wDvfFffdwbm5U15K",
|
||||||
|
database="tms"
|
||||||
|
)
|
||||||
|
|
||||||
|
print(f"Connected to {host}:{port}")
|
||||||
|
return conn
|
||||||
|
|
||||||
|
|
||||||
|
def create_sub_table(conn):
|
||||||
|
sql = """
|
||||||
|
CREATE TABLE IF NOT EXISTS gj_jxjs_sk_test001
|
||||||
|
USING gj_jxjs_sk
|
||||||
|
TAGS ('test001','equip001')
|
||||||
|
"""
|
||||||
|
conn.execute(sql)
|
||||||
|
print("Sub table created")
|
||||||
|
|
||||||
|
|
||||||
|
def insert_test_data(conn):
|
||||||
|
|
||||||
|
base_ts = int(time.time() * 1000)
|
||||||
|
|
||||||
|
sql = f"""
|
||||||
|
INSERT INTO gj_jxjs_sk_test001 VALUES
|
||||||
|
({base_ts}, 'well1',1,1,1,20250311,120000,1,100.5,100.5,100.5,100.5,5.5,10.5,200,200,5.5,5.5,100,100,120,200,200,1,1,1,10,10,1,1,1,1,1,1,1,1,1,1,1,100,5,1,1,1,1,1),
|
||||||
|
({base_ts+1000}, 'well1',1,1,2,20250311,120001,1,101.5,101.5,101.5,101.5,5.6,10.6,201,201,5.6,5.6,101,101,121,201,201,1,1,1,11,11,1,1,1,1,1,1,1,1,1,1,1,101,5,1,1,1,1,1),
|
||||||
|
({base_ts+2000}, 'well1',1,1,3,20250311,120002,1,102.5,102.5,102.5,102.5,5.7,10.7,202,202,5.7,5.7,102,102,122,202,202,1,1,1,12,12,1,1,1,1,1,1,1,1,1,1,1,102,5,1,1,1,1,1)
|
||||||
|
"""
|
||||||
|
|
||||||
|
conn.execute(sql)
|
||||||
|
|
||||||
|
print("Insert success")
|
||||||
|
|
||||||
|
return base_ts
|
||||||
|
|
||||||
|
|
||||||
|
def query_stable(conn, start_ts, end_ts):
|
||||||
|
|
||||||
|
sql = f"""
|
||||||
|
SELECT ts, actual_date, actual_time, deptbitm, chkp, sppa, rpma, torqa, hkla, blkpos, woba
|
||||||
|
FROM gj_jxjs_sk
|
||||||
|
WHERE ts > {start_ts} AND ts < {end_ts}
|
||||||
|
ORDER BY ts ASC
|
||||||
|
"""
|
||||||
|
|
||||||
|
result = conn.query(sql)
|
||||||
|
|
||||||
|
print("\nQuery from STABLE (gj_jxjs_sk):")
|
||||||
|
for row in result:
|
||||||
|
print(row)
|
||||||
|
|
||||||
|
|
||||||
|
def query_sub_table(conn, start_ts, end_ts):
|
||||||
|
|
||||||
|
sql = f"""
|
||||||
|
SELECT ts, actual_date, actual_time, deptbitm, chkp, sppa, rpma, torqa, hkla, blkpos, woba
|
||||||
|
FROM gj_jxjs_sk_test001
|
||||||
|
WHERE ts > {start_ts} AND ts < {end_ts}
|
||||||
|
ORDER BY ts ASC
|
||||||
|
"""
|
||||||
|
|
||||||
|
result = conn.query(sql)
|
||||||
|
|
||||||
|
print("\nQuery from SUB TABLE (gj_jxjs_sk_test001):")
|
||||||
|
for row in result:
|
||||||
|
print(row)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
|
||||||
|
conn = create_connection()
|
||||||
|
|
||||||
|
try:
|
||||||
|
|
||||||
|
# 1 创建子表
|
||||||
|
create_sub_table(conn)
|
||||||
|
|
||||||
|
# 2 插入测试数据
|
||||||
|
base_ts = insert_test_data(conn)
|
||||||
|
|
||||||
|
# 3 查询 STABLE
|
||||||
|
query_stable(conn, base_ts - 1000, base_ts + 5000)
|
||||||
|
|
||||||
|
# 4 查询子表
|
||||||
|
query_sub_table(conn, base_ts - 1000, base_ts + 5000)
|
||||||
|
|
||||||
|
finally:
|
||||||
|
conn.close()
|
||||||
@@ -1,20 +1,28 @@
|
|||||||
import ssl
|
import ssl
|
||||||
import websocket
|
import websocket
|
||||||
|
|
||||||
# URL = "ws://192.168.1.202:9100/well-tool-test-system/ws/"
|
URL = "wss://192.168.1.87/ws/" # 注意走 443,不要再连 8080 了
|
||||||
|
# 如果你的 WS 路径是 /ws/,就写成上面这样;若是别的路径自己改
|
||||||
|
|
||||||
URL = "wss://192.168.1.87/ws/"
|
def on_message(ws, msg): print("收到:", msg)
|
||||||
ws = websocket.WebSocketApp(
|
def on_error(ws, err): print("错误:", err)
|
||||||
URL,
|
def on_close(ws, code, reason): print("关闭:", code, reason)
|
||||||
on_open=lambda ws: print("连接成功"),
|
def on_open(ws):
|
||||||
on_message=lambda ws, msg: print("消息:", msg),
|
print("连接成功")
|
||||||
on_error=lambda ws, err: print("错误:", err),
|
ws.send("hello server mac")
|
||||||
on_close=lambda ws, code, reason: print("关闭:", code, reason),
|
|
||||||
)
|
|
||||||
|
|
||||||
ws.run_forever(
|
if __name__ == "__main__":
|
||||||
sslopt={
|
websocket.enableTrace(True)
|
||||||
|
ws = websocket.WebSocketApp(
|
||||||
|
URL,
|
||||||
|
on_open=on_open,
|
||||||
|
on_message=on_message,
|
||||||
|
on_error=on_error,
|
||||||
|
on_close=on_close,
|
||||||
|
# header=["Origin: https://192.168.1.3"] # 如后端不校验 Origin 可删
|
||||||
|
header=[] # 如后端不校验 Origin 可删
|
||||||
|
)
|
||||||
|
ws.run_forever(sslopt={
|
||||||
"cert_reqs": ssl.CERT_NONE,
|
"cert_reqs": ssl.CERT_NONE,
|
||||||
"check_hostname": False,
|
"check_hostname": False,
|
||||||
}
|
})
|
||||||
)
|
|
||||||
Reference in New Issue
Block a user