Arduino_SNMP icon indicating copy to clipboard operation
Arduino_SNMP copied to clipboard

Pointer to structure for addReadWriteStringHandler results in SNMP no such object

Open dmarc1234 opened this issue 2 years ago • 6 comments

I am trying to point the addReadWriteStringHandler() to a char array within a global structure to allow a GET and SET to be performed on it and I am having real problems getting to work.

I have tried creating a pointer to the structure and dereferencing the structure like this:

SNMPAgent * snmp; snmp = new SNMPAgent("public", "private");

CONFIG_REG conf = new CONFIG_REG(); snmp->addReadWriteStringHandler(".1.3.6.1.4.1.38218.1.3.1.0", (char*) (*conf).sensor_name, 40, true);

But get a SNMP not such object reply in iReasoning MIB browser.

The snmp->addReadOnlyStaticStringHandler() works okay so I am at a loss as to why it will not work ?

dmarc1234 avatar Jan 18 '23 14:01 dmarc1234

That line did come out right above, should be:

snmp->addReadWriteStringHandler(".1.3.6.1.4.1.38218.1.3.1.0", (char**)(*conf).sensor_name, 40, true);

dmarc1234 avatar Jan 18 '23 14:01 dmarc1234

Hi @dmarc1234. What is the type of (*conf).sensor_name? If it is a char*, then you'll need to pass the reference of it to addReadWriteStringHandler(). For example: snmp->addReadWriteStringHandler(".1.3.6.1.4.1.38218.1.3.1.0", &(*conf).sensor_name, 40, true); You shouldn't need to cast it to a char** unless it's not a char* originally.

Let me know if that helps!. Thanks.

0neblock avatar Jan 18 '23 22:01 0neblock

Thank you for your reply.

Yes, (*conf).sensor_name is a char within the CONFIG_REG structure.

I have tried: snmp->addReadWriteStringHandler(".1.3.6.1.4.1.38218.1.3.1.0", &(*conf).sensor_name, 40, true); but it will not compile, I need to cast to char** to make it compile, so: snmp->addReadWriteStringHandler(".1.3.6.1.4.1.38218.1.3.1.0", (char**)&(*conf).client_name, 40, true); which compiles but still results in a SNMP no such object error.

Also tried a different approach as follows:

CONFIG_REG *config = &configReg;
snmp->addReadWriteStringHandler(".1.3.6.1.4.1.38218.1.3.1.0", (char**)&config->sensor_name, 40, true);

which returns a blank string rather than the no object error.

Really not sure where to go next ?

dmarc1234 avatar Jan 19 '23 09:01 dmarc1234

@dmarc1234 Can you show me the declaration of the CONFIG_REG type? What data type is sensor_name?

0neblock avatar Jan 22 '23 06:01 0neblock

This is how CONFIG_REG is defined:

// Structure to contain configuration information
typedef struct
{
	char		sensor_name[40];		// Sensor name
	char		sensor_location[40];	// Sensor location
} CONFIG_REG;

and then declared as a global in main.c : CONFIG_REG configReg;

I then create a pointer to it using: CONFIG_REG *config = &configReg;

dmarc1234 avatar Jan 25 '23 11:01 dmarc1234

@0neblock did you see my message in relation to the structure, still struggling to get this to work.

dmarc1234 avatar Jan 31 '23 10:01 dmarc1234