Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DAQ: Add decoder for Fine Offset (FOSHK) weather station equipment #125

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
DAQ: Mask PASSKEY variable coming from HTTP, emitted by Ecowitt
amotl committed Mar 2, 2023
commit 6ff6922c6ec241c9f03989c40901d35d82f33ce3
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ in progress
Other types will make the panel croak like ``InfluxDB Error: unsupported
mean iterator type: *query.stringInterruptIterator`` or ``InfluxDB Error:
not executed``.
- DAQ: Mask ``PASSKEY`` variable coming from HTTP, emitted by Ecowitt


.. _kotori-0.27.0:
10 changes: 9 additions & 1 deletion kotori/io/protocol/http.py
Original file line number Diff line number Diff line change
@@ -328,7 +328,15 @@ def read_request(self, bucket):

# Data acquisition uses HTTP POST
if request.method == 'POST':
return self.data_acquisition(bucket)
data = self.data_acquisition(bucket)

# Mask `PASSKEY` ingress variable.
# https://github.com/daq-tools/kotori/discussions/122
# https://community.hiveeyes.org/t/ecowitt-wunderground-api-fur-weather-hiveeyes-org-nutzbar/4735
if "PASSKEY" in data:
del data["PASSKEY"]

return data

def data_acquisition(self, bucket):

88 changes: 88 additions & 0 deletions test/test_ecowitt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import json
from test.settings.mqttkit import PROCESS_DELAY_HTTP, influx_sensors, settings
from test.util import http_form_sensor, sleep

import pytest
import pytest_twisted
from twisted.internet import threads


@pytest_twisted.inlineCallbacks
@pytest.mark.http
def test_ecowitt_post(machinery, create_influxdb, reset_influxdb):
"""
Submit single reading in ``x-www-form-urlencoded`` format to HTTP API
and proof it is stored in the InfluxDB database.
"""

# Submit a single measurement, without timestamp.
data = {
"PASSKEY": "B950C...[obliterated]",
"stationtype": "EasyWeatherPro_V5.0.6",
"runtime": "456128",
"dateutc": "2023-02-20 16:02:19",
"tempinf": "69.8",
"humidityin": "47",
"baromrelin": "29.713",
"baromabsin": "29.713",
"tempf": "48.4",
"humidity": "80",
"winddir": "108",
"windspeedmph": "1.12",
"windgustmph": "4.92",
"maxdailygust": "12.97",
"solarradiation": "1.89",
"uv": "0",
"rainratein": "0.000",
"eventrainin": "0.000",
"hourlyrainin": "0.000",
"dailyrainin": "0.028",
"weeklyrainin": "0.098",
"monthlyrainin": "0.909",
"yearlyrainin": "0.909",
"temp1f": "45.0",
"humidity1": "90",
"soilmoisture1": "46",
"soilmoisture2": "53",
"tf_ch1": "41.9",
"rrain_piezo": "0.000",
"erain_piezo": "0.000",
"hrain_piezo": "0.000",
"drain_piezo": "0.028",
"wrain_piezo": "0.043",
"mrain_piezo": "0.492",
"yrain_piezo": "0.492",
"wh65batt": "0",
"wh25batt": "0",
"batt1": "0",
"soilbatt1": "1.6",
"soilbatt2": "1.6",
"tf_batt1": "1.60",
"wh90batt": "3.04",
"freq": "868M",
"model": "HP1000SE-PRO_Pro_V1.8.5",
}
deferred = threads.deferToThread(http_form_sensor, settings.channel_path_data, data)
yield deferred

# Check response.
response = deferred.result
assert response.status_code == 200
assert response.content == json.dumps(
[{"type": "info", "message": "Received #1 readings"}], indent=4
).encode("utf-8")

# Wait for some time to process the message.
yield sleep(PROCESS_DELAY_HTTP)

# Proof that data arrived in InfluxDB.
record = influx_sensors.get_first_record()

assert record["tempf"] == 48.4
assert record["humidity"] == 80.0
assert record["model"] == "HP1000SE-PRO_Pro_V1.8.5"

# Make sure this will not be public.
assert "PASSKEY" not in record

yield record