0neblock / Arduino_SNMP

SNMP Agent built with Arduino
MIT License
78 stars 30 forks source link

Work with the type "String" #13

Closed Sergio-tix closed 4 years ago

Sergio-tix commented 4 years ago

While reading from OID .1.3.6.1.2.1.1.2.0 need to return text "Sensor-Unit". My sketch:

#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <Arduino_SNMP.h>

const char* ssid = "888";
const char* password = "888";

WiFiUDP udp;
SNMPAgent snmp = SNMPAgent("public");  // Starts an SMMPAgent instance with the community string 'public'

int changingNumber = 1;
int settableNumber = 0;

String sysObjectID = "Sensor-Unit";

void setup(){
    Serial.begin(115200);
    WiFi.begin(ssid, password);
    Serial.println("");

    while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
    }
    Serial.println("");
    Serial.print("Connected to ");
    Serial.println(ssid);
    Serial.print("IP address: ");
    Serial.println(WiFi.localIP());
    snmp.setUDP(&udp);
    snmp.begin();

    snmp.addIntegerHandler(".1.3.6.1.4.1.5.0", &changingNumber);
    snmp.addIntegerHandler(".1.3.6.1.4.1.5.1", &settableNumber, true);
//===============================================================================

    snmp.addStringHandler(".1.3.6.1.2.1.1.2.0", &sysObjectID);

//===============================================================================

}

void loop(){
    snmp.loop(); // must be called as often as possible
    if(snmp.setOccurred){
        Serial.printf("Number has been set to value: %i", settableNumber);
        snmp.resetSetOccurred();
    }
    changingNumber++;
}

But I get a compilation error:

no matching function for call to 'SNMPAgent::addStringHandler(const char [19], String*)'

Here is all the text from the compiler:


C:\arduino-1.8.11_ESP8266\!_FW\UPS_SNMP\UPS_SNMP.ino: In function 'void setup()':

UPS_SNMP:38:61: error: no matching function for call to 'SNMPAgent::addStringHandler(const char [19], String*)'

     snmp.addStringHandler(".1.3.6.1.2.1.1.2.0", &sysObjectID);

                                                             ^

C:\arduino-1.8.11_ESP8266\!_FW\UPS_SNMP\UPS_SNMP.ino:38:61: note: candidate is:

In file included from C:\arduino-1.8.11_ESP8266\!_FW\UPS_SNMP\UPS_SNMP.ino:3:0:

C:\arduino-1.8.11_ESP8266\libraries\Arduino_SNMP-master/Arduino_SNMP.h:403:16: note: ValueCallback* SNMPAgent::addStringHandler(char*, char**, bool, bool)

 ValueCallback* SNMPAgent::addStringHandler(char* oid, char** value, bool isSettable, bool overwritePrefix){

                ^

C:\arduino-1.8.11_ESP8266\libraries\Arduino_SNMP-master/Arduino_SNMP.h:403:16: note:   no known conversion for argument 2 from 'String*' to 'char**'

exit status 1
no matching function for call to 'SNMPAgent::addStringHandler(const char [19], String*)'

As I understand it, it is necessary to transform String to Char? How to do it right?

Sergio-tix commented 4 years ago

Сan do this - pass a string in OID ? I've been trying for the third day converting "String" to "Char" different ways, But when I pass the variable to: snmp.addStringHandler(".1.3.6.1.2.1.1.2.0", &sysObjectID); That is on this line that the compiler sees errors.