Go Down

Topic: PubSubClient (or AduinoMqttClient) + Wifinina + Servo problem (Read 141 times) previous topic - next topic

arduino_cyberspace

Apr 14, 2019, 04:52 pm Last Edit: Apr 19, 2019, 05:51 pm by arduino_cyberspace
Hi,
newbie here trying to get Arduino Wifi Rev 2 to work with servo, wifi and mqtt. No success.

Bottom line
When using wifi + mqtt + servo the wifi and/or mqtt connection becomes very unstable. As soon as the servo is out of the picture, it works very well. Servo on its own works well.
In the below example the servo is not even attached to the Arduino. So no externals are connected at all but still the problem is there.

Setup
Arduino Wifi Rev 2, firmware 1.2.1
Wifinina version 1.4.0
Servo version 1.1.3
PubSubClient 2.7.0

Description
As soon as the row with the attaching of the servo is active (see the code), the whole setup becomes very unstable. See log. I cannot use all three libraries together no matter what pin I attach the servo to. The servo functionality in itself works fine, it is the dropping of the wifi and/or mqtt that is the problem. The wifi connection and mqtt connection works fine when servo is not attached. See log.

It does not matter if I use ArduinoMqttClient or PubSubClient. Same instability. The example is with PubSubClient.

First I thought the Arduino was too far away from the AP but it is exactly in the same spot as when it works. I have tried switch the servo on/off in the code several time, same result. Works when off, does not work when on (the wifi/mqtt connection).


Code
I have attached the code in a file. It is basically exactly the WifiSimpleReceive sketch but with two lines added connected to the servo setup.

Logs WITHOUT servo active
Code: [Select]
Attempting to connect to WPA SSID: XXXXXX

You're connected to the network

Connecting to MQTT... connected!


Message arrived in topic: Home/Outside/Gate/
Message: OpenGate
The total message is:OpenGate
---------------------------------------------------


Message arrived in topic: Home/Outside/Gate/
Message: LockGate
The total message is:LockGate
---------------------------------------------------

Quite stable and working well.


Logs WITH servo active
Code: [Select]
Attempting to connect to WPA SSID: XXXXXXXX
.
You're connected to the network

Connecting to MQTT... connected!
MQTT connection lost - trying again.
Connecting to MQTT... failed with state -2
Connecting to MQTT... failed with state -2
Connecting to MQTT... failed with state -2
Connecting to MQTT... failed with state -2
Connecting to MQTT... connected!
MQTT connection lost - trying again.
Connecting to MQTT... failed with state -2
Connecting to MQTT... failed with state -2
Connecting to MQTT... failed with state -2
Connecting to MQTT... failed with state -2
Connecting to MQTT... failed with state -2
Connecting to MQTT... failed with state -2
Connecting to MQTT... failed with state -2
Connecting to MQTT... failed with state -2
Connecting to MQTT... failed with state -2
Connecting to MQTT... failed with state -2
Connecting to MQTT... failed with state -2
Connecting to MQTT... failed with state -2
Connecting to MQTT... connected!
MQTT connection lost - trying again.
Connecting to MQTT... failed with state -2
Connecting to MQTT... connected!
MQTT connection lost - trying again.
Connecting to MQTT... failed with state -2
Connecting to MQTT... connected!

And so on. Very unstable.


I have been isolating this for a long time (newbie as stated before), now I understand a little bit more but still in the dark when coming up with a solution. It would be very appreciated if someone more experienced could push me in the right direction or tell me if I am doing something fundamentally wrong. Thanks!

Go Up