Code Monkey home page Code Monkey logo

arduino_connectionhandler's Introduction

Arduino Library for network connections management

Check Arduino status Compile Examples status Spell Check status

Library for handling and managing network connections by providing keep-alive functionality and automatic reconnection in case of connection-loss. It supports the following boards:

How-to-use

#include <Arduino_ConnectionHandler.h>
/* ... */
#if defined(BOARD_HAS_ETHERNET)
EthernetConnectionHandler conMan;
#elif defined(BOARD_HAS_WIFI)
WiFiConnectionHandler conMan("SECRET_SSID", "SECRET_PASS");
#elif defined(BOARD_HAS_GSM)
GSMConnectionHandler conMan("SECRET_PIN", "SECRET_APN", "SECRET_GSM_LOGIN", "SECRET_GSM_PASS");
#elif defined(BOARD_HAS_NB)
NBConnectionHandler conMan("SECRET_PIN", "SECRET_APN", "SECRET_GSM_LOGIN", "SECRET_GSM_PASS");
#elif defined(BOARD_HAS_LORA)
LoRaConnectionHandler conMan("SECRET_APP_EUI", "SECRET_APP_KEY");
#endif
/* ... */
void setup() {
  Serial.begin(9600);
  while(!Serial) { }

  setDebugMessageLevel(DBG_INFO);

  conMan.addCallback(NetworkConnectionEvent::CONNECTED, onNetworkConnect);
  conMan.addCallback(NetworkConnectionEvent::DISCONNECTED, onNetworkDisconnect);
  conMan.addCallback(NetworkConnectionEvent::ERROR, onNetworkError);
}

void loop() {
  /* The following code keeps on running connection workflows on our
   * ConnectionHandler object, hence allowing reconnection in case of failure
   * and notification of connect/disconnect event if enabled (see
   * addConnectCallback/addDisconnectCallback) NOTE: any use of delay() within
   * the loop or methods called from it will delay the execution of .check(),
   * which might not guarantee the correct functioning of the ConnectionHandler
   * object.
   */
  conMan.check();
}
/* ... */
void onNetworkConnect() {
  Serial.println(">>>> CONNECTED to network");
}

void onNetworkDisconnect() {
  Serial.println(">>>> DISCONNECTED from network");
}

void onNetworkError() {
  Serial.println(">>>> ERROR");
}

arduino_connectionhandler's People

Contributors

aentinger avatar aliphys avatar cmaglie avatar dependabot[bot] avatar fabik111 avatar facchinm avatar ilcato avatar manchoz avatar mastrolinux avatar matteosuppo avatar mirkokurt avatar pennam avatar per1234 avatar physicsuofraui avatar sandeepmistry avatar ubidefeo avatar zfields avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

arduino_connectionhandler's Issues

WiFi101OTA not working with ConnectionHandler

Just added WiFiConnectionHandler to code that previously used WiFi101 for MKR1000 board but now the WiFiOTA does not register the board in the ports selection. If I remove ConnectionHandler and revert back to WiFI101 natively (I know ConnectionHandler just calls this library after testing for ARCH of hardware) it works normally. This does not make any sense, any help would be greatly appreciated.

#include <Arduino_WiFiConnectionHandler.h>
#include <WiFi101OTA.h>

const char* ssid = "_SSID_";
const char* password = "_PASSWORD_";

WiFiConnectionHandler net(ssid, password);

void onNetworkConnect(void *_arg) {Serial.println(">>>> CONNECTED to network");}
void onNetworkDisconnect(void *_arg) {Serial.println(">>>> DISCONNECTED from network");}

void setup() 
{
  delay(5000);
  Serial.begin(115200);
  setDebugMessageLevel(2);
  net.addConnectCallback(onNetworkConnect);
  net.addDisconnectCallback(onNetworkDisconnect);
  WiFiOTA.begin("_HostName_", "_Password_", InternalStorage);
}

void loop() 
{
  net.update();
  WiFiOTA.poll();
}

VERSION INFO
MKR1000 Firmware v19.6.1
Arduino IDE v1.8.9
Arduino SAMD (32-bits ARM Cortex-M0+) v1.8.3
WiFi101OTA v1.0.2
Arduino_ConnectionHandler v0.1.3

