fix: re-login on network errors + daswetter v4 compatibility#148
fix: re-login on network errors + daswetter v4 compatibility#148JanHoBW wants to merge 1 commit into
Conversation
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
Log examples — before and after the fixesBefore 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: The history JSON shows the last value at After Fix 2 (network error → re-login + resume)Data gap: ~30 seconds instead of 12 hours. Before Fix 1 (401 → terminate)This happened every night when the inverter invalidated its session. After Fix 1 (401 → re-login in place)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 |
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/403response from the inverter calledadapter.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
loginSessionIdand calllogin()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()returnedcode=0. ThepollStates()function silently skippedprocessDataResponse()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 freshlogin(). 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:
NextHours.Location_1.Day_X.Hour_Y.*location_1.ForecastHourly.Hour_Y.*rain_valuerainclouds_valuecloudshour_valuetimedayhourshoursUpdated
weatherAdaptersconfig inplenticore.jsand replaced the broken Kachelmann rain scraping with a newgetRainDataFromDaswetter()function that reads rain data directly from daswetter ioBroker states.Eliminates the recurring warnings:
Test environment
node --checkpasses on both filesRelated issues
Fixes #147 (daswetter v4 compatibility)