I have a server set up on a remote computer, and allowed for remote connections through TCP on a specified port. I'm trying to connect to it using the WiFi101.h library and the client.connect().
However, this only works when the MKR1000 is connected to the Wifi that obtains its IP from the same router as that of the server I'm trying to connect to. When it's connected to another Wifi (and thus has a different IP address), it cannot establish the connection to the server. And I confirmed that the connection is alive through https://w3dt.net/tools/tcping. I can also access the server from my mac under the same Wifi/IP connection; I just can't seem to connect to it from the MKR1000.
#include <SPI.h>
#include <WiFi101.h>
char ssid[] = "***"; // your network SSID (name)
int status = WL_IDLE_STATUS;
IPAddress server(*.*.*.*);
WiFiClient client;
void setup() {
delay(2000);
Serial.begin(9600);
Serial.println("Attempting to connect to WPA network...");
Serial.print("SSID: ");
Serial.println(ssid);
status = WiFi.begin(ssid);
if ( status != WL_CONNECTED) {
Serial.println("Couldn't get a wifi connection");
// don't do anything else:
while(true);
}
else {
Serial.println("Connected to wifi");
Serial.println("\nStarting connection...");
// if you get a connection, report back via serial:
if (client.connect(server, ****)) {
Serial.println("connected");
client.println();
client.flush();
}
}
}
void loop() {
}
Serial monitor output when it fails to connect:
Attempting to connect to WPA network...
SSID: ***
Connected to wifi
Starting connection...
Serial monitor output connected to the Wifi with same router:
Attempting to connect to WPA network...
SSID: ***
Connected to wifi
Starting connection...
connected
How can I successfully connect to the server from any IP from the MKR1000? What am I doing wrong here?