Adding SSL selector?

Helpful library -thanks! Would you consider adding a SSL selector in the calls?

Add support for MKR ETH Shield

Hello!

Is there any equivalent statement for the MKR ETH shield for the MKR1000 WiFi mode:

WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);

Need to use MKR1000 with already tested MKR ETH shield. Thanks.

Kind regards.

Arduino Library Manager Issues?

0.7.7. working great on Opta HW using Arduino IDE - and now I want to move the sketch into the PLC IDE tool.

I'm now trying to use the Arduino PLC IDE (ver 1.0.3.1) and it only pulls libraries down from the Arduino Library Manager (i.e. they must be registered and catalogued there). BUT - it isn't working for me. Not sure if it's my tools fault or what. Arduino_ConnectionHandler only shows up on there to version 0.7.6. When I add it to the Sketch/Library manager in the PLC IDE it tries to pull it down (vs 0.7.6 or less) it fails.

Do you have any insight as to why? or where the error may be? I am also pinging the Arduino support to see if the PLC IDE library manager is working.

getStatus() help

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,

Arduino R4 Wifi Error - WifiS3.h : No such file or directory

Trying to use this library on an Uno R4 Wifi and I get this compile error:

Processing uno_r4_wifi (platform: renesas-ra; framework: arduino; board: uno_r4_wifi)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/renesas-ra/uno_r4_wifi.html
PLATFORM: Renesas RA (1.1.0) > Arduino Uno R4 WiFi    
HARDWARE: RA4M1 48MHz, 32KB RAM, 256KB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, jlink)
PACKAGES:
 - framework-arduinorenesas-uno @ 1.0.2
 - tool-bossac @ 1.10901.0 (1.9.1)
 - toolchain-gccarmnoneeabi @ 1.100301.220327 (10.3.1)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 30 compatible libraries
Scanning dependencies...
Dependency Graph
|-- ArduinoIoTCloud @ 1.12.0
|-- Arduino_ConnectionHandler @ 0.7.6
Building in release mode
Compiling .pio\build\uno_r4_wifi\src\Blink.cpp.o
Compiling .pio\build\uno_r4_wifi\lib2f1\Arduino_ConnectionHandler\Arduino_ConnectionHandler.cpp.o
Compiling .pio\build\uno_r4_wifi\lib2f1\Arduino_ConnectionHandler\Arduino_EthernetConnectionHandler.cpp.o
Compiling .pio\build\uno_r4_wifi\lib2f1\Arduino_ConnectionHandler\Arduino_GSMConnectionHandler.cpp.o
Compiling .pio\build\uno_r4_wifi\lib2f1\Arduino_ConnectionHandler\Arduino_LoRaConnectionHandler.cpp.o
Compiling .pio\build\uno_r4_wifi\lib2f1\Arduino_ConnectionHandler\Arduino_NBConnectionHandler.cpp.o
Compiling .pio\build\uno_r4_wifi\lib2f1\Arduino_ConnectionHandler\Arduino_WiFiConnectionHandler.cpp.o
Compiling .pio\build\uno_r4_wifi\lib68b\ArduinoIoTCloud\ArduinoIoTCloud.cpp.o
Compiling .pio\build\uno_r4_wifi\lib68b\ArduinoIoTCloud\ArduinoIoTCloudLPWAN.cpp.o
Compiling .pio\build\uno_r4_wifi\lib68b\ArduinoIoTCloud\ArduinoIoTCloudTCP.cpp.o
Compiling .pio\build\uno_r4_wifi\lib68b\ArduinoIoTCloud\cbor\CBORDecoder.cpp.o
Compiling .pio\build\uno_r4_wifi\lib68b\ArduinoIoTCloud\cbor\CBOREncoder.cpp.o
Compiling .pio\build\uno_r4_wifi\lib68b\ArduinoIoTCloud\cbor\lib\tinycbor\src\cborencoder.c.o
Compiling .pio\build\uno_r4_wifi\lib68b\ArduinoIoTCloud\cbor\lib\tinycbor\src\cborencoder_close_container_checked.c.o
Compiling .pio\build\uno_r4_wifi\lib68b\ArduinoIoTCloud\cbor\lib\tinycbor\src\cborerrorstrings.c.o
Compiling .pio\build\uno_r4_wifi\lib68b\ArduinoIoTCloud\cbor\lib\tinycbor\src\cborparser.c.o
Compiling .pio\build\uno_r4_wifi\lib68b\ArduinoIoTCloud\cbor\lib\tinycbor\src\cborparser_dup_string.c.o
Compiling .pio\build\uno_r4_wifi\lib68b\ArduinoIoTCloud\cbor\lib\tinycbor\src\cborpretty.c.o
Compiling .pio\build\uno_r4_wifi\lib68b\ArduinoIoTCloud\cbor\lib\tinycbor\src\cborpretty_stdio.c.o
Compiling .pio\build\uno_r4_wifi\lib68b\ArduinoIoTCloud\cbor\lib\tinycbor\src\cbortojson.c.o
Compiling .pio\build\uno_r4_wifi\lib68b\ArduinoIoTCloud\cbor\lib\tinycbor\src\cborvalidation.c.o
In file included from .pio\libdeps\uno_r4_wifi\Arduino_ConnectionHandler\src\Arduino_EthernetConnectionHandler.h:22,
                 from .pio\libdeps\uno_r4_wifi\Arduino_ConnectionHandler\src\Arduino_EthernetConnectionHandler.cpp:19:
