arduino-libraries/Arduino_ConnectionHandler

getStatus() help

salvq opened this issue · 1 comments

salvq commented

Hello, not sure if this is issue or just I am newbie and do not know how to correctly call the function :)

I am using this connection handler for GSM MKR connection to cellular network. In my routines I would like to check what is current status of the network and use it for if condition i.e. do not execute condition in main loop until modem is connected.

    if ( (millis()-s2) > 50000 && CONNECTIONREADY) {
       s2 = millis();

       Serial.println("Fifty SECONDS");
    }

However, firstly I tried to insert boolean into routine (CONNECTED) but this boolean gets reseted once get out from the routine and in main loop value is always 0 and do not know why. Can you help to understand why is that ? :)

void onNetworkConnect(void *_arg) {
  Serial.println(">>>> CONNECTED to network");
  bool CONNECTIONREADY = true;
}

Is there better way to set CONNECTIONREADY to 1 or use function which is mention on the readme getStatus(). It says it returns the status, which variable I can read this value from ? Why I can not just read this information without using getStatus() ? How to add it to my if routine to validate condition in main loop ?

Please help me with this,
Thanks,

salvq commented

As easy as adding condition reading, but it was not that obvious from readme (at least for beginners like me)

conMan.getStatus() == (NetworkConnectionState::CONNECTED)

So final condition looks like

    if ( (millis()-s2) > 50000  && conMan.getStatus() == (NetworkConnectionState::CONNECTED)) {
       s2 = millis();

       Serial.println("Fifty SECONDS");
    }

make sure that you initiated classes before setup
GSMConnectionHandler conMan(SECRET_PIN, SECRET_APN, SECRET_GSM_USER, SECRET_GSM_PASS);