Devel version
This commit is contained in:
parent
5590713619
commit
aaddd30df5
@ -1,5 +1,4 @@
|
||||
{
|
||||
"sensor": "anemometer",
|
||||
"time": 1351824120,
|
||||
"speed": 27.10,
|
||||
"error": false
|
||||
|
139
fup-anemomoter-user.py
Normal file
139
fup-anemomoter-user.py
Normal file
@ -0,0 +1,139 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
OSC/Random Example: send random numbers to OSC.
|
||||
|
||||
This example sends a pseudo-random number between 0 and 1024
|
||||
to the OSC receiver on UDP port 2222.
|
||||
"""
|
||||
from pythonosc import udp_client
|
||||
from pythonosc import osc_message_builder
|
||||
import time
|
||||
import os
|
||||
import time
|
||||
|
||||
# import urllib library
|
||||
import urllib.request
|
||||
import urllib.error
|
||||
|
||||
# import json
|
||||
import json
|
||||
|
||||
# import argparse
|
||||
import argparse
|
||||
|
||||
debug_p = False
|
||||
|
||||
debug_flag = True
|
||||
debug_args = True
|
||||
debug_working_directory = os.path.dirname(os.path.realpath(__file__))
|
||||
|
||||
prod_flag = False
|
||||
prod_working_directory = "/usr/local/com.fup.anemometre_daemon"
|
||||
|
||||
meteobridge_template = "cgi-bin/template.cgi?template={%22time%22:%22[DD][MM][YYYY][hh][mm][ss]%22,%22speed%22:[wind0wind-act],%22lastspeed%22:[wind0wind-lastval],%22battery%22:[wind0lowbat-act.0],%22wind-age%22:[wind0wind-age],%22signal%22:[wind0signal-act.0]}"
|
||||
|
||||
def main(meteobridge_url, meteobridge_user, meteobridge_passwd, max_host, max_port):
|
||||
|
||||
oscSender = udp_client.UDPClient(max_host, max_port)
|
||||
|
||||
# http log to meteobridge
|
||||
passman = urllib.request.HTTPPasswordMgrWithDefaultRealm()
|
||||
passman.add_password(None, meteobridge_url, meteobridge_user, meteobridge_passwd)
|
||||
authhandler = urllib.request.HTTPBasicAuthHandler(passman)
|
||||
opener = urllib.request.build_opener(authhandler)
|
||||
urllib.request.install_opener(opener)
|
||||
|
||||
try:
|
||||
res = urllib.request.urlopen(meteobridge_url)
|
||||
|
||||
except urllib.error.HTTPError as e:
|
||||
print('HTTP Error code: ', e.code)
|
||||
raise SystemExit(e)
|
||||
|
||||
except urllib.error.URLError as e:
|
||||
print('URL Error Reason: ', e.reason)
|
||||
raise SystemExit(e)
|
||||
|
||||
else:
|
||||
res_body = res.read()
|
||||
print(res_body.decode('utf-8'))
|
||||
|
||||
|
||||
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
|
||||
try:
|
||||
response = urllib.request.urlopen(meteobridge_sensor_req)
|
||||
|
||||
except urllib.error.HTTPError as e:
|
||||
print('HTTP Error code: ', e.code)
|
||||
raise SystemExit(e)
|
||||
|
||||
except urllib.error.URLError as e:
|
||||
print('URL Error Reason: ', e.reason)
|
||||
raise SystemExit(e)
|
||||
|
||||
# storing the JSON response
|
||||
# from url in data
|
||||
try:
|
||||
data_json = json.loads(response.read())
|
||||
print(data_json)
|
||||
wind_speed = float(data_json["speed"])
|
||||
wind_lastspeed = float(data_json["lastspeed"])
|
||||
wind_batt = int(data_json["battery"])
|
||||
wind_age = int(data_json["wind-age"])
|
||||
wind_signal = int(data_json["signal"])
|
||||
|
||||
except json.JSONDecodeError as e:
|
||||
print("Invalid JSON syntax:", e)
|
||||
msg = osc_message_builder.OscMessageBuilder(address = "/env_sensors/anemometer/error")
|
||||
msg.add_arg(1)
|
||||
oscSender.send(msg.build())
|
||||
# print the json response
|
||||
# print(data_json)
|
||||
else:
|
||||
msg = osc_message_builder.OscMessageBuilder(address = "/env_sensors/anemometer/speed")
|
||||
msg.add_arg(wind_lastspeed)
|
||||
oscSender.send(msg.build())
|
||||
|
||||
msg = osc_message_builder.OscMessageBuilder(address = "/env_sensors/anemometer/battery")
|
||||
msg.add_arg(wind_batt)
|
||||
oscSender.send(msg.build())
|
||||
|
||||
msg = osc_message_builder.OscMessageBuilder(address = "/env_sensors/anemometer/age")
|
||||
msg.add_arg(wind_age)
|
||||
oscSender.send(msg.build())
|
||||
|
||||
msg = osc_message_builder.OscMessageBuilder(address = "/env_sensors/anemometer/signal")
|
||||
msg.add_arg(wind_signal)
|
||||
oscSender.send(msg.build())
|
||||
|
||||
msg = osc_message_builder.OscMessageBuilder(address = "/env_sensors/anemometer/error")
|
||||
msg.add_arg(0)
|
||||
oscSender.send(msg.build())
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description="FUP anemometer for OSC")
|
||||
parser.add_argument('-url', '--url-meteobridge', default='http://192.168.0.39/')
|
||||
parser.add_argument('-u', '--user-meteobridge', default='meteobridge')
|
||||
parser.add_argument('-p', '--passwd-meteobridge',default='meteobridge')
|
||||
parser.add_argument('-mh', '--max-host', default='localhost')
|
||||
parser.add_argument('-mp','--max-port', default=2222)
|
||||
args = parser.parse_args()
|
||||
|
||||
# if debug_args is True, print arguments
|
||||
if debug_args:
|
||||
print('Meteobridge URL:', args.url_meteobridge)
|
||||
print('Meteobridge User:', args.user_meteobridge)
|
||||
print('Meteobridge Password:', args.passwd_meteobridge)
|
||||
print('OSC host:', args.max_host)
|
||||
print('OSC port:', args.max_port)
|
||||
|
||||
main(meteobridge_url=args.url_meteobridge, meteobridge_user=args.user_meteobridge, meteobridge_passwd=args.passwd_meteobridge, max_host=args.max_host, max_port=args.max_port)
|
@ -1,68 +1,14 @@
|
||||
2024-06-11 23:54:51,982 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-11 23:54:56,988 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-11 23:55:01,994 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-11 23:55:07,001 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-11 23:55:12,008 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-11 23:55:17,014 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-11 23:55:22,021 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-11 23:55:27,028 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-11 23:55:32,031 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-11 23:55:37,035 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-11 23:55:42,042 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-11 23:55:47,048 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-11 23:55:52,053 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-11 23:55:57,058 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-11 23:56:02,063 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-11 23:56:07,068 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-11 23:56:12,076 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-11 23:56:17,083 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-11 23:56:22,089 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:03:17,954 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:03:22,956 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:03:27,962 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:03:32,967 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:03:37,973 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:03:42,979 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:03:47,985 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:03:52,992 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:03:57,998 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:04:03,004 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:04:08,008 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:04:13,013 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:04:18,018 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:04:23,023 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:04:28,027 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:04:33,033 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:04:38,038 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:04:43,043 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:04:48,047 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:04:53,052 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:04:58,057 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:05:03,063 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:05:08,069 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:05:13,075 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:05:18,080 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:05:23,087 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:05:28,091 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:05:33,097 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:05:38,104 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:05:43,111 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:05:48,116 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:05:53,121 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:05:58,127 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:06:03,133 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:06:08,139 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:06:13,145 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:06:18,151 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:06:23,157 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:06:28,162 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:06:33,168 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:09:05,006 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:09:10,011 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:09:15,017 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:09:20,024 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:09:25,030 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:09:30,036 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:09:35,043 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:09:40,049 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:09:45,055 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:56:38,580 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:56:43,585 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:56:48,590 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:56:53,596 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:56:58,601 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:57:03,606 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:57:08,613 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:57:13,620 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:57:18,627 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:57:23,633 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:57:28,640 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:57:33,647 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:57:38,654 - fup_anemo_daemon - INFO - 27.1
|
||||
2024-06-12 00:57:43,660 - fup_anemo_daemon - INFO - 27.1
|
||||
|
13
url_test.txt
Normal file
13
url_test.txt
Normal file
@ -0,0 +1,13 @@
|
||||
http://ip-of-meteobridge/cgi-bin/template.cgi?template=
|
||||
{
|
||||
"time": "[DD][MM][YYYY][hh][mm]",
|
||||
"speed": [wind0wind]
|
||||
}
|
||||
|
||||
http://192.168.0.39/cgi-bin/template.cgi?template={"time":"[DD][MM][YYYY][hh][mm][ss]","speed":[wind0wind-act],"battery":[wind0lowbat-act.0],"wind-age":[wind0wind-age],"signal":[wind0signal-act.0]}
|
||||
|
||||
http://192.168.0.39/cgi-bin/template.cgi?template=[DD].[MM].[YY]+[HH]:[mm]:[ss][APM]%0D[wind0wind-act]%BAC%0d[th0hum-act]%25&contenttype=application/json;charset=iso-8859-1 #new\n#clearall\n*clearloop\n#font 6x12\n#if#{*[wind0wind-age:999]>300*}#then##string 0 24 WIND --#else##string 0 24 WIND [wind0wind-age:--]s\n#string 80 24 [wind0signal-act.0:--]db#fi#
|
||||
|
||||
#new\n#clearall\n*clearloop\n#font 6x12\n#if#{*[wind0wind-age:999]>300*}#then##string 0 24 WIND --#else##string 0 24 WIND [wind0wind-age:--]s\n#string 80 24 [wind0signal-act.0:--]db#fi#\n#show
|
||||
|
||||
{'time': '190620240005', 'speed': 0.0, 'battery': 0, 'wind-age': 3, 'signal': -57}
|
Loading…
Reference in New Issue
Block a user