.pio\libdeps\uno_r4_wifi\Arduino_ConnectionHandler\src\Arduino_ConnectionHandler.h:151:12: fatal error: WiFiS3.h: No such file or directory

Trouble Dropping GSM Connection With No Recovery

I have been having trouble with the Arduino MKR GSM dropping the connection to the Arduino IoT cloud and not being able to recover.

I was thinking that it must be the connection to the antenna, so I tried putting dielectric grease on the connection of the antenna. That seemed to help, but I still have had a few times the connection has dropped and failed to reconnect.

I am thinking it is similar to this issue: arduino-libraries/MKRGSM#66.

I think it might be fixed by adding

static int const GPRS_TIMEOUT = 30000;

to the constants in src\Arduino_GSMConnectionHandler.cpp, and then

_gprs.setTimeout(GPRS_TIMEOUT);

directly under

_gsm.setTimeout(GSM_TIMEOUT);

In the implementation of GSMConnectionHandler::update_handleInit() in the same file as mentioned before.

This is what I am planning to try anyways.

I am not that experienced with regards to GSM communication, so if someone has a better idea to try and fix the problem I've been having I'd like to hear it.

Support for Ethernet client

is there a possibility that we have an ethernet connection handler? I am working on a project that uses teensy4 and Wiz850 Ethernet module

Arduino_ConnectionHandler does not handle open networks correctly

At line 101 in Arduino_WiFiConnectionHandler.cpp:

The code should check for an empty password and, if so, call WiFi.begin(_ssid) instead of WiFi.begin(_ssid, _password).

WiFi.begin(_ssid, "") results in a failed connection on open networks that do not require a password to connect. WiFi.begin(_ssid) connects successfully.

WiFi Handler for WPA2 Enterprise networks

Hi ๐Ÿ‘‹๐Ÿป

I have been struggling some time to connect my Arduino MKR1010 to the Arduino IoT Cloud by my university wifi network, which asks a username and password (WPA2 WiFi network).

For Arduino MKR1010, Arduino_ConnectionHandler establish a connection by creating a WiFi object from WiFiNINA and calling the method .begin(). This method only allows connections with WPA networks (SSID & Password).

If the method .beginEnterprise() from WiFiNINA was included in the class WiFiConnectionHandler fromArduino_WiFiConnectionHandler.cpp, it would be possible to connect to WPA2 Enterprise networks such as eduroam. Again, it only works for devices using WiFiNINA instead of WiFi101. I donโ€™t know if there exists a similar method for the latter.

Lastly, I tried it myself and it works. It only took me minutes to update the code. And it doesnโ€™t change what is made already.

Thanks for the nice library you created!

Why no SSL Client Support ?

I am using this along with the arduino mqtt library and its all working well however i now need to connect to an mqtt broker using TLS, i was surprised to find that i cannot use this connection handler library for that, are there are plans to add support this functionality ?

