A pOnvif problem could delete and re-create the whole camera node, which
dropped the video stream bound to it, so recordings were cut although the
video was fine.
deviceNodeCamera::validate() compared the whole camera record with
memcmp; any difference rebuilt the node:
- CAM_WS_INIT sets m_sCamData.online = false before re-creating the
PTZ protocol and writes the DB only afterwards. A validate() during a
slow ONVIF re-init saw "online" differ and deleted the camera
mid-re-init.
- The ONVIF discovery (updateIPCam) wrote online=1 and the whole XAddrs
list into onvif_ctrl (the web UI and la_mojo store only the path), so
the record changed on discovery rounds.
- A failed read (SQLite busy, queries fail at once) returned NULL =
"camera deleted".
Now:
- Field classes (camDataChange):
- runtime and discovery fields (online, status, session, max_range,
uuid, mac): ignored;
- name and hardware: taken over;
- PTZ access (onvif_ctrl, onvif_access, port, auth_mode, ptz_token):
the camera thread re-creates only the PTZ protocol, keeping the node
and the stream;
- anything else (ip and credentials used by the stream, stream_id,
type, geometry, ...): rebuild as before, logged with the reason.
- A lasting PTZ problem rebuilds the camera only after
CAM_REBUILD_AFTER_FAILED_INITS (10) failed protocol initialisations
in a row (several minutes with the retry back-off).
- Node / camera record not read: rebuild only after
NODE_DATA_MISSES_TO_REBUILD (3) validations in a row, for all nodes
(deviceNode::validate).
- updateIPCam: onvif_ctrl = path of the first XAddr. Host and port come
from the first XAddr only: ':' was searched in the whole list, so a
second, IPv6 XAddr gave a broken IP. A result without an address
doesn't wipe the IP.
Tested (functions extracted unchanged): camDataChange classifies
online / status / max_range / uuid / mac as ignored, rename as
cosmetic, port / onvif_ctrl / auth / ptz token as PTZ re-init, and ip /
password / stream / geometry as rebuild. The XAddrs parser was checked
with a port, without a port, with an IPv6 second XAddr, with a query, and
with no address.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
From the la_mojo log of a gateway reached over the Internet (2.54.237.28:8234):
deviceETH2UART
- In TCP mode, link health is the TCP connection itself (socket, I/O
thread, SO_ERROR, TCP keepalive). ICMP isn't used there: gateways on
mobile networks often don't answer ping, and the working connection was
closed every second ("No Ping to device!").
- Ping (UDP modes) up to 3 echoes x 2000 ms, at most every 10 s. Only an
echo reply from the gateway with our id and sequence counts. A signal
(EINTR) no longer ends the wait. The old single recvfrom() with
SO_RCVTIMEO returned EINTR at the first signal, even with SA_RESTART.
- TCP connect timeout 1 s -> 5 s (E2UART_CONNECT_TIMEOUT_MS), and EINTR in
select() continues waiting.
- create_SOL() closes the previous socket and I/O thread first. It
overwrote the socket (the connection leaked) and init() failed while
the old thread ran, so each reconnect left an open TCP connection at the
gateway and the node stayed invalid although "Connected". If init()
fails, the new socket is closed.
- create()/validate()/reconnect() are serialised: they run on the node
factory thread and on the hardware manager thread.
- Registered with the hardware manager once. Re-creation from the
hardware manager locked its non-recursive list mutex again (deadlock).
- Reconnect back-off 2 s -> 30 s.
- recv() == 0 on TCP means the gateway closed the connection (a stale
errno was checked before).
- Destructor resigns from the hardware manager before closing.
deviceNodeFactory
- deleteNode() deletes the gateway object. It was only removed from the
list and kept running next to the new node created for the same id.
- Nodes are deleted after the validation loop (erasing inside it skipped
the next node).
deviceNode::validate
- Compares the configuration only. "online" changes whenever another
object of the same node id is created or deleted.
hardwareManager::assignResource
- Ignores a resource that is already assigned.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16