Files
MeshCore/src/helpers/SNMPAgent.h
T
agessaman 4c683b13b3 fix(network): pre-merge review fixes
- Guard the boot-time link bootstrap to observer ESP32 builds. It ran
  unconditionally in MyMesh::begin(), breaking every non-observer
  repeater/room server build (ESP32 and nRF52).
- Rename NetworkInterface -> NetworkLink (class, accessor, files).
  Arduino-ESP32 3.x ships its own NetworkInterface class and header,
  which broke the ESP32-C6 builds. Drop WiFi.setAutoConnect(), a no-op
  on 2.x and removed in 3.x.
- Refresh stored Wi-Fi credentials every bridge tick so the STA
  reconnect loop picks up `set wifi.ssid` / `set wifi.pwd` without a
  reboot, as the bridge did before the link moved out of it. Skip
  reconnects while the SSID is empty.
- Restore the "WiFi connected: <ip>" / "WiFi disconnected: reason N"
  debug lines the bridge used to print.
- Alert on Ethernet only once it has held a lease this boot or when no
  Wi-Fi is configured; Wi-Fi-only installs of an Ethernet-preferred
  image keep Wi-Fi alerts instead of reporting "Ethernet down".
- Record wifi.setup_complete only for Ethernet LAN onboarding, so
  Wi-Fi builds keep the SSID-based first-boot portal rule.
- Use seq_cst for the route-switch lock/mutation flag handshake.
- Docs: SNMP RSSI sentinel is -127; describe link-return vs medium-switch
  reconnect behavior accurately; note runtime credential pickup.
- Test: unknown keys inside a known /mqtt.json group are ignored, which
  keeps wifi.setup_complete downgrade-safe.
2026-09-19 10:14:16 -07:00

80 lines
2.1 KiB
C++

#pragma once
#ifdef WITH_SNMP
#include <WiFi.h>
#include <WiFiUdp.h>
#include <SNMP_Agent.h>
// Temporary private enterprise OID base - replace with registered PEN when available.
// All MeshCore OIDs live under this subtree.
#define MESHCORE_OID_BASE ".1.3.6.1.4.1.99999"
// OID layout:
// .1.x.0 = system (uptime, version, node name)
// .2.x.0 = radio (packets, RSSI, SNR, noise floor, air time)
// .3.x.0 = mqtt (connected slots, queue depth, skipped publishes)
// .4.x.0 = memory (free heap, max alloc, internal free, PSRAM free)
// .5.x.0 = network (WiFi RSSI)
class MeshSNMPAgent {
public:
MeshSNMPAgent();
void begin(const char* community);
void loop();
// Called from the mesh task (Core 1) to push fresh stats into SNMP-visible variables.
// Copies are atomic for 32-bit aligned ints on ESP32, so no mutex needed.
void updateRadioStats(uint32_t packets_recv, uint32_t packets_sent, uint32_t recv_errors,
int16_t noise_floor, int16_t last_rssi, int16_t last_snr,
uint32_t sent_flood, uint32_t sent_direct,
uint32_t recv_flood, uint32_t recv_direct,
uint32_t total_air_time_secs, uint32_t uptime_secs);
void updateMQTTStats(int connected_slots, int queue_depth, int skipped_publishes);
void setNodeName(const char* name);
void setFirmwareVersion(const char* version);
bool isRunning() const { return _running; }
private:
WiFiUDP _udp;
SNMPAgent _snmp;
bool _running;
// System OIDs
int _uptime_secs;
char _firmware_version[32];
char _node_name[32];
// Radio OIDs
int _packets_recv;
int _packets_sent;
int _recv_errors;
int _noise_floor;
int _last_rssi;
int _last_snr;
int _sent_flood;
int _sent_direct;
int _recv_flood;
int _recv_direct;
int _total_air_time_secs;
// MQTT OIDs
int _mqtt_connected_slots;
int _mqtt_queue_depth;
int _mqtt_skipped_publishes;
// Memory OIDs (updated in loop() since we're on Core 0 with WiFi)
int _free_heap;
int _max_alloc;
int _internal_free;
int _psram_free;
// Network OIDs
int _wifi_rssi;
};
#endif // WITH_SNMP