Asking for wifi status

Post Reply
lazyprogramer
Posts: 85
Joined: Mon Sep 27, 2010 5:26 pm

Asking for wifi status

Post by lazyprogramer » Sat Oct 16, 2010 10:56 am

How can I ask for the wifi status ?
(perfect, good, okay, bad no wifi)

Lakedaemon
Posts: 4
Joined: Mon Aug 16, 2010 8:48 pm

Re: Asking for wifi status

Post by Lakedaemon » Mon Oct 18, 2010 9:35 pm

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);

lazyprogramer
Posts: 85
Joined: Mon Sep 27, 2010 5:26 pm

Re: Asking for wifi status

Post by lazyprogramer » Tue Oct 19, 2010 1:20 pm

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:

lazyprogramer
Posts: 85
Joined: Mon Sep 27, 2010 5:26 pm

Re: Asking for wifi status

Post by lazyprogramer » Tue Oct 19, 2010 6:17 pm

These are the errors:
Attachments
errors.jpg
errors
(118.15 KiB) Not downloaded yet

RyouArashi
Posts: 29
Joined: Sun Mar 29, 2009 9:23 pm

Re: Asking for wifi status

Post by RyouArashi » Tue Oct 19, 2010 8:16 pm

@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.

lazyprogramer
Posts: 85
Joined: Mon Sep 27, 2010 5:26 pm

Re: Asking for wifi status

Post by lazyprogramer » Wed Oct 20, 2010 12:12 pm

@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:
Attachments
errors2.jpg
errors
(210.54 KiB) Not downloaded yet

zeromus
Posts: 212
Joined: Wed Mar 31, 2010 6:05 pm

Re: Asking for wifi status

Post by zeromus » Thu Oct 21, 2010 6:39 am

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

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Semrush [Bot] and 0 guests