Wlan.useConnectionConfig(1)

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
AkumaATR
Posts: 11
Joined: Sun Oct 30, 2005 1:07 am

Wlan.useConnectionConfig(1)

Post by AkumaATR »

My app. seems to hang sometimes during this call... any ideas as to why? I have to hard reset when it happens. It only happens like 1/5. Thanks.
AkumaATR
Posts: 11
Joined: Sun Oct 30, 2005 1:07 am

Post by AkumaATR »

After searching I see that it's advised to have power save off for WiFi for WiFi homebrew. I'll use this setting for today to see if I have any improvements... although it's worth noting that if it didn't freeze at useConnectionConfig(1) it did work for the rest of my app's duration (and it continues to make connections). Perhaps Wlan.useConnectionConfig() doesn't wait long enough for something to come out of power save mode?
wombot
Posts: 5
Joined: Tue Jan 10, 2006 10:37 am

Post by wombot »

I've been having the same problem with 0.16. 0.15 still seems to work fine for me though... maybe something broke in the update (even the 0.16 demo locks up, and I have powersave off)
modsyn
Posts: 28
Joined: Tue Sep 27, 2005 6:02 am

Post by modsyn »

i had a similar issue with 0.16 and it seems that the function Wlan.useConnectionConfig() behaves differently for the 2 versions. it's mentioned in the changes. i just added one to the index value i wanted to use and it worked fine after that. like so:

Code: Select all

function chooseNetwork()
  Wlan.init()
  configs = Wlan.getConnectionConfigs()
  local name,nstate = choose("Select a Network Connection",configs)
  if not quit then
    nstate=nstate+1
    gprintln("Using network connection " .. nstate)
    Wlan.useConnectionConfig(tonumber(nstate))
  end
end
wombot
Posts: 5
Joined: Tue Jan 10, 2006 10:37 am

Post by wombot »

Well will you look at that. Obviously I didn't read the changenotes cloesly enough. Thanks!

Strangely enough the WLAN example script still seems to lock up (my own code works though...)
Elxx
Posts: 16
Joined: Wed Dec 07, 2005 4:48 pm
Contact:

Post by Elxx »

Yes, it appears that scripts completely freeze if they are unable to connect to the wireless network, and you have to restart LuaPlayer.

There needs to be a way to have a check of whether the connection succeeded or not, allowing us to try again if not.
AkumaATR
Posts: 11
Joined: Sun Oct 30, 2005 1:07 am

Post by AkumaATR »

Agreed. I had already modified it to use connection+1.
Elxx
Posts: 16
Joined: Wed Dec 07, 2005 4:48 pm
Contact:

Post by Elxx »

Okay, I modified the LuaPlayer source code so it doesn't lock up when it's unable to connect. No idea how to do the fancy SVN submission thingee though, if I figure that out later I'll submit it as a patch.
Oobles
Site Admin
Posts: 347
Joined: Sat Jan 17, 2004 9:49 am
Location: Melbourne, Australia
Contact:

Post by Oobles »

If your patch is simple then paste it into a message here and someone with commit access with put it into svn.

David. aka Oobles.
www.livemedia.com.au/Blog
Elxx
Posts: 16
Joined: Wed Dec 07, 2005 4:48 pm
Contact:

Post by Elxx »

Here's the fixed useConnectionConfig function. It will return nil if it was unable to connect to the network. Otherwise, if it succeeds, it will return 1.

So yeah, somebody please commit this into SVN, the current connection function is aggravating because you have to completely restart the app if it fails to connect. I've been testing my new function with PSP-HTTPD and it seems to work well, it hasn't frozen up at all yet.

I moved the sceKernelDelayThread to the top of the while{} just to give it at least a bit of time to initialize, otherwise it might return nil before the WLAN connection gets a chance to try connecting.

Code: Select all

static int Wlan_useConnectionConfig(lua_State* L)
{
	if (!wlanInitialized) return luaL_error(L, wlanNotInitialized);
	int argc = lua_gettop(L); 
	if (argc != 1) return luaL_error(L, "Argument error: index to connection config expected."); 
	
	int connectionConfig = luaL_checkint(L, 1) - 1;
	int result = sceNetApctlConnect(connectionConfig);

	int state = 0;

	while (1)
	{
		sceKernelDelayThread(200*1000); // 200ms

		int err = sceNetApctlGetState(&state);
		if (err != 0)
			return 0;

		if (state == 0)
			return 0;

		if (state == 4) { //connection succeeded
			result = 1;
			break;
		}

	}

	lua_pushnumber(L, result);

	return 1;
}
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

Elxx wrote:Here's the fixed useConnectionConfig function. It will return nil if it was unable to connect to the network. Otherwise, if it succeeds, it will return 1.
Thanks, I've committed it to the SVN repository.
Post Reply