Thanks again, for your input. I already implemented some sort of
#INTERNET-ERROR-HANDLING (tagged the relevant code-parts this way in my script below)
into my script, BUT somehow the Skript won't reconnect to the internet, once the internet is up again...
I wrote many comments for you into my script, so you can have a fast look over it
My infinitly looping script (please don't forget, that I start this script with rc.local):
import time
import sys
import os
import datetime
import plotly
from array import *
# BASICALLY THIS PYTHON SCRIPT (SHALL) INFINITLY
# 1. OPENS THEN READS A LINE OF A datalog.txt-FILE INTO A ARRAY (content: Arduino-Sketch
# generates (and fills) datalog.txt-file constantly every 5-6 sec and writes comma-seperated temperatures
# of sensors into a line of the datalog.txt )
# 2. THEN TRANSFERS THE TEMPERATURES TO A PLOTTING SERVICE (needs to be almost LIVE/max. 20 sec delay)
# 3. THEN DELETES THE datalog.txt AND WAITS FOR MY ARDUINO-SKETCH TO RECREATE THE datalog.txt
#
# AND IF THE INTERNETS SOMEHOW DOWN THE SCRIPT (SHALL) "WAITS" UNTIL INTERNET IS UP AGAIN <<<---- PROBLEM
______
( I cut this part, because its not relevant AT ALL (layout of plots, login-data etc.). I'm sure about this)
______
x = datetime.datetime.now() # DATE AND TIME ARE ESSENTIAL FOR TEMPERATURE-PLOTTING !
print x
responseping = os.system("ping -c 1 google.com") # PING FOR INTERNET-ERROR-HANDLING
# AS LONG AS THERE IS A LINE IN datalog.txt THIS 'WHILE' SHALL READ,
# then TRANSFER TEMP-data, then DELETE datalog.txt then WAIT some sec
while line:
if (responseping == 0): # INTERNET-ERROR-HANDLING-if
if (len(line) > 1): # FILE-LINE-NOT-EMPTY
# nLines = nLines + 1
words = line.split(' ')
if (len(words) == 2):
fields = words[1].split(',')
timeo = fields[0].strip()
temp1 = fields[1].strip()
temp2 = fields[2].strip()
print temp2
dewy = fields[3].strip()
time.sleep( 2 )
x = datetime.datetime.now() # get date/time again (so that time is always correct during the WHILE)
data = [{'x': x, # x-axis is time
'y': temp1, # y-axis is first sensors temperature
'name':'Raum 1',
'type':'scatter',
'marker': {'symbol':'square','color':'blue'}
},
{'x': x,
'y': temp2,
'name':'Raum 2',
'type':'scatter',
'marker':{'color':'purple'}
},
# Testing a second y-axis at the right side of the plot for humidity levels
{'x': x,
"y": [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25],
"yaxis":"y2",
'name':'Feuchtigkeit Raum 3'
}
]
# INTERNET-ERRORHANDLING-AGAIN (if WHILE was already entered the moment that the internet went down):
responseping3 = os.system("ping -c 1 google.com")
if ( responseping3 == 0 ):
response = py.plot(data, filename='Plot-Name' , fileopt='extend', layout=layout)
url = response['url']
# THIS (SHALL) RESTARTS THE SCRIPT IF SOMEHOW INTERNETS DOWN (not sure if it works):
else:
python = sys.executable
os.execl(python, python, * sys.argv)
line = file.readline()
file.close()
# FILE-DELETION AND OPENING AFTER WAITING SOME SEC
if (os.path.isfile("/tmp/datalog.txt")):
os.remove("/tmp/datalog.txt")
time.sleep( 15 )
data_filename = "/tmp/datalog.txt";
file = open(data_filename, 'r')
line = file.readline()
# datalog.txt-FILE-JET-NOT-AVAILABLE-HANDLING:
else:
time.sleep( 7 )
file = open(data_filename, 'r')
line = file.readline()
else: # FILE-LINE-EMPTY
line = file.readline()
# INTERNET-ERROR-HANDLING-else
else:
if (os.path.isfile(data_filename)):
file.close()
time.sleep( 20 )
if (os.path.isfile("/tmp/datalog.txt")):
file = open(data_filename, 'r')
line = file.readline()
# INTERNET-ERROR-HANDLING
responseping = os.system("ping -c 1 google.com")
if (responseping != 0):
python = sys.executable
os.execl(python, python, * sys.argv)
os.remove("/tmp/datalog.txt")
print "While ende" # SHOWS ME IF WHILE SOMEHOW UNINTENTIONALLY ENDS
# END OF MY SCRIPT
Maybe we could somehow make YOUR script return some value, so that my script knows when internet is up or not?!
If internet is not up, my script should be aborted or killed or waiting...and then your script could restart my script? But how do I accomplish this?!
I forgot to mention, that I tried your other solution etc:
- luci-app-multiwan couldn't be found by opkg install... maybe its not available anylonger or its not compatible?
- I installed and tested multiwan but couldn't make it work...actually I broke my entiry connection to the yun and needed to reconfigure everything. In the aftermath I think its not really an option for me, because I can't connect the Yun to 2 ISPs (e.g. LAN to one ISP and Wifi to another ISP)
- I added the missing line to the dhcp-file (the known dhcp issue of openwrt)