Skip to content

Commit 692de44

Browse files
fix WifiScanner and example
1 parent 7ceacc8 commit 692de44

File tree

4 files changed

+67
-3
lines changed

4 files changed

+67
-3
lines changed

examples/CameraWebServerExample/CameraWebServerExample.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include "eloquent/networking/wifi.h"
33
#include "eloquent/vision/camera/esp32/webserver.h"
44
// replace according to your own camera
5-
#include "eloquent/vision/camera/esp32/m5wide/jpeg/vga.h"
5+
#include "eloquent/vision/camera/esp32/m5wide/jpeg/qqvga.h"
66

77

88

examples/IndoorPositioning/WiFiScannerExample/WiFiScannerExample.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ void loop() {
3939
if (location != "" && location != "stop") {
4040
Serial.print(location);
4141
Serial.print(": ");
42+
wifiScanner.scan();
4243
wifiScanner.printAsJson(Serial);
4344
delay(2000);
4445
}

src/eloquent/networking/wifi/WifiScanner.h

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,15 @@ namespace Eloquent {
9191
* @return
9292
*/
9393
virtual String macAt(uint8_t i) {
94-
return WiFi.BSSIDstr(i);
94+
uint8_t *bssid = WiFi.BSSID(i);
95+
96+
return this->hex(bssid[0]) + ":" +
97+
this->hex(bssid[1]) + ":" +
98+
this->hex(bssid[2]) + ":" +
99+
this->hex(bssid[3]) + ":" +
100+
this->hex(bssid[4]) + ":" +
101+
this->hex(bssid[5]) + ":" +
102+
this->hex(bssid[6]);
95103
}
96104

97105
/**
@@ -114,6 +122,14 @@ namespace Eloquent {
114122
return WiFi.RSSI(i);
115123
}
116124

125+
/**
126+
* Get identifier of current network
127+
* @return
128+
*/
129+
virtual String id() {
130+
return idAt(i);
131+
}
132+
117133
/**
118134
* Get identifier of given network
119135
* @param i
@@ -129,7 +145,7 @@ namespace Eloquent {
129145
* @param stream
130146
*/
131147
template<typename Stream>
132-
virtual void printAsJson(Stream& stream) {
148+
void printAsJson(Stream& stream) {
133149
stream.print('{');
134150

135151
for (uint8_t i = 0; i < numNetworks; i++) {
@@ -151,6 +167,22 @@ namespace Eloquent {
151167
uint8_t i = 0;
152168
uint8_t numNetworks;
153169
bool useMac = false;
170+
171+
/**
172+
* Convert byte to hex string
173+
* @param byte
174+
* @return
175+
*/
176+
String hex(uint8_t byte) {
177+
String alphabet = "0123456789ABCDEF";
178+
char hex[3] = {
179+
alphabet.charAt(byte >> 4),
180+
alphabet.charAt(byte & 0b1111),
181+
'\0'
182+
};
183+
184+
return String(hex);
185+
}
154186
};
155187
}
156188
}

src/eloquent/vision/image/BaseImage.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,17 @@ namespace Eloquent {
202202
_copyOnWrite = copy;
203203
}
204204

205+
/**
206+
* Cast to given type
207+
* @tparam T
208+
* @param dest
209+
*/
210+
template<typename T>
211+
void castTo(T* dest) {
212+
for (size_t i = 0; i < getLength(); i++)
213+
dest[i] = (T) buffer[i];
214+
}
215+
205216
/**
206217
* Write raw data to image container
207218
* @param buffer
@@ -230,6 +241,26 @@ namespace Eloquent {
230241
size_t writeTo(Writer writer) {
231242
return writer.write(buffer, getLength());
232243
}
244+
245+
/**
246+
*
247+
* @tparam Printer
248+
* @param printer
249+
* @param separator
250+
* @param end
251+
* @return
252+
*/
253+
template<typename Printer>
254+
void printTo(Printer printer, char separator = ',', char end = '\n') {
255+
printer.print(at(0));
256+
257+
for (size_t i = 1; i < 30; i++) {
258+
printer.print(separator);
259+
printer.print(at(i));
260+
}
261+
262+
printer.print(end);
263+
}
233264

234265
/**
235266
* Print as json

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy