Implement SNMP

SNMP (Simple Network Management Protocol) consists of an application layer protocol and database schema. It used to control and monitor network devices with different manufacturers and models. With the rapid development of IoT (interest of things) technology, network management becomes a critical issue. SNMP provides a solution to monitor these network devices.


Quick Menu

Before burning the bin file into your EVB:

  1. Connect W5500 EVB to the router/NAT that you are using, or any other device that allows you to connect to internet
  2. Manually change the Network configuration:
    • Go to the definition of function set_default() (Should be inside device.c), make sure the subnet mask, local IP address, gateway and DNS are set according to the internet setting you are using with your router/NAT
  3. Rebuild the sample code and burn it into W5500EVB

Code Explanation

int main(void)
{

After boot or reboot W5500EVB, all necessary configurations are initialized.

    uint8 m=0;	
    Systick_Init(72);
    GPIO_Configuration();
    USART1_Init();
    at24c16_init();
    printf("W5500 EVB initialization over.\r\n");
  
    Reset_W5500();
    WIZ_SPI_Init();
    printf("W5500 initialized!\r\n");  
    set_default();
    set_network(); 
/*****************



These are all the 
necessary
initialization




******************/

There are the main loop of SNMP Demo.

    while(1)
    {
        for ( m=0; m<10; m++)
        {
            GPIO_SetBits(GPIOA, LED0);
            Delay_ms(100);
            GPIO_ResetBits(GPIOA, LED0);
            Delay_ms(100);
        }
        UserSnmpDemo();
   }
/*****************



Main loop 
for SNMP Demo




******************/

UserSnmpDemo(void)

void UserSnmpDemo(void)
{
    WDEBUG("\r\n\r\nStart UserSnmpDemo");
    SnmpXInit();
    {
        dataEntryType enterprise_oid = {8, {0x2b, 6, 1, 4, 1, 0, 0x10, 0},
           SNMPDTYPE_OBJ_ID,8 ,{"\x2b\x06\x01\x04\x01\x00\x10\x00"},
           NULL, NULL};
        dataEntryType trap_oid1 = {8, {0x2b, 6, 1, 4, 1, 0, 11, 0}, 
           SNMPDTYPE_OCTET_STRING, 30, {""}, NULL, NULL};
        dataEntryType trap_oid2 = {8, {0x2b, 6, 1, 4, 1, 0, 12, 0}, 
           SNMPDTYPE_INTEGER, 4, {""}, NULL, NULL};
        strcpy((int8*)trap_oid1.u.octetstring, "Alert!!!");
        trap_oid2.u.intval = 123456;
        SnmpXTrapSend("192.168.1.110", "192.168.1.111", "public", 
           enterprise_oid, 1, 0, 0);
        SnmpXTrapSend("192.168.1.111", "127.0.0.0", "public", enterprise_oid, 
           6, 0, 2, &trap_oid1, &trap_oid2);
    }
    SnmpXDaemon();
}

Test process

  1. Execute cmd.exe
  2. Enter cd \usr\bin to change the current directory
  3. Enter the following commands to test SNMP
Type Commands(E.g. IP address = 192.168.1.111) Return
ReadDescription: read the status of LED (return String)
snmpget -v 1 -c public {IP address} .1.3.6.1.4.1.0.1.0
E.g. snmpget -v 1 -c public 192.168.1.111 .1.3.6.1.4.1.0.1.0
-LED Off
-LED On
Read Description: read the status of LED (return integer)
snmpget -v 1 -c public {IP address} .1.3.6.1.4.1.0.2.0
E.g. snmpget -v 1 -c public 192.168.1.111 .1.3.6.1.4.1.0.2.0
-0: LED Off
-1: LED On
Write Description: set the status of LED
snmpset -v 1 -c public {IP address} .1.3.6.1.4.1.0.2.0 i {enable}
E.g.  Enable: snmpset -v 1 -c public 192.168.1.111 .1.3.6.1.4.1.0.2.0 i 1
Disable: snmpset -v 1 -c public 192.168.1.111 .1.3.6.1.4.1.0.2.0 i 0
/

Remarks

  1. There are three version of SNMP, SNMP V1, SNMP V2C, SNMP V3. In this sample code, we demostrate the implementation of SNMP V1.
  2. Before this demostration, we need to install and configure SNMP service. (In window 10 computer, SNMP service is NOT installed. In window 7 computer, please install and enable SNMP in control panel.)
  3. For firewall port setting, please ensure the ports are open. The default UDP port for SNMP trap message is port 162.