arduino-libraries / ArduinoIoTCloud

https://app.arduino.cc
Other
111 stars 78 forks source link

Use without using Arduino_ConnectionHandler library #338

Open chrisisbeef opened 2 years ago

chrisisbeef commented 2 years ago

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?

pennam commented 2 years ago

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

olipinski commented 1 year ago

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.

milanbx commented 10 months ago

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?

per1234 commented 10 months ago

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

You make a good point:

https://github.com/arduino-libraries/ArduinoIoTCloud/blob/d436b80f099be3bbc9132248aae24c3042836446/src/ArduinoIoTCloudTCP.h#L87

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.

milanbx commented 10 months ago

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

pennam commented 10 months ago

Hi @milanbx I've created this draft PR https://github.com/arduino-libraries/ArduinoIoTCloud/pull/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.

milanbx commented 10 months ago

Thanks @pennam a lot!

pennam commented 10 months ago

Thanks @pennam a lot!

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

milanbx commented 10 months ago

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

milanbx commented 10 months ago

@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.

pennam commented 10 months ago

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.

milanbx commented 10 months ago

No rush, please... 😃