Jump to content

question about WifiAssocStatus() and reinitialization


wetpaste

Recommended Posts

I am playing around with some of the library functions and I have a little loop that is supposed to establish a connection to an access point. It looks like this:

 

int simpleWFCconnect(){ // simple WFC connect:
	Wifi_AutoConnect(); // request connect
	while(1) {
		int i=Wifi_AssocStatus(); // check status
		if(i==ASSOCSTATUS_ASSOCIATED) {
			iprintf("Connected successfully! With IP %lu\n", Wifi_GetIP());
			return 0;
		}
		if(i==ASSOCSTATUS_CANNOTCONNECT) {
			iprintf("Could not connect! Press \"A\" to try again\n");
			iprintf("\"B\" to cancel\n");
			while (1){
				scanKeys();
				u16 keys = keysDown();
				if (keys & KEY_A){
				/* note: I am just trying this to see if it fixes the problem with the Wifi_AssocStatus function */
					Wifi_DisconnectAP();

					return simpleWFCconnect();
				}
				if (keys & KEY_B){
					return -1;
				}
			}
		}
	}
}

 

If the operation fails because it couldn't connect, I would like it to ask the user if they would like to try connecting again (i do this recursively, maybe there is a better way). The problem is, that after it fails once, I try to connect and the associated status is not updated. This sends me immediately into the second conditional. I'm not exactly sure where I am going wrong, any ideas? I also tried adding Wifi_DisconnectAP() (as can be seen in the code example) to see if this would bring things back to a normal state.

 

 

-thanks

Link to comment
Share on other sites

  • 4 months later...

I don't see a problem with your implementation, so I have to ask a few questions (some may be silly, but if I don't ask then I can't be sure).

 

Can you connect to your access point with other homebrew?

 

The auto connect function you are using assumes you have the wifi information stored in the firmware from a retail game, is this true for you and if so can you connect with retail games?

 

Have you tried using a different access point?

 

If your answer to these is yes, then have you initialized your IRQ's properly as demonstrated in the wifi example? Like so:

 

int wifi_connect(){


 // send fifo message to initialize the arm7 wifi
	REG_IPC_FIFO_CR = IPC_FIFO_ENABLE | IPC_FIFO_SEND_CLEAR; // enable & clear FIFO

	u32 Wifi_pass= Wifi_Init(WIFIINIT_OPTION_USELED);
	REG_IPC_FIFO_TX=0x12345678;
	REG_IPC_FIFO_TX=Wifi_pass;

	*((volatile u16 *)0x0400010E) = 0; // disable timer3

	//irqInit(); 
	irqSet(IRQ_TIMER3, Timer_50ms); // setup timer IRQ
	irqEnable(IRQ_TIMER3);
	irqSet(IRQ_FIFO_NOT_EMPTY, arm9_fifo); // setup fifo IRQ
	irqEnable(IRQ_FIFO_NOT_EMPTY);

	REG_IPC_FIFO_CR = IPC_FIFO_ENABLE | IPC_FIFO_RECV_IRQ; // enable FIFO IRQ
	Wifi_SetSyncHandler(arm9_synctoarm7); // tell wifi lib to use our handler to notify arm7

	// set timer3
	*((volatile u16 *)0x0400010C) = -6553; // 6553.1 * 256 cycles = ~50ms;
	*((volatile u16 *)0x0400010E) = 0x00C2; // enable, irq, 1/256 clock

	while(Wifi_CheckInit()==0) { // wait for arm7 to be initted successfully
		while(VCOUNT>192); // wait for vblank
		while(VCOUNT<192);
	}

	// simple WFC connect:
	int i;
	Wifi_AutoConnect(); // request connect
	while(1) {
		i=Wifi_AssocStatus(); // check status
		if(i==ASSOCSTATUS_ASSOCIATED) {
			break;
		}
		if(i==ASSOCSTATUS_CANNOTCONNECT) {
			iprintf("Could not connect!\n");
			return 0;
			break;
		}
	}	
return 1;
}

Link to comment
Share on other sites

Yes, those are all true. It is a strange situation. It does work sometimes. I noticed this because i was in an area with about 20 access points with the same name, when it tried to connect to one of the weaker ones, it would fail, so i wanted some kind of way to try again, but when I call it again, it immediately fails. This also happens when im on my home wifi sometimes, where it can be weak in certain parts of the house. But if there is a single strong connection, i can connect, no problem there. It is just strange because when i call WifiAssocStatus again after trying to connect again after a failed attempt, it immediately exits with the same failure status, rather than going through the whole connection process. Basically im saying that the status doesn't seem to reset when you use autoconnect for the second time. I thought of resetting it manually somehow but that seems hackish at best.

 

EDIT: if you want to see what i mean, try putting a loop around the last part of your example that asks if you want to try again, like i was doing. On first connection attempt, put the DS in the fridge. Then it will fail, then try again out of the fridge and see if it tries to connect again, or if it restarts immediately.

Edited by wetpaste
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...