Update fup-anemometer-user.py
This commit is contained in:
parent
825c9e4a82
commit
37d1a631f7
@ -39,7 +39,7 @@ debug_args_print = True
|
||||
debug_json_print = True
|
||||
debug_urllib_print = True
|
||||
debug_restart_print = True
|
||||
debug_osc = False
|
||||
info_osc_log = True
|
||||
debug_working_directory = os.path.dirname(os.path.realpath(__file__))
|
||||
|
||||
# OSC Addresses
|
||||
@ -51,7 +51,7 @@ osc_signal_addr = "/env_sensors/anemometer/signal"
|
||||
|
||||
|
||||
# define urllib timeout in seconds
|
||||
url_timeout = 120
|
||||
url_timeout = 20
|
||||
|
||||
# max error number before self restart
|
||||
# max_error_rst = 3
|
||||
@ -65,6 +65,8 @@ def send_osc_message(osc_sender, osc_address, osc_arg):
|
||||
msg = osc_message_builder.OscMessageBuilder(address = osc_address)
|
||||
msg.add_arg(osc_arg)
|
||||
osc_sender.send(msg.build())
|
||||
if info_osc_log:
|
||||
logging.info("OSC datas sent : " + osc_address + " : " + str(osc_arg))
|
||||
|
||||
def main(meteobridge_url, meteobridge_user, meteobridge_passwd, max_host, max_port, errors_restart):
|
||||
|
||||
@ -75,7 +77,7 @@ def main(meteobridge_url, meteobridge_user, meteobridge_passwd, max_host, max_po
|
||||
meteobridge_sensor_req = meteobridge_url + meteobridge_template
|
||||
|
||||
# Logging
|
||||
logging.basicConfig(filename='fup_anemometer.log', encoding='utf-8', format='%(asctime)s-%(levelname)s:%(message)s', datefmt='%Y/%m/%d %H:%M:%S', level=logging.DEBUG)
|
||||
logging.basicConfig(filename='fup_anemometer.log', encoding='utf-8', format='%(asctime)s-%(levelname)s : %(message)s', datefmt='%Y/%m/%d %H:%M:%S', level=logging.DEBUG)
|
||||
logging.info("fup_anemometer started")
|
||||
|
||||
while True:
|
||||
@ -134,9 +136,9 @@ def main(meteobridge_url, meteobridge_user, meteobridge_passwd, max_host, max_po
|
||||
|
||||
except :
|
||||
if debug_urllib_print:
|
||||
print('URL Unknown Error')
|
||||
print('Unknown error on request to : ' + meteobridge_sensor_req)
|
||||
|
||||
logging.error("URL Unknown Error")
|
||||
logging.error("Unknown error on request to : " + meteobridge_sensor_req)
|
||||
error_counter += 1
|
||||
|
||||
else:
|
||||
@ -166,41 +168,16 @@ def main(meteobridge_url, meteobridge_user, meteobridge_passwd, max_host, max_po
|
||||
error_counter = 0
|
||||
|
||||
send_osc_message(oscSender, osc_speed_addr, wind_lastspeed)
|
||||
# msg = osc_message_builder.OscMessageBuilder(address = "/env_sensors/anemometer/speed")
|
||||
# msg.add_arg(wind_lastspeed)
|
||||
# oscSender.send(msg.build())
|
||||
|
||||
send_osc_message(oscSender, osc_battery_addr, wind_batt)
|
||||
# msg = osc_message_builder.OscMessageBuilder(address = "/env_sensors/anemometer/battery")
|
||||
# msg.add_arg(wind_batt)
|
||||
# oscSender.send(msg.build())
|
||||
|
||||
send_osc_message(oscSender, osc_age_addr, wind_age)
|
||||
# msg = osc_message_builder.OscMessageBuilder(address = "/env_sensors/anemometer/age")
|
||||
# msg.add_arg(wind_age)
|
||||
# oscSender.send(msg.build())
|
||||
|
||||
send_osc_message(oscSender, osc_signal_addr, wind_signal)
|
||||
# msg = osc_message_builder.OscMessageBuilder(address = "/env_sensors/anemometer/signal")
|
||||
# msg.add_arg(wind_signal)
|
||||
# oscSender.send(msg.build())
|
||||
|
||||
send_osc_message(oscSender, osc_error_addr, OSC_no_error)
|
||||
# msg = osc_message_builder.OscMessageBuilder(address = "/env_sensors/anemometer/error")
|
||||
# msg.add_arg(OSC_no_error)
|
||||
# oscSender.send(msg.build())
|
||||
|
||||
if debug_osc:
|
||||
logging.debug("OSC datas sent")
|
||||
# Sleep 2 seconds if no errors
|
||||
time.sleep(2)
|
||||
|
||||
# Self restart
|
||||
if error_counter >= errors_restart:
|
||||
send_osc_message(oscSender, osc_error_addr, OSC_meteobridge_restart)
|
||||
# msg = osc_message_builder.OscMessageBuilder(address = "/env_sensors/anemometer/error")
|
||||
# msg.add_arg(OSC_meteobridge_restart)
|
||||
# oscSender.send(msg.build())
|
||||
time.sleep(1)
|
||||
if debug_restart_print:
|
||||
print("Current errors count : " + str(error_counter) + " / " + errors_restart + " max errors")
|
||||
|
Loading…
Reference in New Issue
Block a user