int wlan_connected_rssi() { int _returnValue = 0; system_tick_t _functionStart = HAL_Timer_Get_Milli_Seconds(); while ((HAL_Timer_Get_Milli_Seconds() - _functionStart) < 1000) { tNetappIpconfigRetArgs config; netapp_ipconfig((void*)&config); int l; for (l=0; l<16; l++) { char wlan_scan_results_table[50]; if(wlan_ioctl_get_scan_results(0, (unsigned char*)wlan_scan_results_table) != 0) { _returnValue = 1; break; } if (wlan_scan_results_table[0] == 0) break; if (!strcmp(wlan_scan_results_table+12, config.uaSSID)) { _returnValue = ((wlan_scan_results_table[8] >> 1) - 127); break; } } if (_returnValue != 0) { break; } }
/** * @brief Scans area for access points. Blocks operation to allow for scan. * * To scan for APs, first call scanAccessPoints() with an appropriate scan time * (recommended scan_time = 4000ms). Create an AccessPointInfo struct and pass * that to getNextAccessPoint(). Continue to call getNextAccessPoint() until it * returns false (there are no more APs to scan). * * @param[in] scan_time time to scan networks in milliseconds * @return True if scan succeeded. False otherwise. */ bool SFE_CC3000::scanAccessPoints(unsigned int scan_time) { int i; unsigned long channel_timeouts[SCAN_NUM_CHANNELS]; /* If CC3000 is not initialized, return false. */ if (!getInitStatus()) { return false; } /* Create channel interval list for AP scanning */ for (i = 0; i < SCAN_NUM_CHANNELS; i++) { channel_timeouts[0] = SCAN_CHANNEL_TIMEOUT; } /* Setup access point scan */ if (wlan_ioctl_set_scan_params( scan_time, SCAN_MIN_DWELL_TIME, SCAN_MAX_DWELL_TIME, SCAN_NUM_PROBE_REQS, SCAN_CHANNEL_MASK, SCAN_RSSI_THRESHOLD, SCAN_NSR_THRESHOLD, SCAN_DEFAULT_TX_POWER, channel_timeouts ) != CC3000_SUCCESS) { return false; } /* Wait for scan to complete */ delay(scan_time + 500); /* Re-initialize AP counters */ num_access_points_ = 0; access_point_count_ = 0; /* Get first scan result in order to obtain the total number of APs */ if (wlan_ioctl_get_scan_results(0, (unsigned char *)&ap_scan_result_) != CC3000_SUCCESS ){ return false; } num_access_points_ = ap_scan_result_.num_networks; /* Stop scan */ if (wlan_ioctl_set_scan_params( 0, SCAN_MIN_DWELL_TIME, SCAN_MAX_DWELL_TIME, SCAN_NUM_PROBE_REQS, SCAN_CHANNEL_MASK, SCAN_RSSI_THRESHOLD, SCAN_NSR_THRESHOLD, SCAN_DEFAULT_TX_POWER, channel_timeouts ) != CC3000_SUCCESS) { return false; } return true; }
bool WifiScan::Next(char *line, uint8_t len) { WifiScanResults_t scanResult; wipeStr(line, len); wipeStr((char *)scanResult.ssid, 32); long err = wlan_ioctl_get_scan_results(0, (uint8_t* ) &scanResult); if(err == 0) { parseScanResultToJson(scanResult, line); } else { const char *msg = (String("Error ") + String(err)).c_str(); strncpy(line, msg, strlen(msg)); } if (String(line).indexOf("00:00:00:00:00:00") >= 0) { return false; } return true; }
/** * @brief Fills out AP info struct with next access data. * * To scan for APs, first call scanAccessPoints() with an appropriate scan time * (recommended scan_time = 4000ms). Create an AccessPointInfo struct and pass * that to getNextAccessPoint(). Continue to call getNextAccessPoint() until it * returns false (there are no more APs to scan). * * @param[out] ap_info struct containing information about the next AP * @return True if next AP obtained. False if no more APs available. */ bool SFE_CC3000::getNextAccessPoint(AccessPointInfo &ap_info) { /* If CC3000 is not initialized, return false. */ if (!getInitStatus()) { return false; } /* If results are invalid (e.g. no results), return false */ if (!ap_scan_result_.is_valid) { return false; } /* If we have exhausted all of the networks to list, return false */ if (access_point_count_ >= num_access_points_) { return false; } /* Fill out AP info with last AP surveyed */ ap_info.rssi = ap_scan_result_.rssi; ap_info.security_mode = ap_scan_result_.security_mode; strncpy(ap_info.ssid, (char *)ap_scan_result_.ssid, ap_scan_result_.ssid_length); ap_info.ssid[ap_scan_result_.ssid_length] = '\0'; memcpy(ap_info.bssid, ap_scan_result_.bssid, BSSID_LENGTH); /* Get next set of results */ if (wlan_ioctl_get_scan_results(0, (unsigned char *)&ap_scan_result_) != CC3000_SUCCESS ) { return false; } /* Increment AP counter */ access_point_count_++; return true; }
void loop() { netapp_ipconfig(&ipconfig); char connectedSSID[32]; sprintf(connectedSSID, "%s", ipconfig.uaSSID); digitalWrite(ledPin1,HIGH); delay(50); digitalWrite(ledPin1,LOW); delay(50); long errParams = wlan_ioctl_set_scan_params(1000, 20, 30, 2, 0x7ff, -80, 0, 205, aiIntervalList[16]); long errResults = wlan_ioctl_get_scan_results(0, ucResults); int _numEntry = ((uint8_t) ucResults[3] << 24) | ((uint8_t) ucResults[2] << 16) | ((uint8_t) ucResults[1] << 8) | ((uint8_t) ucResults[0]); if (errParams == 0 && errResults == 0 && _numEntry > 0) { digitalWrite(ledPin2,HIGH); delay(50); digitalWrite(ledPin2,LOW); int _stat = ((uint8_t) ucResults[7] << 24) | ((uint8_t) ucResults[6] << 16) | ((uint8_t) ucResults[5] << 8) | ((uint8_t) ucResults[4]); bool _valid = (uint8_t) ucResults[8] & 0x1; int _rssi = (uint8_t) ucResults[8] >> 1; int _mode = ((uint8_t) ucResults[9] | 0xC0) & 0x3; int _ssidlen = (uint8_t) ucResults[9] >> 2; char ssid[32]; int idx = 0; while(strcmp(connectedSSID, ssid) != 0) { ssid[idx] = ucResults[idx+12]; idx++; ssid[_ssidlen] = (char) NULL; } digitalWrite(ledPin3,HIGH); delay(100); digitalWrite(ledPin3,LOW); Serial.print("WiFi scan status: "); switch (_stat) { case 0: Serial.print("aged, "); break; case 1: Serial.print("valid, "); break; case 2: Serial.print("no results, "); break; } Serial.print(_numEntry); Serial.print(" nets found. "); Serial.print(ssid); Serial1.println(ssid); if (_valid){ Serial.print(" is valid, RSSI: "); } else Serial.print("not valid, RSSI: "); Serial.print(_rssi); Serial1.println(_rssi); Serial.print(", mode: "); switch (_mode) { case 0: Serial.println("OPEN"); break; case 1: Serial.println("WEP"); break; case 2: Serial.println("WPA"); break; case 3: Serial.println("WPA2"); break; } // else { // Serial.print(connectedSSID); // Serial.print(" >______< "); // Serial.println(ssid); // } incomingByte = Serial.read(); //key press 'a' to get data if (incomingByte == 97){ Serial.println(Network.localIP()); Serial.println(Network.subnetMask()); Serial.println(Network.gatewayIP()); Serial.println(Network.SSID()); } }
void ListAccessPoints(void) { unsigned long aiIntervalList[NUM_CHANNELS]; uint8_t rval; scanResults sr; int apCounter, i; char localB[33]; if (!isInitialized) { printf("CC3000 not initialized; can't list access points.\n"); return; } printf("List visible access points\n"); printf(" Setting scan parameters...\n"); for (i=0; i<NUM_CHANNELS; i++) { aiIntervalList[i] = 2000; } rval = wlan_ioctl_set_scan_params( 1000, /* Enable start application scan */ 100, /* Minimum dwell time on each channel */ 100, /* Maximum dwell time on each channel */ 5, /* Number of probe requests */ 0x7ff, /* Channel mask */ -80, /* RSSI threshold */ 0, /* SNR threshold */ 205, /* Probe TX power */ aiIntervalList /* Table of scan intervals per channel */ ); if (rval!=0) { printf(" Got back unusual result from wlan_ioctl_set_scan_params, can't continue: %d\n", rval); return; } #if 0 printf(" Sleeping 5 seconds to let the CC3000 discover APs...\n"); usleep(5000000); #endif printf(" Getting AP count...\n"); /* On the first call to get_scan_results, sr.numNetworksFound will return the * actual # of APs currently seen. Get that # then loop through and print * out what's found. */ if ((rval=wlan_ioctl_get_scan_results(2000, (uint8_t *)&sr))!=0) { printf(" Got back unusual result from wlan_ioctl_get scan results, can't continue: %d\n", rval); return; } apCounter = sr.numNetworksFound; printf(" Number of APs found: %d\n", apCounter); do { if (sr.isValid) { printf(" "); switch (sr.securityMode) { case WLAN_SEC_UNSEC: /* 0 */ printf("OPEN "); break; case WLAN_SEC_WEP: /* 1 */ printf("WEP "); break; case WLAN_SEC_WPA: /* 2 */ printf("WPA "); break; case WLAN_SEC_WPA2: /* 3 */ printf("WPA2 "); break; } sprintf(localB, "%3u ", sr.rssi); printf("%s", localB); memset(localB, 0, 33); memcpy(localB, sr.ssid_name, sr.ssidLength); printf("%s\n", localB); } if (--apCounter>0) { if ((rval=wlan_ioctl_get_scan_results(2000, (uint8_t *)&sr)) !=0) { printf(" Got back unusual result from wlan_ioctl_get scan, can't continue: %d\n", rval); return; } } } while (apCounter>0); printf(" Access Point list finished.\n"); }
void loop() { if (client.connected()) { digitalWrite(D4,HIGH); digitalWrite(D0,HIGH); delay(200); digitalWrite(D4,LOW); digitalWrite(D0,LOW); while (client.available()) { digitalWrite(D4,HIGH); digitalWrite(D7,HIGH); delay(200); digitalWrite(D4,LOW); digitalWrite(D7,LOW); Serial.println(); int val = client.read(); Serial.println(val); netapp_ipconfig(&ipconfig); char connectedSSID[32]; sprintf(connectedSSID, "%s", ipconfig.uaSSID); digitalWrite(D7,HIGH); delay(500); digitalWrite(D7,LOW); delay(500); long err = wlan_ioctl_get_scan_results(0, ucResults); int _numEntry = ((uint8_t) ucResults[3] << 24) | ((uint8_t) ucResults[2] << 16) | ((uint8_t) ucResults[1] << 8) | ((uint8_t) ucResults[0]); if (err == 0 && _numEntry > 0) { digitalWrite(D4,HIGH); delay(100); digitalWrite(D4,LOW); int _stat = ((uint8_t) ucResults[7] << 24) | ((uint8_t) ucResults[6] << 16) | ((uint8_t) ucResults[5] << 8) | ((uint8_t) ucResults[4]); bool _valid = (uint8_t) ucResults[8] & 0x1; int _rssi = (uint8_t) ucResults[8] >> 1; int _mode = ((uint8_t) ucResults[9] | 0xC0) & 0x3; int _ssidlen = (uint8_t) ucResults[9] >> 2; char ssid[32]; int idx = 0; while(idx < _ssidlen) { ssid[idx] = ucResults[idx+12]; idx++; } ssid[_ssidlen] = (char) NULL; if (strcmp(connectedSSID, ssid) == 0){ digitalWrite(D0,HIGH); delay(100); digitalWrite(D0,LOW); Serial.print("WiFi scan status: "); server.write("WiFi scan status: "); switch (_stat) { case 0: Serial.print("aged, "); server.write("aged, "); break; case 1: Serial.print("valid, "); server.write("valid, "); break; case 2: Serial.print("no results, "); server.write("no results, "); break; } Serial.print(_numEntry); Serial.print(" nets found. "); Serial.print(ssid); server.write(_numEntry); server.write(" nets found. "); server.write(ssid); if (_valid){ Serial.print(" is valid, RSSI: "); server.write(" is valid, RSSI: "); } else{ Serial.print("not valid, RSSI: "); server.write("not valid, RSSI: "); } Serial.print(_rssi); Serial.print(", mode: "); server.write(_rssi); server.write(", mode: "); switch (_mode) { case 0: Serial.println("OPEN"); server.write("OPEN\n"); break; case 1: Serial.println("WEP"); server.write("WEP\n"); break; case 2: Serial.println("WPA"); server.write("WPA\n"); break; case 3: Serial.println("WPA2"); server.write("WPA2\n"); break; } } incomingByte = Serial.read(); //key press 'a' to get data if (incomingByte == 97){ Serial.print("local ip : "); Serial.println(Network.localIP()); Serial.print("subnet mask: "); Serial.println(Network.subnetMask()); Serial.print("gateway ip : "); Serial.println(Network.gatewayIP()); Serial.print("ssid : "); Serial.println(Network.SSID()); Serial.println(); } Serial.print(connectedSSID); Serial.print( " "); Serial.println(ssid); server.write(connectedSSID); server.write( " "); server.write(ssid); server.write("\n"); } else {