Arduino_WiFiConnectionHandler.cpp:52:15: error: 'class WiFiClass' has no member named 'getTime'

I am attempting to complete the Arduino IoT Cloud's "Get Started" project (https://create.arduino.cc/iot/onboarding) with a MKR1000 and am receiving the following after it asks for Wi-Fi network credentials and attempts to compile the onboarding sketch. I assume there is some issue with this library, because I have yet to type anything and it cannot compile the base sketch.

/home/builder/opt/libraries/latest/arduino_connectionhandler_0_7_4/src/Arduino_WiFiConnectionHandler.cpp: In member function 'virtual long unsigned int WiFiConnectionHandler::getTime()':
/home/builder/opt/libraries/latest/arduino_connectionhandler_0_7_4/src/Arduino_WiFiConnectionHandler.cpp:52:15: error: 'class WiFiClass' has no member named 'getTime'
   return WiFi.getTime();
               ^~~~~~~
Error during build: exit status 1

Errore GPRS attach failed

Hi,
I have a MKRGSM1400 board. When connecting to cloud I have the following messages in serial monitor:

20:35:20.787 -> SIM card ok
20:35:24.801 -> GPRS.attachGPRS(): 4
20:35:24.801 -> Sending PING to outer space...
20:35:29.814 -> GPRS.ping(): -2
20:35:29.814 -> PING failed
20:35:29.814 -> Retrying in  "500" milliseconds
20:35:30.131 -> GPRS.attachGPRS(): 0
20:35:30.131 -> GPRS attach failed
20:35:30.131 -> Make sure the antenna is connected and reset your board.

Then the board stop connecting and I have to reset.

Looking at Arduino_GSMConnectionHandler.cpp, but I am not an expert, I see the following code:

NetworkConnectionState GSMConnectionHandler::update_handleConnecting()
{
  GSM3_NetworkStatus_t const network_status = _gprs.attachGPRS(_apn, _login, _pass, true);
  Debug.print(DBG_DEBUG, "GPRS.attachGPRS(): %d", network_status);
  if (network_status == GSM3_NetworkStatus_t::ERROR)
  {
    Debug.print(DBG_ERROR, "GPRS attach failed");
    Debug.print(DBG_ERROR, "Make sure the antenna is connected and reset your board.");
    return NetworkConnectionState::ERROR;
  }
  Debug.print(DBG_INFO, "Sending PING to outer space...");
  int const ping_result = _gprs.ping("time.arduino.cc");
  Debug.print(DBG_INFO, "GPRS.ping(): %d", ping_result);
  if (ping_result < 0)
  {
    Debug.print(DBG_ERROR, "PING failed");
    Debug.print(DBG_INFO, "Retrying in  \"%d\" milliseconds", CHECK_INTERVAL_TABLE[static_cast<unsigned int>(NetworkConnectionState::CONNECTING)]);
    return NetworkConnectionState::CONNECTING;
  }
  else
  {
    Debug.print(DBG_INFO, "Connected to GPRS Network");
    return NetworkConnectionState::CONNECTED;
  }
}

The first time GPRS.attachGPRS() run successfully but the ping end with -2 so the program try to reconnect again.
The second time GPRS.attachGPRS() run with error, maybe because the GPRS is already connected?

I see in my test that the first ping always end with -2, but putting the ping inside a loop the second or third ping end successfully. I don't know why the first ping is always -2.

So what is the problem? The ping should be put inside a loop or the problem is the attachGPRS?

Please help.

Thanks.

SIM not present or wrong PIN routine stuck

I am using Connection Handler to get connected to GSM network via MKR GSM 1400. From time to time when I restart or reupload the sketch and I am getting error "SIM not present or wrong PIN" attaching screenshot.

When I restart the unit (reset button) or re-upload the sketch connection is successful. Looks to me that function just finish and never continue "void GSMConnectionHandler::init()" Arduino_GSMConnectionHandler.cpp

  1. Does this means in default settings there is no 2nd, 3rd etc. retry ?
  2. If so, is there any settings to set it up the way to retry again before fail or reset modem etc.?

Thanks a lot
Clipboard01

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.