disable debug
This commit is contained in:
parent
97aa7ce8e1
commit
482b6b28e5
@ -1,3 +1,4 @@
|
|||||||
|
#/bin/python
|
||||||
import socket
|
import socket
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
@ -9,7 +10,7 @@ def parse_to_graphite(data, root='rc.bms', timestamp=None):
|
|||||||
if not timestamp:
|
if not timestamp:
|
||||||
timestamp = int(time.time())
|
timestamp = int(time.time())
|
||||||
results = []
|
results = []
|
||||||
|
|
||||||
lines = data.strip().split('\n')
|
lines = data.strip().split('\n')
|
||||||
for line in lines:
|
for line in lines:
|
||||||
if line.startswith('BMS'):
|
if line.startswith('BMS'):
|
||||||
@ -36,7 +37,7 @@ def send_to_graphite(data, host='10.6.0.1', port=2003):
|
|||||||
while data:
|
while data:
|
||||||
message = data.popleft()
|
message = data.popleft()
|
||||||
sock.sendall(message.encode('utf-8'))
|
sock.sendall(message.encode('utf-8'))
|
||||||
print(f"Sent to Graphite: {message.strip()}")
|
#print(f"Sent to Graphite: {message.strip()}")
|
||||||
except (socket.error, socket.timeout) as e:
|
except (socket.error, socket.timeout) as e:
|
||||||
print(f"Failed to send data, will drop if buffer is full. Error: {e}", file=sys.stderr)
|
print(f"Failed to send data, will drop if buffer is full. Error: {e}", file=sys.stderr)
|
||||||
|
|
||||||
@ -50,18 +51,18 @@ def main():
|
|||||||
if select.select([ser], [], [], 0)[0]: # Check if there is data to read
|
if select.select([ser], [], [], 0)[0]: # Check if there is data to read
|
||||||
line = ser.readline().decode('utf-8').strip()
|
line = ser.readline().decode('utf-8').strip()
|
||||||
if line:
|
if line:
|
||||||
print(f"Raw Input: {line}") # Output raw line to screen
|
print(f"{line}") # Output raw line to screen
|
||||||
graphite_data = parse_to_graphite(line)
|
graphite_data = parse_to_graphite(line)
|
||||||
for data in graphite_data:
|
for data in graphite_data:
|
||||||
if len(data_buffer) < data_buffer.maxlen:
|
if len(data_buffer) < data_buffer.maxlen:
|
||||||
data_buffer.append(data + '\n')
|
data_buffer.append(data + '\n')
|
||||||
print(f"Added to buffer: {data.strip()}")
|
#print(f"Added to buffer: {data.strip()}")
|
||||||
else:
|
else:
|
||||||
print("Buffer full, dropping data", file=sys.stderr)
|
print("Buffer full, dropping data", file=sys.stderr)
|
||||||
|
|
||||||
# Try to send data if the buffer is not empty
|
# Try to send data if the buffer is not empty
|
||||||
if data_buffer:
|
if data_buffer:
|
||||||
print("Attempting to send data to Graphite...")
|
#print("Attempting to send data to Graphite...")
|
||||||
send_to_graphite(data_buffer)
|
send_to_graphite(data_buffer)
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
Loading…
Reference in New Issue
Block a user