Skip to content

Conversation

@silverfoxy
Copy link
Contributor

@silverfoxy silverfoxy commented Aug 15, 2025

This PR adds new settings for static IP address. This is particularly useful for setups where the router does not support static IPs and mDNS does not work. This allows me to define a hardcoded hostname and ensure that Gaggimate's IP stays the same.

I tested this settings by manually flashing the firmware on the controller and the display:

  • I verified that "Gaggimate" AP works as expected.
  • Once the wifi configuration is setup, I verified that both DHCP and static IP work as expected.
  • Export settings option correctly includes static IP configurations.

Summary by CodeRabbit

  • New Features
    • Added Static IP support for Wi‑Fi networking.
    • New Settings section: “Network Configuration” with a “Use Static IP” toggle and fields for IP Address, Subnet Mask, Gateway, and DNS (enabled when toggled on).
    • Settings are saved and applied on the device; when Static IP is off or not set, the device uses DHCP.
    • Web interface now displays and updates these network settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 15, 2025

Walkthrough

Adds optional static IP support across firmware, backend, and web UI: new settings for static IP parameters; controller applies static or DHCP during WiFi setup; WebUI API can read/write these settings; frontend exposes a toggle and fields for static IP, netmask, gateway, and DNS.

Changes

Cohort / File(s) Summary
WiFi Controller
src/display/core/Controller.cpp
Adds branch to parse/apply static IP (IP, netmask, gateway, optional DNS defaulting to gateway). Resets to DHCP when static IP not enabled or absent. Logs outcomes; rest of WiFi flow unchanged.
Settings Core
src/display/core/Settings.h, src/display/core/Settings.cpp
Introduces static IP settings: enable flag and four string fields; getters/setters; load/save via preferences with new keys (si_e, si_ip, si_nm, si_gw, si_dns). Defaults set (netmask 255.255.255.0).
Web UI Backend
src/display/plugins/WebUIPlugin.cpp
Extends /api/settings GET to include static IP fields. POST updates static IP fields when provided; staticIpEnabled set via arg presence.
Web UI Frontend
web/src/pages/Settings/index.jsx
Adds Network Configuration section: toggle for static IP and inputs for IP, netmask, gateway, DNS (enabled when toggled). Form handling updated to include these fields.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant WebApp
  participant WebUIPlugin
  participant Settings

  User->>WebApp: Toggle "Use Static IP", edit fields
  WebApp->>WebUIPlugin: POST /api/settings (staticIpEnabled, staticIp, ...)
  WebUIPlugin->>Settings: setStaticIpEnabled/setStaticIp/...
  Settings-->>WebUIPlugin: Persisted
  WebUIPlugin-->>WebApp: 200 OK
  WebApp->>WebUIPlugin: GET /api/settings
  WebUIPlugin->>Settings: read getters
  WebUIPlugin-->>WebApp: JSON incl. static IP fields
Loading
sequenceDiagram
  participant Controller
  participant Settings
  participant WiFi

  Controller->>Settings: read staticIpEnabled + params
  alt Static IP enabled with valid IP/netmask/gateway
    Controller->>WiFi: config(ip, gateway, netmask, dns|gateway)
  else Not enabled or no static IP
    Controller->>WiFi: config(0,0,0)  Note right of WiFi: DHCP
  end
  Controller->>WiFi: begin(ssid, pass)
  WiFi-->>Controller: connection events
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

A rabbit taps the network tree,
“Static burrows? Yes, for me!”
IPs lined like carrot rows,
Gateway paths where traffic flows.
DNS stars to guide the night—
Flip the switch, we’re locked in tight.
DHCP? Hop on, if light.

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
6 Security Hotspots

See analysis details on SonarQube Cloud

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/display/core/Settings.h (1)

171-175: Reasonable defaults; consider optional future constantization.

Defaults look sane (netmask 255.255.255.0, empty gateway/DNS). Optionally, you could lift the netmask default into a named constant alongside other defaults in constants.h for consistency.

web/src/pages/Settings/index.jsx (1)

427-491: Add basic client-side IPv4 validation and required constraints when static IP is enabled.

This reduces invalid submissions that would otherwise fall back to DHCP and avoids silent misconfigurations. Pattern + inputMode + required improve UX without changing backend.

Apply this diff to the static IP inputs:

-                <input
+                <input
                   id='staticIp'
                   name='staticIp'
                   type='text'
                   className='input input-bordered w-full'
                   placeholder='192.168.1.100'
-                  value={formData.staticIp}
-                  onChange={onChange('staticIp')}
+                  value={formData.staticIp}
+                  onChange={onChange('staticIp')}
+                  autoComplete='off'
+                  inputMode='numeric'
+                  pattern='^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$'
+                  title='Enter a valid IPv4 address, e.g. 192.168.1.100'
+                  required={!!formData.staticIpEnabled}
                   disabled={!formData.staticIpEnabled}
                 />
@@
-                <input
+                <input
                   id='staticNetmask'
                   name='staticNetmask'
                   type='text'
                   className='input input-bordered w-full'
                   placeholder='255.255.255.0'
-                  value={formData.staticNetmask}
-                  onChange={onChange('staticNetmask')}
+                  value={formData.staticNetmask}
+                  onChange={onChange('staticNetmask')}
+                  autoComplete='off'
+                  inputMode='numeric'
+                  pattern='^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$'
+                  title='Enter a valid IPv4 netmask, e.g. 255.255.255.0'
+                  required={!!formData.staticIpEnabled}
                   disabled={!formData.staticIpEnabled}
                 />
