error in try routine

master
ademant 2019-06-03 15:43:48 +02:00
parent 7b94fef947
commit 80b00a0efc
2 changed files with 10 additions and 1 deletions

6
simple_wrapper.sh Executable file
View File

@ -0,0 +1,6 @@
#!/bin/sh
while [ /bin/true ]; do
python /home/pi/rasolar/tri.py
sleep 5
done

5
tri.py
View File

@ -97,7 +97,7 @@ while a > 1:
ch_val[channel_names.index("pressure")]=int(1000*bme_data.pressure) # Pressure
ch_val[channel_names.index("humidity")]=int(1000*bme_data.humidity) # Humidity
timefile=round(timestamp/3600)
timefile=round(timestamp/3600000)
f1=open("/home/pi/log/data_{:d}.txt".format(int(timefile)),"a")
payload={}
for i in range(len(ch_val)):
@ -110,6 +110,9 @@ while a > 1:
json_out={"time": ch_val[channel_names.index("time")],"device": "rasolar","payload":payload}
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except:
print("{}: could not connect to database".format(time.time()))
else:
s.connect((HOST, PORT))
s.sendall(json.dumps(json_out))
s.close()