Wifi Shield Network connect failed


#1

Hi

I’m new here and I’m trying to create my very first project with an Arduino Uno and a Wifi Shield, but I’ve been having problems from the very beginning. First, when I load the code into my board, The compiler gives this warnings (I’m not pretty sure if they are normal).

In file included from /Users/JoseZarco/Documents/Arduino/libraries/CayenneMQTT/src/CayenneMQTTWiFiClient.h:21:0,
from /Users/JoseZarco/Documents/Arduino/libraries/CayenneMQTT/src/CayenneMQTTWiFi.h:26,
from /Users/JoseZarco/Documents/Arduino/Cayenne/Cayenne_01/Cayenne_01.ino:15:
/Users/JoseZarco/Documents/Arduino/libraries/CayenneMQTT/src/CayenneArduinoMQTTClient.h: In member function ‘void CayenneArduinoMQTTClient::connect()’:
/Users/JoseZarco/Documents/Arduino/libraries/CayenneMQTT/src/CayenneArduinoMQTTClient.h:58:63: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
if (!NetworkConnect(&_network, CAYENNE_DOMAIN, CAYENNE_PORT)) {
^
In file included from /Users/JoseZarco/Documents/Arduino/libraries/CayenneMQTT/src/CayenneMQTTWiFi.h:26:0,
from /Users/JoseZarco/Documents/Arduino/Cayenne/Cayenne_01/Cayenne_01.ino:15:
/Users/JoseZarco/Documents/Arduino/libraries/CayenneMQTT/src/CayenneMQTTWiFiClient.h: In member function ‘void CayenneMQTTWiFiClient::begin(const char*, const char*, const char*, const char*, const char*)’:
/Users/JoseZarco/Documents/Arduino/libraries/CayenneMQTT/src/CayenneMQTTWiFiClient.h:49:33: warning: invalid conversion from ‘const char*’ to ‘char*’ [-fpermissive]
WiFi.begin(ssid, wifiPassword);
^
In file included from /Users/JoseZarco/Documents/Arduino/libraries/CayenneMQTT/src/CayenneMQTTWiFi.h:24:0,
from /Users/JoseZarco/Documents/Arduino/Cayenne/Cayenne_01/Cayenne_01.ino:15:
/Applications/Arduino.app/Contents/Java/libraries/WiFi/src/WiFi.h:79:9: note: initializing argument 1 of ‘int WiFiClass::begin(char*, const char*)’
int begin(char* ssid, const char passphrase);
^
In file included from /Users/JoseZarco/Documents/Arduino/libraries/CayenneMQTT/src/CayenneMQTTWiFi.h:26:0,
from /Users/JoseZarco/Documents/Arduino/Cayenne/Cayenne_01/Cayenne_01.ino:15:
/Users/JoseZarco/Documents/Arduino/libraries/CayenneMQTT/src/CayenneMQTTWiFiClient.h:52:19: warning: invalid conversion from 'const char
’ to ‘char*’ [-fpermissive]
WiFi.begin(ssid);
^
In file included from /Users/JoseZarco/Documents/Arduino/libraries/CayenneMQTT/src/CayenneMQTTWiFi.h:24:0,
from /Users/JoseZarco/Documents/Arduino/Cayenne/Cayenne_01/Cayenne_01.ino:15:
/Applications/Arduino.app/Contents/Java/libraries/WiFi/src/WiFi.h:60:9: note: initializing argument 1 of ‘int WiFiClass::begin(char*)’
int begin(char* ssid);
^
/Users/JoseZarco/Documents/Arduino/libraries/CayenneMQTT/src/CayenneMQTTClient/CayenneMQTTClient.c: In function ‘CayenneMQTTPublishDataInt’:
/Users/JoseZarco/Documents/Arduino/libraries/CayenneMQTT/src/CayenneMQTTClient/CayenneMQTTClient.c:135:2: warning: implicit declaration of function ‘itoa’ [-Wimplicit-function-declaration]
itoa(value, str, 10);
^
/Users/JoseZarco/Documents/Arduino/libraries/CayenneMQTT/src/CayenneMQTTClient/CayenneMQTTClient.c: In function ‘CayenneMQTTPublishDataUInt’:
/Users/JoseZarco/Documents/Arduino/libraries/CayenneMQTT/src/CayenneMQTTClient/CayenneMQTTClient.c:158:2: warning: implicit declaration of function ‘utoa’ [-Wimplicit-function-declaration]
utoa(value, str, 10);
^
/Users/JoseZarco/Documents/Arduino/libraries/CayenneMQTT/src/CayenneMQTTClient/CayenneMQTTClient.c: In function ‘CayenneMQTTPublishDataLong’:
/Users/JoseZarco/Documents/Arduino/libraries/CayenneMQTT/src/CayenneMQTTClient/CayenneMQTTClient.c:181:2: warning: implicit declaration of function ‘ltoa’ [-Wimplicit-function-declaration]
ltoa(value, str, 10);
^
/Users/JoseZarco/Documents/Arduino/libraries/CayenneMQTT/src/CayenneMQTTClient/CayenneMQTTClient.c: In function ‘CayenneMQTTPublishDataULong’:
/Users/JoseZarco/Documents/Arduino/libraries/CayenneMQTT/src/CayenneMQTTClient/CayenneMQTTClient.c:204:2: warning: implicit declaration of function ‘ultoa’ [-Wimplicit-function-declaration]
ultoa(value, str, 10);
^
/Users/JoseZarco/Documents/Arduino/libraries/CayenneMQTT/src/CayenneMQTTClient/CayenneMQTTClient.c: In function ‘CayenneMQTTPublishDataDouble’:
/Users/JoseZarco/Documents/Arduino/libraries/CayenneMQTT/src/CayenneMQTTClient/CayenneMQTTClient.c:227:2: warning: implicit declaration of function ‘dtostrf’ [-Wimplicit-function-declaration]
dtostrf(value, 5, 3, str);
^
/Users/JoseZarco/Documents/Arduino/libraries/CayenneMQTT/src/CayenneUtils/CayenneDataArray.c: In function ‘CayenneDataArrayAddInt’:
/Users/JoseZarco/Documents/Arduino/libraries/CayenneMQTT/src/CayenneUtils/CayenneDataArray.c:87:2: warning: implicit declaration of function ‘itoa’ [-Wimplicit-function-declaration]
itoa(value, str, 10);
^
/Users/JoseZarco/Documents/Arduino/libraries/CayenneMQTT/src/CayenneUtils/CayenneDataArray.c: In function ‘CayenneDataArrayAddUInt’:
/Users/JoseZarco/Documents/Arduino/libraries/CayenneMQTT/src/CayenneUtils/CayenneDataArray.c:105:2: warning: implicit declaration of function ‘utoa’ [-Wimplicit-function-declaration]
utoa(value, str, 10);
^
/Users/JoseZarco/Documents/Arduino/libraries/CayenneMQTT/src/CayenneUtils/CayenneDataArray.c: In function ‘CayenneDataArrayAddLong’:
/Users/JoseZarco/Documents/Arduino/libraries/CayenneMQTT/src/CayenneUtils/CayenneDataArray.c:123:2: warning: implicit declaration of function ‘ltoa’ [-Wimplicit-function-declaration]
ltoa(value, str, 10);
^
/Users/JoseZarco/Documents/Arduino/libraries/CayenneMQTT/src/CayenneUtils/CayenneDataArray.c: In function ‘CayenneDataArrayAddULong’:
/Users/JoseZarco/Documents/Arduino/libraries/CayenneMQTT/src/CayenneUtils/CayenneDataArray.c:141:2: warning: implicit declaration of function ‘ultoa’ [-Wimplicit-function-declaration]
ultoa(value, str, 10);
^
/Users/JoseZarco/Documents/Arduino/libraries/CayenneMQTT/src/CayenneUtils/CayenneDataArray.c: In function ‘CayenneDataArrayAddDouble’:
/Users/JoseZarco/Documents/Arduino/libraries/CayenneMQTT/src/CayenneUtils/CayenneDataArray.c:159:2: warning: implicit declaration of function ‘dtostrf’ [-Wimplicit-function-declaration]
dtostrf(value, 5, 3, str);
^
/Users/JoseZarco/Documents/Arduino/libraries/CayenneMQTT/src/CayenneUtils/CayenneUtils.c: In function ‘buildSuffix’:
/Users/JoseZarco/Documents/Arduino/libraries/CayenneMQTT/src/CayenneUtils/CayenneUtils.c:88:15: warning: assignment discards ‘const’ qualifier from pointer target type
topicString = COMMAND_STRING;
^
/Users/JoseZarco/Documents/Arduino/libraries/CayenneMQTT/src/CayenneUtils/CayenneUtils.c:91:15: warning: assignment discards ‘const’ qualifier from pointer target type
topicString = DATA_STRING;
^
/Users/JoseZarco/Documents/Arduino/libraries/CayenneMQTT/src/CayenneUtils/CayenneUtils.c:94:15: warning: assignment discards ‘const’ qualifier from pointer target type
topicString = RESPONSE_STRING;
^
/Users/JoseZarco/Documents/Arduino/libraries/CayenneMQTT/src/CayenneUtils/CayenneUtils.c:97:15: warning: assignment discards ‘const’ qualifier from pointer target type
topicString = SYS_MODEL_STRING;
^
/Users/JoseZarco/Documents/Arduino/libraries/CayenneMQTT/src/CayenneUtils/CayenneUtils.c:100:15: warning: assignment discards ‘const’ qualifier from pointer target type
topicString = SYS_VERSION_STRING;
^
/Users/JoseZarco/Documents/Arduino/libraries/CayenneMQTT/src/CayenneUtils/CayenneUtils.c:103:15: warning: assignment discards ‘const’ qualifier from pointer target type
topicString = SYS_CPU_MODEL_STRING;
^
/Users/JoseZarco/Documents/Arduino/libraries/CayenneMQTT/src/CayenneUtils/CayenneUtils.c:106:15: warning: assignment discards ‘const’ qualifier from pointer target type
topicString = SYS_CPU_SPEED_STRING;
^
/Applications/Arduino.app/Contents/Java/libraries/WiFi/src/utility/wifi_drv.cpp: In static member function ‘static uint8_t WiFiDrv::getEncTypeNetowrks(uint8_t)’:
/Applications/Arduino.app/Contents/Java/libraries/WiFi/src/utility/wifi_drv.cpp:451:10: warning: converting to non-pointer type ‘uint8_t {aka unsigned char}’ from NULL [-Wconversion-null]
return NULL;
^
/Applications/Arduino.app/Contents/Java/libraries/WiFi/src/utility/wifi_drv.cpp: In static member function ‘static int32_t WiFiDrv::getRSSINetoworks(uint8_t)’:
/Applications/Arduino.app/Contents/Java/libraries/WiFi/src/utility/wifi_drv.cpp:476:10: warning: converting to non-pointer type ‘int32_t {aka long int}’ from NULL [-Wconversion-null]
return NULL;
^

But it finally loads and runs the code, because in the Serial Monitor I can see it is working: It starts, connects to my wifi, tries to connect to mitt.mydevices.com:1883 and the answer is always Network connect failed. This is the output of the Serial Monitor:

[0] Connecting to My_Wifi
[10000] Connected to WiFi
[10001] IP: 192.168.1.135
[10002] Connecting to mqtt.mydevices.com:1883
[21039] Network connect failed
[32041] Network connect failed
[43042] Network connect failed
[55044] Network connect failed
No Socket available
[56045] Network connect failed
No Socket available
[57047] Network connect failed
No Socket available
[58048] Network connect failed
No Socket available
[59048] Network connect failed
No Socket available
[60050] Network connect failed
No Socket available

What am I doing wrong?

Thanks in advance for the help


#2

@josezarcotorres,

It is very difficult to diagnose an error stream without knowing a lot more detail. Here are some questions, please answer thoroughly and I can try to help.

What Wifi Shield are you using? There are several and the sketch you use will be different based on which shield you bought.

Have you removed or moved out of the Arduino library folder all previous Cayenne libs? If you have multiple Cayenne libs, the compiler guesses which one you wanted and that’s not good.

Grab the Cayenne MQTT Arduino library and unzip the folder into libraries . It can be found here. https://github.com/myDevicesIoT/Cayenne-MQTT-Arduino

Select the correct example sketch from the Connections folder for your Shield.

Add your MQTT and Wifi credentials to the sketch.

Make sure you select the Uno board, and try to compile your sketch.

If it compiles, upload it to your Uno, and give it a whizzzz.

If the above steps work, and you are sure that you selected the right sketch, then I would check and see if your router is blocking port 1883.

Cheers,

Craig


#3

Hi Kreggly

I’m using an Arduino WiFi Shield (https://store.arduino.cc/arduino-wifi-shield) And the Arduino board is an UNO R3.

I have erased all the libraries and unzipped the one you have said on libraries folder. I have selected the example: Connections - WiFi Shield, I’ve modified the Wifi and MQTT credentials and compiled it. Now it gives fewer errors:

In file included from /Users/JoseZarco/Documents/Arduino/libraries/Cayenne-MQTT-Arduino-master/src/CayenneMQTTWiFiClient.h:21:0,
from /Users/JoseZarco/Documents/Arduino/libraries/Cayenne-MQTT-Arduino-master/src/CayenneMQTTWiFi.h:26,
from /var/folders/ls/d2yx8jn577d160170ny3nqhr0000gn/T/arduino_modified_sketch_765484/WiFiShield.ino:15:
/Users/JoseZarco/Documents/Arduino/libraries/Cayenne-MQTT-Arduino-master/src/CayenneArduinoMQTTClient.h: In member function ‘void CayenneArduinoMQTTClient::connect()’:
/Users/JoseZarco/Documents/Arduino/libraries/Cayenne-MQTT-Arduino-master/src/CayenneArduinoMQTTClient.h:58:63: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
if (!NetworkConnect(&_network, CAYENNE_DOMAIN, CAYENNE_PORT)) {
^
In file included from /Users/JoseZarco/Documents/Arduino/libraries/Cayenne-MQTT-Arduino-master/src/CayenneMQTTWiFi.h:26:0,
from /var/folders/ls/d2yx8jn577d160170ny3nqhr0000gn/T/arduino_modified_sketch_765484/WiFiShield.ino:15:
/Users/JoseZarco/Documents/Arduino/libraries/Cayenne-MQTT-Arduino-master/src/CayenneMQTTWiFiClient.h: In member function ‘void CayenneMQTTWiFiClient::begin(const char*, const char*, const char*, const char*, const char*)’:
/Users/JoseZarco/Documents/Arduino/libraries/Cayenne-MQTT-Arduino-master/src/CayenneMQTTWiFiClient.h:53:33: warning: invalid conversion from ‘const char*’ to ‘char*’ [-fpermissive]
WiFi.begin(ssid, wifiPassword);
^
In file included from /Users/JoseZarco/Documents/Arduino/libraries/Cayenne-MQTT-Arduino-master/src/CayenneMQTTWiFi.h:24:0,
from /var/folders/ls/d2yx8jn577d160170ny3nqhr0000gn/T/arduino_modified_sketch_765484/WiFiShield.ino:15:
/Applications/Arduino.app/Contents/Java/libraries/WiFi/src/WiFi.h:79:9: note: initializing argument 1 of ‘int WiFiClass::begin(char*, const char*)’
int begin(char* ssid, const char passphrase);
^
In file included from /Users/JoseZarco/Documents/Arduino/libraries/Cayenne-MQTT-Arduino-master/src/CayenneMQTTWiFi.h:26:0,
from /var/folders/ls/d2yx8jn577d160170ny3nqhr0000gn/T/arduino_modified_sketch_765484/WiFiShield.ino:15:
/Users/JoseZarco/Documents/Arduino/libraries/Cayenne-MQTT-Arduino-master/src/CayenneMQTTWiFiClient.h:56:19: warning: invalid conversion from 'const char
’ to ‘char*’ [-fpermissive]
WiFi.begin(ssid);
^
In file included from /Users/JoseZarco/Documents/Arduino/libraries/Cayenne-MQTT-Arduino-master/src/CayenneMQTTWiFi.h:24:0,
from /var/folders/ls/d2yx8jn577d160170ny3nqhr0000gn/T/arduino_modified_sketch_765484/WiFiShield.ino:15:
/Applications/Arduino.app/Contents/Java/libraries/WiFi/src/WiFi.h:60:9: note: initializing argument 1 of ‘int WiFiClass::begin(char*)’
int begin(char* ssid);

But if I try to upload it the output on the Serial Monitor is exactly the same. I have checked my router and it doesn’t seem to be blocking the port.

Thanks for your help.

Jose


#4

@josezarcotorres,

That’s more like it. Let’s see your sketch now.

Looks like it is complaining about your SSID string.

Cheers,

Craig


#5

@josezarcotorres,

Should be this one.

If you don’t have a wifi password, you still need to have the variable assigned, but assign it like this, char wifiPassword[] = “”;

Cheers,

Craig

/*
This example shows how to connect to Cayenne using a WiFi shield and send/receive sample data.
The CayenneMQTT Library is required to run this sketch. If you have not already done so you can install it from the Arduino IDE Library Manager.
Steps:
1. Set the Cayenne authentication info to match the authentication info from the Dashboard.
2. Set the network name and password.
3. Compile and upload the sketch.
4. A temporary widget will be automatically generated in the Cayenne Dashboard. To make the widget permanent click the plus sign on the widget.
*/

//#define CAYENNE_DEBUG       // Uncomment to show debug messages
#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include <CayenneMQTTWiFi.h>

// WiFi network info.
char ssid[] = "ssid";
char wifiPassword[] = "wifiPassword";

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "MQTT_USERNAME";
char password[] = "MQTT_PASSWORD";
char clientID[] = "CLIENT_ID";

void setup() {
	Serial.begin(9600);
	Cayenne.begin(username, password, clientID, ssid, wifiPassword);
}

void loop() {
	Cayenne.loop();
}

// Default function for sending sensor data at intervals to Cayenne.
// You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data.
CAYENNE_OUT_DEFAULT()
{
	// Write data to Cayenne here. This example just sends the current uptime in milliseconds on virtual channel 0.
	Cayenne.virtualWrite(0, millis());
	// Some examples of other functions you can use to send data.
	//Cayenne.celsiusWrite(1, 22.0);
	//Cayenne.luxWrite(2, 700);
	//Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
}

// Default function for processing actuator commands from the Cayenne Dashboard.
// You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
CAYENNE_IN_DEFAULT()
{
	CAYENNE_LOG("Channel %u, value %s", request.channel, getValue.asString());
	//Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError("Error message");
}