Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
191 changes: 178 additions & 13 deletions README.md

Large diffs are not rendered by default.

70 changes: 70 additions & 0 deletions demos/arduino_cli_esp32/arduino_cli_esp32.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* SNMP_Agent minimal demo — ESP32 (esp32:esp32:esp32)
* Target: arduino-cli compile --fqbn esp32:esp32:esp32
* Purpose: DoD H — confirm Arduino-CLI ESP32 build is zero-error,
* zero-warning against the current SNMP_Agent HEAD checkout.
*
* Wiring: Serial 115200 baud (native USB on ESP32 DevKitC).
*
* Before run:
* 1. Fill in WIFI_SSID / WIFI_PASSWORD below.
* 2. Install esp32:esp32 core via Arduino CLI board manager.
* 3. Symlink / copy this repo into your <sketchbook>/libraries/SNMP_Agent
* (Arduino-CLI scans for libraries here at compile time).
* e.g. ln -s <repo> ~/Arduino/libraries/SNMP_Agent
*/

#include <WiFi.h>
#include <SNMP_Agent.h>

#define WIFI_SSID "your-ssid-here"
#define WIFI_PASSWORD "your-pass-here"

static SNMPAgent agent;

static int myInteger = 42;
static char sensorName[] = "ESP32-Sensor";
static uint32_t counter32 = 0;

static uint32_t getUptimeSeconds(void) { return (uint32_t)(millis() / 1000U); }

void setup()
{
Serial.begin(115200);
delay(500);
Serial.println();
Serial.println("SNMP_Agent v3.x minimal demo (ESP32)");

WiFi.mode(WIFI_STA);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
delay(200);
Serial.print('.');
}
Serial.println();
Serial.print("IP: "); Serial.println(WiFi.localIP());

agent.begin(); // Default community: "public", OID prefix: ".1.3.6.1.2.1.1"

/* Three representative handlers to stress-test different ValueCallback
* code paths (integer / static string / dynamic-timestamp). */
agent.addIntegerHandler(".8.0", &myInteger, true);
agent.addReadOnlyStaticStringHandler(".5.0", sensorName);
agent.addDynamicReadOnlyTimestampHandler(".3.0", getUptimeSeconds);

agent.addCounter32Handler(".6.1.2.1.0", &counter32);

Serial.println("SNMP agent started. try: snmpget -v 2c -c public <ip> .1.3.6.1.2.1.1.8.0");
}

void loop()
{
agent.loop();

static unsigned long lastTick = 0;
if (millis() - lastTick > 1000UL) {
lastTick = millis();
counter32++; /* Exercise the counter32 handler on each tick so
subsequent SNMP walks see changing data. */
}
}
70 changes: 70 additions & 0 deletions demos/arduino_cli_esp8266/arduino_cli_esp8266.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* SNMP_Agent minimal demo — ESP8266 (ESP-01)
* Target: arduino-cli compile --fqbn esp8266:esp8266:generic
* Purpose: DoD H — confirm Arduino-CLI ESP8266 build is zero-error,
* zero-warning against the current SNMP_Agent HEAD checkout.
*
* Wiring: Serial 115200 baud, GPIO1 TX, GPIO3 RX (ESP-01 pins).
*
* Before run:
* 1. Fill in WIFI_SSID / WIFI_PASSWORD below.
* 2. Install esp8266:esp8266 core via Arduino CLI board manager.
* 3. Symlink / copy this repo into your <sketchbook>/libraries/SNMP_Agent
* (Arduino-CLI scans for libraries here at compile time).
* e.g. ln -s <repo> ~/Arduino/libraries/SNMP_Agent
*/

#include <ESP8266WiFi.h>
#include <SNMP_Agent.h>

#define WIFI_SSID "your-ssid-here"
#define WIFI_PASSWORD "your-pass-here"

static SNMPAgent agent;

static int myInteger = 42;
static char sensorName[] = "ESP-01-Sensor";
static uint32_t counter32 = 0;

static uint32_t getUptimeSeconds(void) { return (uint32_t)(millis() / 1000U); }

