Skip to content

fix: re-login on network errors + daswetter v4 compatibility#148

Open
JanHoBW wants to merge 1 commit into
pixcept:masterfrom
JanHoBW:fix/reconnect-daswetter-v4
Open

fix: re-login on network errors + daswetter v4 compatibility#148
JanHoBW wants to merge 1 commit into
pixcept:masterfrom
JanHoBW:fix/reconnect-daswetter-v4

Conversation

@JanHoBW

@JanHoBW JanHoBW commented Apr 14, 2026

Copy link
Copy Markdown

Summary

This PR fixes three bugs found by analyzing a production system with recurring 12-hour data gaps in ioBroker history.


Fix 1: Re-login on HTTP 401/403 instead of terminating (plenticore.js)

Problem: Any 401/403 response from the inverter called adapter.terminate(), causing a full adapter restart (~7 seconds downtime) every time the Kostal inverter invalidated the session (e.g. after network interruption or nightly session timeout).

Fix: Clear loginSessionId and call login() directly — polling resumes without any restart.


Fix 2: Re-login on network errors (code=0) instead of silent data loss (plenticore.js)

Problem: When a network error occurred (TCP timeout, connection reset, WiFi repeater disconnect), apiCall() returned code=0. The pollStates() function silently skipped processDataResponse() but kept the polling timer running — the adapter appeared healthy in ioBroker while writing no data for hours.

Observed on a production system: a 30-second WiFi repeater reconnect caused a 12-hour data gap because the adapter never recovered its session.

Fix: On code=0, clear session, wait 15s, trigger fresh login(). A warning log message makes the event visible.


Fix 3: daswetter v4 (2026 API) compatibility (plenticore.js + weather.js)

As reported in #147 — the daswetter adapter v4 changed its object structure completely:

Old (broken) New (v4)
Path NextHours.Location_1.Day_X.Hour_Y.* location_1.ForecastHourly.Hour_Y.*
Rain field rain_value rain
Sky field clouds_value clouds
Time field hour_value time
fc_mode dayhours hours

Updated weatherAdapters config in plenticore.js and replaced the broken Kachelmann rain scraping with a new getRainDataFromDaswetter() function that reads rain data directly from daswetter ioBroker states.

Eliminates the recurring warnings:

warn: Processing rain data failed
warn: Could not process weather data (rain)

Test environment

  • ioBroker js-controller: 7.0.6 / 7.0.7
  • plenticore adapter: 2.3.2
  • daswetter adapter: 4.5.3
  • Node.js: v22.15.0
  • Inverter: Kostal Plenticore Plus
  • Syntax checked: node --check passes on both files

Related issues

Fixes #147 (daswetter v4 compatibility)

Three bug fixes for improved reliability and daswetter v4 support:

**Fix 1: Re-login on HTTP 401/403 instead of terminating (plenticore.js)**
Previously the adapter called adapter.terminate() on any 401/403 response,
causing a 7-second restart cycle every time the Kostal inverter invalidated
the session (e.g. after network interruption or session timeout).
Now the adapter clears the session ID and triggers a fresh login, resuming
polling without any restart.

**Fix 2: Re-login on network errors (code=0) instead of silent data loss (plenticore.js)**
When a network error occurred (TCP timeout, connection reset), apiCall()
returned code=0. The pollStates() function silently skipped processDataResponse()
but kept the polling timer running — resulting in the adapter appearing healthy
while writing no data to ioBroker for hours (observed: 12-hour data gaps).
Now on code=0 the adapter clears the session, waits 15s, and triggers a fresh
login before resuming normal polling. A re-login log message makes the event
visible in the ioBroker log.

**Fix 3: daswetter v4 (2026 API) compatibility (plenticore.js + weather.js)**
The daswetter adapter v4 changed its object structure completely:
- Old paths: NextHours.Location_1.Day_X.Hour_Y.{rain_value,clouds_value,hour_value}
- New paths: location_1.ForecastHourly.Hour_Y.{rain,clouds,time}
The fc_id, field names and fc_mode in the weatherAdapters config are updated
to match the new structure.
The Kachelmann rain scraping (getRainData) is supplemented by a new async
function getRainDataFromDaswetter() that reads rain data directly from daswetter
ioBroker states, eliminating the recurring 'Processing rain data failed' warnings.

Root cause analysis: Fixes 1+2 were identified by analyzing ioBroker history
JSON files on a production system. The 12-hour data gap was triggered by a
WiFi repeater disconnect that caused simultaneous network errors on all devices
behind the repeater. The adapter survived (kept polling) but produced no data.

Tested on: ioBroker js-controller 7.0.6, plenticore adapter 2.3.2,
daswetter adapter 4.5.3, Node.js v22.15.0, Kostal Plenticore Plus
@JanHoBW

JanHoBW commented Apr 14, 2026

Copy link
Copy Markdown
Author

Log examples — before and after the fixes

Before Fix 2 (network error → silent data loss)

The adapter logs nothing abnormal. It keeps running, weather/forecast cycles appear normal — but no inverter data is written to ioBroker states for hours:

10:32:48  info  plenticore.0  Got all internal forecast data and made it available to main process.
10:47:48  info  plenticore.0  got weather data from met.no with 91 elements.
10:47:49  warn  plenticore.0  Processing rain data failed
10:47:49  warn  plenticore.0  Could not process weather data (rain).
11:02:49  info  plenticore.0  got weather data from met.no with 91 elements.
... (12 hours of only weather log entries, zero inverter values)
22:39:33  info  host          stopInstance system.adapter.plenticore.0
22:39:34  info  host          instance terminated with code 11 (ADAPTER_REQUESTED_TERMINATION)
22:39:40  info  host          instance started with pid 1968

The history JSON shows the last value at 10:38:51 — then nothing until the watchdog-triggered restart at 22:39.

After Fix 2 (network error → re-login + resume)

10:38:52  warn  plenticore.0  Processdata request failed: network error (code 0) — triggering re-login in 15s
10:39:07  info  plenticore.0  starting. Version 2.3.2 ...
10:39:08  info  plenticore.0  Re-login after network error successful, resuming polling.
10:39:10  info  plenticore.0  (normal inverter data continues)

Data gap: ~30 seconds instead of 12 hours.


Before Fix 1 (401 → terminate)

22:39:33  info  host          stopInstance system.adapter.plenticore.0
22:39:34  info  plenticore.0  Terminated (ADAPTER_REQUESTED_TERMINATION): Without reason
22:39:40  info  host          instance started with pid 1968
22:39:47  info  plenticore.0  starting. Version 2.3.2 ...

This happened every night when the inverter invalidated its session.

After Fix 1 (401 → re-login in place)

22:39:33  warn  plenticore.0  Session expired or unauthorized (HTTP 401), triggering re-login...
22:39:35  info  plenticore.0  Re-login after 401/403 successful, resuming polling.

No restart, no data gap, no watchdog needed.


Root cause (for context)

The production system has a WiFi repeater between the router and the Kostal inverter. The inverter is connected via LAN cable to the repeater. When the repeater briefly loses its WiFi uplink (DFS channel switch, thermal event, etc.), all devices behind it become unreachable simultaneously — the inverter AND a go-e wallbox both dropped offline at exactly 10:38:51 on 2026-04-13. The 15-second delay before re-login in Fix 2 gives the repeater time to reconnect before the adapter attempts a new session.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

i worked with claude on: Processing rain data failed with exception: Regen --- Could not process weather data (rain).

1 participant