Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ The `hub-server` will automatically log the detected version at the `INFO` level
|----------------------------|-----------------------------------------------------------|-----------------------------|
| `TZ` | Timezone (e.g., `Australia/Brisbane`) | `Australia/Brisbane` |
| `LOG_LEVEL` | Logging verbosity (`DEBUG`, `INFO`, `WARN`, `ERROR`) | `INFO` |
| `TELEMETRY_ENABLED` | Record unknown packets to help aid reverse engineering. | `true` |
| `MAINS_VOLTAGE` | Local mains voltage (e.g., `230` for AU/UK, `120` for US) | `230` |
| `POWER_FACTOR` | Power factor (H1/H2 use `0.6`, H3 uses `1.0`) | `0.6` |
| `HISTORY_RETENTION_MONTHS` | How many months of data to keep (`0` = keep everything) | `0` |
Expand Down
3 changes: 0 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ services:
TZ: Australia/Brisbane
# Logging
LOG_LEVEL: INFO
# Telemetry, unknown packets are recorded to further reverse engineering.
# You may disable this by setting TELEMETRY_ENABLED to false
TELEMETRY_ENABLED: true
# Common voltages AU,UK = 230 | US = 120 https://en.wikipedia.org/wiki/Mains_electricity_by_country
MAINS_VOLTAGE: 230
# H1 and H2 devices used a power factor of 0.6, H3 uses 1.0
Expand Down
5 changes: 0 additions & 5 deletions hub-server/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@
# Logging level, values are DEBUG, INFO, WARN, ERROR, CRITICAL
LOG_LEVEL = os.getenv("LOG_LEVEL", "INFO").upper()

# Telemetry, unknown packets are recorded to further reverse engineering.
# You may disable this by setting TELEMETRY_ENABLED to false
TELEMETRY_ENABLED = os.getenv("TELEMETRY_ENABLED", "true").lower() in ("true", "1", "yes", "on")
TELEMETRY_URL = os.getenv("TELEMETRY_URL", "https://docs.google.com/forms/d/e/1FAIpQLSf4fOvc65H3a9ZbgZ8e8NGvq8tYPOs0bBn5aAqWrugeg5Jqsw/formResponse")

# SQL timeout in seconds
SQLITE_TIMEOUT = float(os.getenv("SQLITE_TIMEOUT", "5.0"))
SQLITE_RETRIES = int(os.getenv("SQLITE_RETRIES", "5"))
Expand Down
29 changes: 1 addition & 28 deletions hub-server/hub_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
This server emulates the sensornet.info API endpoints for an
Efergy hub, logging incoming sensor data to a sqlite database.
"""
import json
import logging
import socket
import sys
import requests
from http.server import HTTPServer, SimpleHTTPRequestHandler
from typing import Type
from urllib.parse import urlparse, parse_qs
Expand All @@ -23,7 +21,7 @@
SERVER_PORT, LOG_LEVEL, MQTT_ENABLED, HA_DISCOVERY, ENERGY_MONTHLY_RESET, HISTORY_RETENTION_MONTHS, SQLITE_TIMEOUT,
SQLITE_RETRIES, SQLITE_RETRY_DELAY, POWER_VALUE_TEMPLATE_H1, POWER_UNIT_OF_MEASUREMENT_H1, POWER_VALUE_TEMPLATE_H2,
POWER_UNIT_OF_MEASUREMENT_H2, POWER_VALUE_TEMPLATE_H3, POWER_UNIT_OF_MEASUREMENT_H3, ENERGY_VALUE_TEMPLATE,
ENERGY_UNIT_OF_MEASUREMENT, TELEMETRY_ENABLED, TELEMETRY_URL
ENERGY_UNIT_OF_MEASUREMENT
)

class EfergyHTTPServer(HTTPServer):
Expand Down Expand Up @@ -104,8 +102,6 @@ def _handle_unknown_packet(self, post_data_bytes: bytes = None):
path = self.path
content_length = int(self.headers.get("Content-Length", 0))
content_type = self.headers.get("Content-Type", "")
body_utf8 = "No request body present"
body_hex = ""

if post_data_bytes is None and content_length > 0:
post_data_bytes = self.rfile.read(content_length)
Expand Down Expand Up @@ -136,28 +132,6 @@ def _handle_unknown_packet(self, post_data_bytes: bytes = None):
logging.warning("Payload HEX:\n%s", body_hex)

logging.warning("====================================")

if TELEMETRY_ENABLED:
payload = {
"entry.712651641": str(method),
"entry.647193072": str(path),
"entry.718643403": str(parsed_url.path),
"entry.628690130": json.dumps(query, ensure_ascii=False),
"entry.744795787": str(content_type),
"entry.2143045526": str(content_length),
"entry.311956051": json.dumps(dict(self.headers), ensure_ascii=False),
"entry.1917117670": body_utf8,
"entry.2020488076": body_hex,
}

logging.warning("Submitting telemetry for unknown packet")
response = requests.post(TELEMETRY_URL, data=payload, timeout=5)
if response.status_code == 200:
logging.warning("Telemetry submission successful")
else:
logging.warning(f"Failed to submit Telemetry: {response.status_code}")

logging.warning("====================================")
except Exception:
logging.exception("Error in unknown HTTP handler")
if not self.wfile.closed:
Expand Down Expand Up @@ -383,7 +357,6 @@ def run_server(database: Database, host: str = '0.0.0.0', port: int = 5000):
logging.info(f" Python: {sys.version.split()[0]}")
logging.info(f" Port: {SERVER_PORT}")
logging.info(f" Logging level: {LOG_LEVEL}")
logging.info(f" Telemetry enabled: {TELEMETRY_ENABLED}")
logging.info(f" MQTT: {'enabled' if MQTT_ENABLED else 'disabled'}")
logging.info(f" HA discovery: {'enabled' if HA_DISCOVERY else 'disabled'}")
logging.info(f" Monthly reset: {ENERGY_MONTHLY_RESET}")
Expand Down
3 changes: 1 addition & 2 deletions hub-server/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
paho-mqtt >= 2.1.0
pytest >= 8.4.1
pytest-cov >= 7.0.0
requests >= 2.32.5
pytest-cov >= 7.0.0
3 changes: 1 addition & 2 deletions hub-server/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
paho-mqtt >= 2.1.0
requests >= 2.32.5
paho-mqtt >= 2.1.0
4 changes: 1 addition & 3 deletions hub-server/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import os

# Set environment variables for tests before any other modules are imported
os.environ["TELEMETRY_ENABLED"] = "false"
os.environ["TELEMETRY_URL"] = ""
# Set environment variables for tests before any other modules are imported
Loading