From b8e48e8a40e004ff1efdf481c2914190d1dc2800 Mon Sep 17 00:00:00 2001 From: "Jason A. Cox" Date: Sun, 26 Feb 2023 21:03:37 -0800 Subject: [PATCH] Add URL for Influx 2.x support --- weather/README.md | 10 ++++++++-- weather/server.py | 16 +++++++++++++--- weather/weather411.conf.sample | 3 ++- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/weather/README.md b/weather/README.md index 69b0fb6e..d165bcf7 100644 --- a/weather/README.md +++ b/weather/README.md @@ -16,7 +16,6 @@ Docker: docker pull [jasonacox/weather411](https://hub.docker.com/r/jasonacox/we ## Quick Start - 1. Create a `weather411.conf` file (`cp weather411.conf.sample weather411.conf`) and update with your specific location details: * Enter your OpenWeatherMap API Key (APIKEY) You can get a free account and key at [OpenWeatherMap.org](https://openweathermap.org/). @@ -52,6 +51,13 @@ Docker: docker pull [jasonacox/weather411](https://hub.docker.com/r/jasonacox/we # Leave blank if not used USERNAME = PASSWORD = + # Auth - Leave blank if not used + USERNAME = + PASSWORD = + # Influx 2.x - Leave blank if not used + TOKEN = + ORG = + URL = ``` 2. Run the Docker Container to listen on port 8676. @@ -143,7 +149,7 @@ docker start weather411 ### 0.2.0 - Upgrade InfluxDB Client -* Upgrade end of life `influxdb` client library to `influxdb-client` (refer discussion #191 and issue #195) +* Upgrade end of life `influxdb` client library to `influxdb-client` (refer discussion #191 and issue #195), providing support for InfluxDB 1.8 and 2.x. ### 0.1.2 - Snow and Rain Data diff --git a/weather/server.py b/weather/server.py index f38e4b16..efc4e7a8 100644 --- a/weather/server.py +++ b/weather/server.py @@ -43,6 +43,13 @@ PORT = 8086 DB = powerwall FIELD = weather + # Auth - Leave blank if not used + USERNAME = + PASSWORD = + # Auth - Influx 2.x - Leave blank if not used + TOKEN = + ORG = + URL = ENVIRONMENTAL: WEATHERCONF = "Path to weather411.conf file" @@ -114,7 +121,10 @@ # Check for InfluxDB 2.x settings ITOKEN = config.get('InfluxDB', 'TOKEN', fallback="") IORG = config.get('InfluxDB', 'ORG', fallback="") + IURL = config.get('InfluxDB', 'URL', fallback="") + if ITOKEN != "" and IURL == "": + IURL = "http://%s:%s" % (IHOST, IPORT) else: # No config file - Display Error sys.stderr.write("Weather411 Server %s\nERROR: No config file. Fix and restart.\n" % BUILD) @@ -266,7 +276,7 @@ def fetchWeather(): else : # Influx 2.x client = InfluxDBClient( - url="http://%s:%s" % (IHOST,IPORT), + url=IURL, token=ITOKEN, org=IORG) output = [{}] @@ -430,8 +440,8 @@ def api(port): sys.stderr.write(" + InfluxDB - Enable: %s, Host: %s, Port: %s, DB: %s, Field: %s\n" % (INFLUX, IHOST, IPORT, IDB, IFIELD)) if ITOKEN != "" or IORG != "": - sys.stderr.write(" + InfluxDB - Org: %s, Token: %s\n" - % (IORG, ITOKEN)) + sys.stderr.write(" + InfluxDB - URL: %s, Org: %s, Token: %s\n" + % (IURL, IORG, ITOKEN)) # Start threads sys.stderr.write("* Starting threads\n") diff --git a/weather/weather411.conf.sample b/weather/weather411.conf.sample index 106a96f0..a8affd87 100644 --- a/weather/weather411.conf.sample +++ b/weather/weather411.conf.sample @@ -27,7 +27,8 @@ FIELD = weather # Auth - Leave blank if not used USERNAME = PASSWORD = -# Auth - Influx 2.x - Leave blank if not used +# Influx 2.x - Leave blank if not used TOKEN = ORG = +URL =