@@
-                <input
+                <input
                   id='staticGateway'
                   name='staticGateway'
                   type='text'
                   className='input input-bordered w-full'
                   placeholder='192.168.1.1'
-                  value={formData.staticGateway}
-                  onChange={onChange('staticGateway')}
+                  value={formData.staticGateway}
+                  onChange={onChange('staticGateway')}
+                  autoComplete='off'
+                  inputMode='numeric'
+                  pattern='^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$'
+                  title='Enter a valid IPv4 gateway, e.g. 192.168.1.1'
+                  required={!!formData.staticIpEnabled}
                   disabled={!formData.staticIpEnabled}
                 />
@@
-                <input
+                <input
                   id='staticDns'
                   name='staticDns'
                   type='text'
                   className='input input-bordered w-full'
                   placeholder='8.8.8.8'
-                  value={formData.staticDns}
-                  onChange={onChange('staticDns')}
+                  value={formData.staticDns}
+                  onChange={onChange('staticDns')}
+                  autoComplete='off'
+                  inputMode='numeric'
+                  pattern='^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$'
+                  title='Enter a valid IPv4 DNS server (optional). If omitted, the gateway will be used.'
                   disabled={!formData.staticIpEnabled}
                 />
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 45bb833 and d0b629f.

📒 Files selected for processing (5)
  • src/display/core/Controller.cpp (1 hunks)
  • src/display/core/Settings.cpp (3 hunks)
  • src/display/core/Settings.h (3 hunks)
  • src/display/plugins/WebUIPlugin.cpp (2 hunks)
  • web/src/pages/Settings/index.jsx (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
src/display/core/Settings.h (1)
src/display/core/Settings.cpp (10)
  • setStaticIpEnabled (198-201)
  • setStaticIpEnabled (198-198)
  • setStaticIp (203-206)
  • setStaticIp (203-203)
  • setStaticNetmask (208-211)
  • setStaticNetmask (208-208)
  • setStaticGateway (213-216)
  • setStaticGateway (213-213)
  • setStaticDns (218-221)
  • setStaticDns (218-218)
web/src/pages/Settings/index.jsx (2)
web/src/pages/Scales/index.jsx (1)
  • key (6-6)
web/src/pages/OTA/index.jsx (1)
  • formData (10-10)
🔇 Additional comments (8)
src/display/core/Settings.h (2)

44-48: LGTM: getters for static IP settings are coherent and consistent with existing API.

Naming, return types, and placement next to WiFi fields are consistent with the rest of Settings. No issues found.


106-110: LGTM: setters align with persistence model.

The setters mirror existing style and are implemented in Settings.cpp with save() calls. No issues found.

web/src/pages/Settings/index.jsx (1)

90-92: LGTM: boolean toggle handling for staticIpEnabled matches existing pattern.

Using presence toggles like other checkbox fields keeps the UI/POST shape consistent.

src/display/plugins/WebUIPlugin.cpp (2)

336-344: Boolean handling and selective updates look good; matches UI behavior.

  • staticIpEnabled derived from presence of the checkbox is consistent with other toggles.
  • IP fields are only updated when present, so disabled inputs won’t clobber stored values.

No changes required.


422-426: LGTM: GET now surfaces static IP settings for the UI and export.

Fields align with Settings getters and match the web form names. No issues found.

src/display/core/Settings.cpp (3)

24-29: LGTM: preference keys and defaults for static IP settings are reasonable.

Keys si_e, si_ip, si_nm, si_gw, si_dns are concise and consistent with existing naming.


198-221: LGTM: setters persist changes via save().

Implementation is straightforward and mirrors other settings. No issues found.


436-441: LGTM: doSave persists static IP fields with existing preferences.

No issues found. Keys match constructor load.

Comment on lines +156 to +177

// Configure static IP if enabled
if (settings.isStaticIpEnabled() && !settings.getStaticIp().isEmpty()) {
IPAddress ip, netmask, gateway, dns;

if (ip.fromString(settings.getStaticIp()) &&
netmask.fromString(settings.getStaticNetmask()) &&
gateway.fromString(settings.getStaticGateway())) {

if (settings.getStaticDns().isEmpty() || !dns.fromString(settings.getStaticDns())) {
dns = gateway; // Use gateway as DNS if no DNS specified
}

ESP_LOGI(LOG_TAG, "Configuring static IP: %s", settings.getStaticIp().c_str());
WiFi.config(ip, gateway, netmask, dns);
} else {
ESP_LOGE(LOG_TAG, "Invalid static IP configuration, using DHCP");
}
} else {
// Reset to DHCP
WiFi.config(0U, 0U, 0U);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Bug: invalid static IP config logs “using DHCP” but never resets to DHCP.

If parsing fails, the previous static configuration may persist. Call WiFi.config(0U,0U,0U) in the error branch to guarantee DHCP fallback.

Apply this diff:

             } else {
-                ESP_LOGE(LOG_TAG, "Invalid static IP configuration, using DHCP");
+                ESP_LOGE(LOG_TAG, "Invalid static IP configuration, using DHCP");
+                // Ensure we fall back to DHCP when static configuration is invalid
+                WiFi.config(0U, 0U, 0U);
             }
🤖 Prompt for AI Agents
In src/display/core/Controller.cpp around lines 156 to 177, the error branch
that logs "Invalid static IP configuration, using DHCP" does not actually reset
networking to DHCP, so previous static settings may persist; update the else
branch that handles failed IP parsing to call WiFi.config(0U, 0U, 0U) (after the
ESP_LOGE) to force DHCP fallback, keeping the log message as-is to indicate the
change.

@jniebuhr jniebuhr added this to the v1.7.0 milestone Aug 19, 2025
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.

2 participants