MCPcopy Create free account
hub / github.com/cifertech/nRFBox / wifiscanLoop

Function wifiscanLoop

nRFBox_V2/wifiscan.cpp:62–148  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

60}
61
62void wifiscanLoop() {
63 unsigned long currentMillis = millis();
64
65 if (!isScanComplete && currentMillis - scan_StartTime < scanTimeout) {
66 int foundNetworks = WiFi.scanNetworks();
67 if (foundNetworks >= 0) {
68 isScanComplete = true;
69 }
70 }
71
72 if (currentMillis - lastButtonPress > debounceTime) {
73 if (digitalRead(BTN_PIN_UP) == LOW) {
74 if (currentIndex > 0) {
75 currentIndex--;
76 if (currentIndex < listStartIndex) {
77 listStartIndex--;
78 }
79 }
80 lastButtonPress = currentMillis;
81 } else if (digitalRead(BTN_PIN_DOWN) == LOW) {
82 if (currentIndex < WiFi.scanComplete() - 1) {
83 currentIndex++;
84 if (currentIndex >= listStartIndex + 5) {
85 listStartIndex++;
86 }
87 }
88 lastButtonPress = currentMillis;
89 } else if (digitalRead(BTN_PIN_SELECT) == LOW) {
90 isDetailView = true;
91 lastButtonPress = currentMillis;
92 }
93 }
94
95 if (!isDetailView && isScanComplete) {
96 u8g2.clearBuffer();
97 u8g2.setFont(u8g2_font_6x10_tr);
98 u8g2.drawStr(0, 10, "Wi-Fi Networks:");
99
100 int networkCount = WiFi.scanComplete();
101 for (int i = 0; i < 5; i++) {
102 int currentNetworkIndex = i + listStartIndex;
103 if (currentNetworkIndex >= networkCount) break;
104
105 String networkName = WiFi.SSID(currentNetworkIndex);
106 int rssi = WiFi.RSSI(currentNetworkIndex);
107
108 String networkInfo = networkName.substring(0, 7);
109 String networkrssi = " | RSSI " + String(rssi);
110
111 if (currentNetworkIndex == currentIndex) {
112 u8g2.drawStr(0, 20 + i * 10, ">");
113 }
114 u8g2.drawStr(10, 20 + i * 10, networkInfo.c_str());
115 u8g2.drawStr(50, 20 + i * 10, networkrssi.c_str());
116 }
117 u8g2.sendBuffer();
118 }
119

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected