arduino-libraries / ArduinoIoTCloud

Home Page:https://app.arduino.cc

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use without using Arduino_ConnectionHandler library

chrisisbeef opened this issue · comments

It would be really nice if there was a way to use this without it taking control of the network connection allowing someone to do their own network connection handling. Is this something that the team would consider, or would my best bet to to fork this and customize if for my own use?

Hi @chrisisbeef
what do you think is missing or does not fit your needs in the Arduino_ConnectionHandler implementation?

An issue I have run into is using the Arduino_ConnectionHandler with a WPA2 Enterprise network, which is currently not supported AFAIK. WiFiNINA does support it though, so it can be done through that instead, but then ideally we should be able to call .begin() with no arguments.

Hi, I have simmilar issue with ESP8266 board. I have created my own connection manager (not a custom handler in terms of your class) and initialize the Arduino cloud with ArduinoCloud.begin(); without any parameters. I suppose, such an approach is possible as this overload of the begin method does exist.
I have also left out the ArduinoCloud.update(); call from loop, as the docs says, that it is needed only for watch dog functionality and ESP8266 is not a supported device for this.
And the result is, that my ESP-01 board connects to my wifi, but dos not interact with the Arduino Cloud at all :-(
Here are the core parts of my sketch:

#include <ArduinoIoTCloud.h>
// #include <Arduino_ConnectionHandler.h>
#include "ESPWiFiManager.h" //my custom wifi connection manager due to need of ESP8266WiFiMulti class 

#define SECRET_DEVICE_KEY "**********************************" //masked out just for the purpose of this forum
#define SECRET_OPTIONAL_PASS "**********"
#define SECRET_SSID "***************"
const char DEVICE_LOGIN_NAME[] = "***********************";
const char SSID[] = SECRET_SSID;
const char PASS[] = SECRET_OPTIONAL_PASS;
const char DEVICE_KEY[] = SECRET_DEVICE_KEY;

// WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);

bool btnState;
void onBtnStateChange()
{
  digitalWrite(LED_BUILTIN, btnState);
}

void setup()
{
  DEBUGINIT(115200); //opens the hw serial etc.

  ArduinoCloud.setBoardId(DEVICE_LOGIN_NAME);
  ArduinoCloud.setSecretDeviceKey(DEVICE_KEY);
  ArduinoCloud.addProperty(btnState, READWRITE, ON_CHANGE, onBtnStateChange);

  wifiMgr.SetupWifi("ArduinoCloud", LED_BUILTIN); //sets up wifi connection, device host name and LED to blink for several infos
  wifiMgr.ConnectWifi(); //connects to my wifi

  ArduinoCloud.begin();
}

void loop()
{
    //ArduinoCloud.update();
}

What am I missing?

such an approach is possible as this overload of the begin method does exist.

You make a good point:

int begin(bool const enable_watchdog = true, String brokerAddress = DEFAULT_BROKER_ADDRESS_SECURE_AUTH, uint16_t brokerPort = DEFAULT_BROKER_PORT_SECURE_AUTH);

What am I missing?

Although feedback regarding the need or lack of need for changes to the library in order to support use without the "Arduino_ConnectionHandler" library is welcome, this is not an appropriate place to request assistance with your project. Please feel free to request assistance over on Arduino Forum:

https://forum.arduino.cc/c/software/iot-cloud/152

I'm sure we'll be able to help you out over there.

OK, thanks, I have creted a related topic in the forum.

Hi @milanbx I've created this draft PR #405 that should do the trick. Not yet finalized, but i've tested with a couple of boards and it is working.

I have also left out the ArduinoCloud.update(); call from loop
You always have to call ArduinoCloud.update(); in the loop otherwise communication with the cloud stops.

Thanks @pennam a lot!

Thanks @pennam a lot!

If you give it a try, let me know if it works for you!

@pennam: I have tried it and works fine! Thanks a lot! I'll wait for the PR to complete to update libraries...

@pennam: Additionally, even your ArduinoIoTCloud-Client.ino example in thingProperties.h > initProperties contains following line:
ArduinoCloud.addProperty(led, Permission::Write).onUpdate(onLedChange);
which causes plenty of compiler warnings - see issue #402, please.

I have tried it and works fine!

Good! Thanks for the feedback

I'll wait for the PR to complete to update libraries...

I'll try to complete the PR as soon as possible, this was something unplanned so please be patient.

No rush, please... 😃