Page 1 of 1

Asking for wifi status

Posted: Sat Oct 16, 2010 10:56 am
by lazyprogramer
How can I ask for the wifi status ?
(perfect, good, okay, bad no wifi)

Re: Asking for wifi status

Posted: Mon Oct 18, 2010 9:35 pm
by Lakedaemon
you can get the signal strength in the rssi field of an ap Wifi_AccessPoint struct (in dswifi9.h).
the % of connection will be (ap.rssi * 100) / 0xD;

Here is a sample of code that tries connecting, among many access point called ssid, to the ssid access point with the best signal

Code: Select all

 
Wifi_AccessPoint ap;
  memset(&ap, 0, sizeof(ap));

  Wifi_AccessPoint bestAp;
  memset(&bestAp, 0, sizeof(bestAp));
  int oldMaxRssi = -2;
  int maxRssi = -1;
  int maxTries = 120;  // will try for a few seconds
  while ((maxRssi < 60 || oldMaxRssi < maxRssi) || maxTries > 0) {
    swiWaitForVBlank();

    // scans the surroundings for wifi Access point -> puts the info in an intern list
    Wifi_ScanMode();

    oldMaxRssi = maxRssi;
    for (int i = 0; i < Wifi_GetNumAP(); ++i) {
      if ((Wifi_GetAPData(i, &ap) == WIFI_RETURN_OK) && (ap.rssi > maxRssi) &&
        (!strcmp(ap.ssid, ssid))) {
        maxRssi = ap.rssi;
        bestAp = ap;
      }
    }
    maxTries -= 1;
  }
  if (maxRssi < 0) {
    fprintf("Can't find any %s access point", ssid);  
    return;  
  }
  fprintf("Connecting to %s (%2i%%): ", bestAp.ssid, (bestAp.rssi * 100) / 0xD0);

  // Setting the DS's IP address and other IP configuration information through DHCP.
  Wifi_SetIP(0, 0, 0, 0, 0);
  Wifi_ConnectAP(&bestAp, wepmode, wepkeyid, wepkey);

Re: Asking for wifi status

Posted: Tue Oct 19, 2010 1:20 pm
by lazyprogramer
Sorry, but when I use this code, it says me over 30 errors with "expected declaration specifers or '...' " and "data defination has no type or storange class"
and much more :cry:

Re: Asking for wifi status

Posted: Tue Oct 19, 2010 6:17 pm
by lazyprogramer
These are the errors:

Re: Asking for wifi status

Posted: Tue Oct 19, 2010 8:16 pm
by RyouArashi
@Lakedaemon:
fprintf is used incorrectly. Replace it by iprintf.

@lazyprogrammer:
use the arm9 template from the libnds examples. Also, create a copy of the template and don't just overwrite it.

Re: Asking for wifi status

Posted: Wed Oct 20, 2010 12:12 pm
by lazyprogramer
@Lakedaemon:
fprintf is used incorrectly. Replace it by iprintf.

@lazyprogrammer:
use the arm9 template from the libnds examples. Also, create a copy of the template and don't just overwrite it.
So I replaced the two "fprintf " by "iprintf" and write the code it in this path:
nintendods/devkitpro/examples/nds/template/arm9/source --> main.c
Okay, but I still have errors:

Re: Asking for wifi status

Posted: Thu Oct 21, 2010 6:39 am
by zeromus
you overwrote the template. he told you not to do that.

heres a tip about programming in C which you normally learn on the first day but you seem to have skipped.

when you get an error like "X undeclared" then search the header files for X and #include the file which contains that symbol