Skip to content
Snippets Groups Projects
Commit a9bf7826 authored by Robert Piotrowski's avatar Robert Piotrowski
Browse files

Fix to new format for swissvault

parent c687ac2b
Branches
No related merge requests found
......@@ -14,18 +14,18 @@ valid_chars = list(range(13, 25)) + [37, 38] # From 13 to 24 and 37, 38
with open("sim_data.txt", "w") as file:
for _ in range(num_lines):
# Generate random values for fields
rssi = random.randint(-92, -45) # RSSI value between -92 and -45
rssi = random.randint(45, 92) # RSSI value between -92 and -45
char = random.choice(valid_chars) # Randomly choose from valid char values
channel = random.randint(37, 39) # Channel value between 37 and 39
tx_power = 8 # Fixed tx_power value
temp = random.randint(0, 1800) # Temperature value between 0 and 1800
pH = random.randint(0, 1800) # pH value between 0 and 1800
pHRaw = pH/10 # pH value between 0 and 1800
battery = random.randint(0, 1800) # pH value between 0 and 1800
temp = int(random.randint(0, 4095)) # Temperature value between 0 and 1800
pH = int(random.randint(0, 4095)) # pH value between 0 and 1800
pHRaw = int(pH/8) # pH value between 0 and 1800
battery = int(random.randint(0, 4095)) # pH value between 0 and 1800
# Format the line according to the InfluxDB requirements
line = (f"bssensor,espar_t=49bd40cdfcab,beacon_t=c00000000003 "
line = (f"dongle_t=c000d0009,beacon_t=c000beac0004 "
f"rssi={rssi},char={char},channel={channel},tx_power={tx_power},"
f"temp={temp},pH={pH},pHRaw={pHRaw},battery={battery},timestamp={timestamp}\n")
f"temp={temp},pH={pH},pHRaw={pHRaw},battery={battery},timestamp=\n")
# Write the line to the file
file.write(line)
......
......@@ -4,7 +4,6 @@ import paho.mqtt.client as mqtt
import time
import argparse
import yaml
# Load default configuration from YAML file
def load_config(file_path="config.yaml"):
with open(file_path, 'r') as file:
......@@ -39,7 +38,7 @@ def main(serial_port=None, baud_rate=115200, file_path="sim_data.txt", mqtt_brok
print(f"Received from serial port: {line}")
# Send data to MQTT
client.publish(mqtt_topic, line)
client.publish(mqtt_topic, line.split(",",1)[1])
print(f"Sent to MQTT: {line}")
time.sleep(0.1) # Short delay
......@@ -54,13 +53,15 @@ def main(serial_port=None, baud_rate=115200, file_path="sim_data.txt", mqtt_brok
else:
# If no serial port is provided, send lines from the file cyclically
file_reader = cyclic_file_reader(file_path)
cnt=0
try:
while True:
# Get the next line from the file
line = next(file_reader)
client.publish(mqtt_topic, line)
print(f"Sent to MQTT: {line}")
cnt = cnt +1
msg=line+str(cnt)
client.publish(msg)
print(f"Sent to MQTT broker={mqtt_broker} in topic={mqtt_topic} msg={msg}")
time.sleep(sim_interval) # Use interval from YAML config
except KeyboardInterrupt:
......
This diff is collapsed.
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment