lib/RobustWifiServer/RobustWiFiServer.cpp
// check whether a state that happen asynchronously
check whether a state that happen asynchronously
check whether a state that happen asynchronously
bool RobustWiFiServer::_checkState(ServerState state, bool debug){
  bool stateok = false;
  int dataCount = 0;
  LOGV(RWIFIS, "Checking wifistate %s", wiFiStateToString().c_str());
  switch(state){
    case UNCONFIGURED:
    stateok = (wifiState == WIFI_DISCONNECTED);
    break;
    case CONNECTED:
    stateok = (wifiState == WIFI_CONNECTED);
    break;
    case SERVER_LISTENING:
    stateok = (wifiState == WIFI_CONNECTED) && _server; 
    break;
    case CLIENT_CONNECTED:
    if (!_client.connected()) {
      _client = _server.available();
    }
    stateok =  (wifiState == WIFI_CONNECTED) && _client.connected();
    break;
    case DATA_AVAILABLE:
    dataCount = _client.available();
    if (dataCount != 0) {
      _lastDataAvailableCount = dataCount;
    }
    stateok =  (wifiState == WIFI_CONNECTED) && dataCount;
    break;
    default: 
    stateok = false;
    break;
  } 
  if (state < CLIENT_CONNECTED) {
    _lastDataAvailableCount = 0; 
  }
  if (!stateok && debug) {
    _printInternalState();
  }
  return stateok;
}
bool RobustWiFiServer :: _checkState ( ServerState state , bool debug ) { bool stateok = false ; int dataCount = 0 ; LOGV ( RWIFIS , " " , wiFiStateToString ( ) . c_str ( ) ) ; switch ( state ) { case UNCONFIGURED : stateok = ( wifiState == WIFI_DISCONNECTED ) ; break ; case CONNECTED : stateok = ( wifiState == WIFI_CONNECTED ) ; break ; case SERVER_LISTENING : stateok = ( wifiState == WIFI_CONNECTED ) && _server ; break ; case CLIENT_CONNECTED : if ( ! _client . connected ( ) ) { _client = _server . available ( ) ; } stateok = ( wifiState == WIFI_CONNECTED ) && _client . connected ( ) ; break ; case DATA_AVAILABLE : dataCount = _client . available ( ) ; if ( dataCount != 0 ) { _lastDataAvailableCount = dataCount ; } stateok = ( wifiState == WIFI_CONNECTED ) && dataCount ; break ; default : stateok = false ; break ; } if ( state < CLIENT_CONNECTED ) { _lastDataAvailableCount = 0 ; } if ( ! stateok && debug ) { _printInternalState ( ) ; } return stateok ; }
check whether a state that happen asynchronously
check whether a state that happen asynchronously
// need to also check wifi status since server would not notice failing wifi // equals to is_listening() // unknown state // reset to show waiting data msg again