示例#1
0
void RSSIProcessed::readFromFile(QXmlStreamReader* xmlReader){
    //all we know upon entering the function is that the current token is <RSSI>
    QString m, e;
    while(!(xmlReader->isEndElement()) || !(xmlReader->name() == "RSSI")){

        if (xmlReader->isStartElement()){
            if(xmlReader->name() == "MACAddress"){
                xmlReader->readNext();
                m = xmlReader->text().toString();
                xmlReader->readNext();
            }else if(xmlReader->name() == "AverageSignalStrength"){
                xmlReader->readNext();
                averageStrength = xmlReader->text().toString().toInt();
                xmlReader->readNext();
            }else if(xmlReader->name() == "StandardDeviation"){
                xmlReader->readNext();
                standardDeviation = xmlReader->text().toString().toInt();
                xmlReader->readNext();
            }else if(xmlReader->name() == "ESSID"){
                xmlReader->readNext();
                e = xmlReader->text().toString();
                xmlReader->readNext();
            }
            xmlReader->readNext();
        }else{
            xmlReader->readNext();
        }
    }
    //on the return from this function, all we know is that the token is </RSSI>
    ap = AccessPoint(m, e);
}
示例#2
0
void MeshishNode::_scanAndConnect()
{
  if (_debug)
  {
    _serial->println("scan start...");
  }

  _numNetworks = min(WiFi.scanNetworks(), MESHISH_MAX_AP_SCAN);

  if (_debug)
  {
    _serial->print(_numNetworks);
    _serial->println(" networks found in scan");
  }

  // the index of the node with the highest rssi
  int maxDBmPrimary = -1;

  for (int i = 0; i < _numNetworks; i++)
  {
    _apList[i] = AccessPoint();
    _apList[i].ssid     = WiFi.SSID(i);
    _apList[i].rssi     = WiFi.RSSI(i);
    _apList[i].encrypt  = WiFi.encryptionType(i);
    _apList[i].nodeType = _getNodeType(_apList[i]);

    if (_apList[i].nodeType == NODE_PRIMARY)
    {
      if (maxDBmPrimary == -1)
      {
        maxDBmPrimary = i;
      }
      else
      {
        if (_apList[i].rssi > _apList[maxDBmPrimary].rssi)
        {
          maxDBmPrimary = i;
        }
      }
    }

    if (_debug)
    {
      _serial->print(_apList[i].ssid);
      _serial->print("\t");
      _serial->print(_apList[i].rssi);
      _serial->print("dBm\t");
      _serial->print("Encryption: ");
      _serial->print(_apList[i].encrypt);
      _serial->print("\tnodeType: ");
      _serial->println(_apList[i].nodeType);
    }
  }

  if (maxDBmPrimary != -1)
  {
    if (_debug)
    {
      _serial->print("MeshishNode::_scanAndConnect: connecting to ");
      _serial->println(_apList[maxDBmPrimary].ssid.c_str());
    } 

    if (_password.equals("")) WiFi.begin(_apList[maxDBmPrimary].ssid.c_str());
    else WiFi.begin(_apList[maxDBmPrimary].ssid.c_str(), _password.c_str());

    _connectingToAP = true;
  }
}