Update fup-anemomoter-user.py
Remove unused debug var : debug_p & debug_flag Add debug var : debug_json Check if http authentification is true
This commit is contained in:
parent
aaddd30df5
commit
b53a7b615b
@ -21,10 +21,8 @@ import json
|
||||
# import argparse
|
||||
import argparse
|
||||
|
||||
debug_p = False
|
||||
|
||||
debug_flag = True
|
||||
debug_args = True
|
||||
debug_json = True
|
||||
debug_working_directory = os.path.dirname(os.path.realpath(__file__))
|
||||
|
||||
prod_flag = False
|
||||
@ -34,8 +32,14 @@ meteobridge_template = "cgi-bin/template.cgi?template={%22time%22:%22[DD][MM][YY
|
||||
|
||||
def main(meteobridge_url, meteobridge_user, meteobridge_passwd, max_host, max_port):
|
||||
|
||||
http_auth_status = False
|
||||
|
||||
oscSender = udp_client.UDPClient(max_host, max_port)
|
||||
|
||||
meteobridge_sensor_req = meteobridge_url + meteobridge_template
|
||||
|
||||
while True:
|
||||
if http_auth_status == False:
|
||||
# http log to meteobridge
|
||||
passman = urllib.request.HTTPPasswordMgrWithDefaultRealm()
|
||||
passman.add_password(None, meteobridge_url, meteobridge_user, meteobridge_passwd)
|
||||
@ -57,31 +61,29 @@ def main(meteobridge_url, meteobridge_user, meteobridge_passwd, max_host, max_po
|
||||
else:
|
||||
res_body = res.read()
|
||||
print(res_body.decode('utf-8'))
|
||||
http_auth_status = True
|
||||
|
||||
|
||||
meteobridge_sensor_req = meteobridge_url + meteobridge_template
|
||||
|
||||
while True:
|
||||
# logger.debug("this is a DEBUG message")
|
||||
# logger.info("this is an INFO message")
|
||||
# logger.error("this is an ERROR message")
|
||||
|
||||
# store the response of URL
|
||||
else:
|
||||
try:
|
||||
response = urllib.request.urlopen(meteobridge_sensor_req)
|
||||
|
||||
except urllib.error.HTTPError as e:
|
||||
print('HTTP Error code: ', e.code)
|
||||
raise SystemExit(e)
|
||||
msg = osc_message_builder.OscMessageBuilder(address = "/env_sensors/anemometer/error")
|
||||
msg.add_arg(1)
|
||||
oscSender.send(msg.build())
|
||||
|
||||
except urllib.error.URLError as e:
|
||||
print('URL Error Reason: ', e.reason)
|
||||
raise SystemExit(e)
|
||||
msg = osc_message_builder.OscMessageBuilder(address = "/env_sensors/anemometer/error")
|
||||
msg.add_arg(1)
|
||||
oscSender.send(msg.build())
|
||||
|
||||
# storing the JSON response
|
||||
# from url in data
|
||||
try:
|
||||
data_json = json.loads(response.read())
|
||||
if debug_json == True:
|
||||
print(data_json)
|
||||
wind_speed = float(data_json["speed"])
|
||||
wind_lastspeed = float(data_json["lastspeed"])
|
||||
|
Loading…
Reference in New Issue
Block a user