Wi-Fi connection timeout?

Moderators: lily.li, violet, salmanfarisvp

Post Reply
squeck94
Pre-kindergarten
Pre-kindergarten
Posts: 7
Joined: Wed Nov 26, 2014 3:20 am

Wi-Fi connection timeout?

Post by squeck94 » Wed Nov 26, 2014 3:49 am

Hello everybody,

I'm connecting to some TCP servers using my new LinkIt ONE and the LWiFiClient class.

The .connect() method returns 1 if it connects to the IP address I specified, but if the IP address doesn't exists or doesn't accept connections (for example, if the server is down) it doesn't return anything and the code gets stuck there. I assume it should timeout then return 0 as per the documentation.

Example:

Code: Select all

int conn = c.connect("192.168.1.5", 8080);
if(conn == 1){
     ...
} else {
     ...
}
If 192.168.1.5 is down, c.connect doesn't return anything and I can't get into the else branch.

Any ideas on how to solve this?

Thank you

squeck94
Pre-kindergarten
Pre-kindergarten
Posts: 7
Joined: Wed Nov 26, 2014 3:20 am

Re: Wi-Fi connection timeout?

Post by squeck94 » Fri Nov 28, 2014 7:37 am

Update: It looks like it's working and it was only my fault. I had a boolean variable named "connected" that conflicted with the LWifiClient which also has a .connected() function.

Everything is working fine now.

User avatar
loovee
Elementary-3
Elementary-3
Posts: 352
Joined: Fri Nov 02, 2012 9:15 am

Re: Wi-Fi connection timeout?

Post by loovee » Sun Dec 07, 2014 10:42 am

nice~ :D

squeck94
Pre-kindergarten
Pre-kindergarten
Posts: 7
Joined: Wed Nov 26, 2014 3:20 am

Re: Wi-Fi connection timeout?

Post by squeck94 » Thu Dec 18, 2014 7:11 am

I have problems trying to do the opposite now: I want the LinkIt to be a TCP server and receive commands from clients.

This is my code, based on the mediatek documentation (sadly there are no working examples), but I can't understand why it doesn't work.

It connects to the Wi-Fi just fine, yet it refuses all the connections by the clients.

Code: Select all

#include <LWiFi.h>
#include <LWiFiClient.h>
#include <LWiFiServer.h>

#define AP_NAME "TP-LINK"
#define PASSWORD "mypassword"
#define PORT 8080

boolean first = true;


LWiFiClient c;
LWiFiServer server(8080);

void setup() {
	Serial.begin(9600);
	LWiFi.begin();
	LWiFi.connectWPA(AP_NAME, PASSWORD);
	Serial.println("Connected to Wi-Fi!");
	server.begin();
}

void loop() {
	if(first){
		c = server.available();
		first = false;
	}
	if(c.available()){
		char ch = c.read();
		Serial.print(ch);
	}
	delay(1000);
}
Any ideas on how to make this work? Thank you

Post Reply