void setup()
{
Serial.begin(115200);
delay(500);
Serial.println();
Serial.println(F("SNMP_Agent v3.x minimal demo (ESP8266)"));

WiFi.mode(WIFI_STA);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
delay(200);
Serial.print('.');
}
Serial.println();
Serial.print(F("IP: ")); Serial.println(WiFi.localIP());

agent.begin(); // Default community: "public", OID prefix: ".1.3.6.1.2.1.1"

/* Three representative handlers to stress-test different ValueCallback
* code paths (integer / static string / dynamic-timestamp). */
agent.addIntegerHandler(".8.0", &myInteger, true);
agent.addReadOnlyStaticStringHandler(".5.0", sensorName);
agent.addDynamicReadOnlyTimestampHandler(".3.0", getUptimeSeconds);

agent.addCounter32Handler(".6.1.2.1.0", &counter32);

Serial.println(F("SNMP agent started. try: snmpget -v 2c -c public <ip> .1.3.6.1.2.1.1.8.0"));
}

void loop()
{
agent.loop();

static unsigned long lastTick = 0;
if (millis() - lastTick > 1000UL) {
lastTick = millis();
counter32++; /* Exercise the counter32 handler on each tick so
subsequent SNMP walks see changing data. */
}
}
46 changes: 46 additions & 0 deletions demos/platformio_minimal/platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
; PlatformIO project for SNMP_Agent minimal compilation demo — DoD I
; --------------------------------------------------------------------
; Build commands:
; cd demos/platformio_minimal
; pio run --environment esp8266 ; ESP-01 (1MB flash) build
; pio run --environment esp32 ; ESP32 DevKitC build
; pio run ; both environments in parallel
; --------------------------------------------------------------------

[platformio]
default_envs = esp8266, esp32
; lib_extra_dirs is PER-ENVIRONMENT, not global. We use relative path
; demos/platformio_minimal -> . is platformio_minimal; ../.. is demos;
; ../../.. is the repo root where library.properties of SNMP_Agent lives.

; -------- COMMON SNIPPET reusable for each env --------
[common_env]
build_flags =
-Wall -Wextra -Werror
-std=gnu++11
lib_compat_mode = strict
lib_ldf_mode = deep+
; Repo root relative to demos/platformio_minimal/: 3 levels up
lib_extra_dirs = ../../..

; -------- ESP-01 (ESP8266, 1MB flash, "dout" required for the tiny flash chip) --------
[env:esp8266]
platform = espressif8266
board = esp01_1m
framework = arduino
board_build.flash_mode = dout
build_flags = ${common_env.build_flags}
lib_compat_mode = ${common_env.lib_compat_mode}
lib_ldf_mode = ${common_env.lib_ldf_mode}
lib_extra_dirs = ${common_env.lib_extra_dirs}

; -------- ESP32 DevKitC (default 4MB flash, QIO flash mode) --------
[env:esp32]
platform = espressif32
board = esp32dev
framework = arduino
build_flags = ${common_env.build_flags}
lib_compat_mode = ${common_env.lib_compat_mode}
lib_ldf_mode = ${common_env.lib_ldf_mode}
lib_extra_dirs = ${common_env.lib_extra_dirs}

73 changes: 73 additions & 0 deletions demos/platformio_minimal/src/main.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* SNMP_Agent minimal demo — dual-build (esp8266 + esp32 via PlatformIO)
* Target: pio run --environment esp8266 / pio run --environment esp32
* Purpose: DoD I — confirm PlatformIO strict build (with -Werror) passes
* both ESP targets cleanly.
*
* Uses #if macro dispatch so a single .ino file compiles against both
* ESP8266WiFi.h (Espressif 8266 core) and WiFi.h (Espressif 32 core).
*
* Before flashing: fill in WIFI_SSID / WIFI_PASSWORD below, then
* pio run -t upload -e esp8266 OR pio run -t upload -e esp32
* pio device monitor -b 115200
*/

#if defined(ESP8266)
# include <ESP8266WiFi.h>
#else
# include <WiFi.h>
#endif

#include <SNMP_Agent.h>

#define WIFI_SSID "your-ssid-here"
#define WIFI_PASSWORD "your-pass-here"

static SNMPAgent agent;

static int myInteger = 42;
static char sensorName[] = "PlatformIO-Sensor";
static uint32_t counter32 = 0;

