57 lines
1.0 KiB
Python
57 lines
1.0 KiB
Python
from SDT_Device.DTS import DTS
|
|
|
|
import time
|
|
import sys
|
|
import json
|
|
import uuid
|
|
import sdtcloudpubsub
|
|
|
|
|
|
# with open("./info.json","r") as f:
|
|
# info = f.read()
|
|
|
|
# ch = info['ch']
|
|
# ch = 0
|
|
# ip = info['ip']
|
|
# port = info['port']
|
|
# enableDelayVal = info['enableDelayVal']
|
|
# sampleRangeVal = info['sampleRangeVal']
|
|
# avgStepVal = info['avgStepVal']
|
|
|
|
# Default Setup for Test
|
|
ch = 0
|
|
ip= "192.168.0.20"
|
|
port = 5001
|
|
enableDelayVal = 10
|
|
sampleRangeVal = 100
|
|
avgStepVal = 10
|
|
|
|
sdtcloud = sdtcloudpubsub.sdtcloudpubsub()
|
|
mqttClient = sdtcloud.setClient(f"device-app-{uuid.uuid1()}") # parameter is client ID(string)
|
|
|
|
# Run Start
|
|
dts = DTS(ip,port)
|
|
dts.setSystemReset()
|
|
dts.setAvgStart(ch, 0)
|
|
|
|
dts.setAvgEnableDelay(ch, 10 + enableDelayVal)
|
|
dts.setAvgSampleRange(ch, sampleRangeVal)
|
|
dts.setAvgStep(ch, avgStepVal)
|
|
|
|
# Get Data Start
|
|
dts. setAvgStart(ch, 1)
|
|
|
|
dts.setTimerTick(ch, 100_000_000)
|
|
|
|
|
|
while(1):
|
|
print("Run")
|
|
y1 = dts.ReadAdcData(0)
|
|
|
|
print(y1)
|
|
msg = {
|
|
"sensor_data": y1
|
|
}
|
|
sdtcloud.pubMessage(mqttClient, msg)
|
|
time.sleep(1)
|