static uint32_t getUptimeSeconds(void) { return (uint32_t)(millis() / 1000U); }

void setup()
{
Serial.begin(115200);
delay(500);
Serial.println();
#if defined(ESP8266)
Serial.println(F("SNMP_Agent v3.x minimal demo (ESP8266 / PlatformIO)"));
#else
Serial.println("SNMP_Agent v3.x minimal demo (ESP32 / PlatformIO)");
#endif

WiFi.mode(WIFI_STA);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
delay(200);
Serial.print('.');
}
Serial.println();
Serial.print("IP: "); Serial.println(WiFi.localIP());

agent.begin();

agent.addIntegerHandler(".8.0", &myInteger, true);
agent.addReadOnlyStaticStringHandler(".5.0", sensorName);
agent.addDynamicReadOnlyTimestampHandler(".3.0", getUptimeSeconds);
agent.addCounter32Handler(".6.1.2.1.0", &counter32);

Serial.println("SNMP agent started.");
}

void loop()
{
agent.loop();

static unsigned long lastTick = 0;
if (millis() - lastTick > 1000UL) {
lastTick = millis();
counter32++;
}
}
31 changes: 24 additions & 7 deletions examples/ESP32_SNMP/ESP32_SNMP.ino
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
#if defined (ESP8266)
#include <ESP8266WiFi.h> // ESP8266 Core WiFi Library
#include <ESP8266WiFi.h> // ESP8266 Core WiFi Library
#else
#include <WiFi.h> // ESP32 Core WiFi Library
#include <WiFi.h> // ESP32 Core WiFi Library
#endif

/* -------------------------------------------------------------------------- *
* COMPILE-TIME TUNING (optional, BEFORE #include <SNMP_Agent.h>)
*
* All SNMP size constants in src/include/defs.h are wrapped with
* `#ifndef ... #endif` so a sketch-side #define placed here wins over the
* library defaults. Good targets for ESP-01 1 MB / 80 KB RAM sensors:
*
* #define SNMP_MAX_COMPLEX_CHILDREN 8
* #define SNMP_MAX_VARBINDS 4
* #define SNMP_MAX_CALLBACKS_PER_AGENT 16
* #define SNMP_MAX_TRAPS_INFLIGHT 4
* #define SNMP_POOL_ASN_OBJECTS 32
* #define SNMP_POOL_VARBIND_OBJECTS 12
*
* Saves ~25 KB BSS (ASNPool halves: (64 - 32) * 768 B = 24,576 B) and a
* few KB more from smaller fixed callback/varbind arrays.
* -------------------------------------------------------------------------- */

#include <WiFiUdp.h>
#include <SNMP_Agent.h>
#include <SNMPTrap.h>
Expand All @@ -21,19 +39,20 @@ int settableNumber = 0;
uint32_t tensOfMillisCounter = 0;

// arbitrary data will be stored here to act as an OPAQUE data-type
uint8_t* stuff = 0;
uint8_t stuff[4];


// If we want to change the functionaality of an OID callback later, store them here.
ValueCallback* changingNumberOID;
ValueCallback* settableNumberOID;
TimestampCallback* timestampCallbackOID;

std::string staticString = "This value will never change";
char staticString[] = "This value will never change";

// Setup an SNMPTrap for later use
SNMPTrap* settableNumberTrap = new SNMPTrap("public", SNMP_VERSION_2C);
char* changingString;
char _changingStringBuf[25];
char* changingString = _changingStringBuf;

void setup(){
Serial.begin(115200);
Expand All @@ -57,7 +76,6 @@ void setup(){
snmp.begin();

// setup our OPAQUE data-type
stuff = (uint8_t*)malloc(4);
stuff[0] = 1;
stuff[1] = 2;
stuff[2] = 24;
Expand All @@ -80,7 +98,6 @@ void setup(){
snmp.addReadOnlyStaticStringHandler(".1.3.6.1.4.1.5.11", staticString);

// Setup read/write string
changingString = (char*)malloc(25 * sizeof(char));
snprintf(changingString, 25, "This is changeable");
snmp.addReadWriteStringHandler(".1.3.6.1.4.1.5.12", &changingString, 25, true);

Expand Down
Loading
Loading