Skip to content

Commit c9f642b

Browse files
add identifyByMac to WifiScanner + [wip] jpeg camera
1 parent 8014626 commit c9f642b

File tree

11 files changed

+537
-14
lines changed

11 files changed

+537
-14
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include "eloquent.h"
2+
#include "eloquent/networking/wifi.h"
3+
#include "eloquent/vision/camera/esp32/webserver.h"
4+
// replace according to your own camera
5+
#include "eloquent/vision/camera/esp32/m5wide/jpeg/vga.h"
6+
7+
8+
9+
void setup() {
10+
Serial.begin(115200);
11+
12+
while (!wifi.connectTo("Abc", "12345678"))
13+
Serial.println("Cannot connect to WiFi");
14+
15+
while (!camera.begin())
16+
Serial.println("Cannot connect to camera");
17+
18+
Serial.println("WiFi connected");
19+
Serial.println("Camera connected");
20+
21+
webServer.start();
22+
Serial.print("Camera web server started at http://");
23+
Serial.println(WiFi.localIP());
24+
}
25+
26+
void loop() {
27+
28+
}

examples/IndoorPositioning/WiFiScannerExample/WiFiScannerExample.ino

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ void setup() {
2222
Serial.println("Instructions:");
2323
Serial.println("\tEnter the name of the location to start scanning");
2424
Serial.println("\tEnter 'stop' to stop scanning");
25+
26+
// you can identify networks either by MAC address
27+
wifiScanner.identifyByMAC();
28+
// or SSID (default)
29+
wifiScanner.identifyBySSID();
2530
}
2631

2732
void loop() {

src/eloquent/networking/wifi/WifiScanner.h

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@ namespace Eloquent {
1010
class WifiScanner {
1111
public:
1212

13+
/**
14+
* Identify networks by SSID
15+
*/
16+
void identifyBySSID() {
17+
useMac = false;
18+
}
19+
20+
/**
21+
* Identify networks by MAC address
22+
*/
23+
void identifyByMAC() {
24+
useMac = true;
25+
}
26+
1327
/**
1428
* Perform scan
1529
*/
@@ -41,7 +55,7 @@ namespace Eloquent {
4155
}
4256

4357
/**
44-
* Get SID of current network
58+
* Get SSID of current network
4559
* @return
4660
*/
4761
String ssid() {
@@ -60,6 +74,26 @@ namespace Eloquent {
6074
return WiFi.SSID(i);
6175
}
6276

77+
/**
78+
* Get MAC address of current network
79+
* @return
80+
*/
81+
String mac() {
82+
if (hasNext())
83+
return macAt(i);
84+
85+
return "";
86+
}
87+
88+
/**
89+
* Get Mac address of given network
90+
* @param i
91+
* @return
92+
*/
93+
String macAt(uint8_t i) {
94+
return WiFi.BSSIDstr(i);
95+
}
96+
6397
/**
6498
* Get RSSI of current network
6599
* @return
@@ -80,6 +114,15 @@ namespace Eloquent {
80114
return WiFi.RSSI(i);
81115
}
82116

117+
/**
118+
* Get identifier of given network
119+
* @param i
120+
* @return
121+
*/
122+
String idAt(uint8_t i) {
123+
return useMac ? macAt(i) : ssidAt(i);
124+
}
125+
83126
/**
84127
* Print scan results as JSON
85128
* @tparam Stream
@@ -91,7 +134,7 @@ namespace Eloquent {
91134

92135
for (uint8_t i = 0; i < numNetworks; i++) {
93136
stream.print('"');
94-
stream.print(ssidAt(i));
137+
stream.print(idAt(i));
95138
stream.print('"');
96139
stream.print(':');
97140
stream.print(rssiAt(i));
@@ -107,6 +150,7 @@ namespace Eloquent {
107150
protected:
108151
uint8_t i = 0;
109152
uint8_t numNetworks;
153+
bool useMac = false;
110154
};
111155
}
112156
}

src/eloquent/vision/camera/esp32/BaseEsp32Camera.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,46 @@ namespace Eloquent {
4141
_config.xclk_freq_hz = 10000000;
4242
}
4343

44+
/**
45+
*
46+
* @param flip
47+
*/
48+
void vflip(bool flip = true) {
49+
if (_sensor != NULL) {
50+
_sensor->set_vflip(_sensor, flip);
51+
}
52+
}
53+
54+
/**
55+
*
56+
* @param mirror
57+
*/
58+
void hmirror(bool mirror = true) {
59+
if (_sensor != NULL) {
60+
_sensor->set_hmirror(_sensor, mirror);
61+
}
62+
}
63+
64+
/**
65+
*
66+
* @param brightness
67+
*/
68+
void setBrightness(int8_t brightness) {
69+
if (_sensor != NULL) {
70+
_sensor->set_brightness(_sensor, brightness);
71+
}
72+
}
73+
74+
/**
75+
*
76+
* @param saturation
77+
*/
78+
void setSaturation(int8_t saturation) {
79+
if (_sensor != NULL) {
80+
_sensor->set_saturation(_sensor, saturation);
81+
}
82+
}
83+
4484
protected:
4585
camera_config_t _config;
4686
sensor_t *_sensor;
@@ -74,6 +114,13 @@ namespace Eloquent {
74114

75115
}
76116

117+
/**
118+
* Configure sensor
119+
*/
120+
virtual void configSensor() {
121+
122+
}
123+
77124
/**
78125
* Set camera-specific pins
79126
*
@@ -122,6 +169,8 @@ namespace Eloquent {
122169
}
123170

124171
_sensor = esp_camera_sensor_get();
172+
_sensor->set_framesize(_sensor, getFrameSize());
173+
configSensor();
125174

126175
return true;
127176
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
//
2+
// Created by Simone on 24/06/2022.
3+
//
4+
5+
#pragma once
6+
7+
#include "../../../../macros.h"
8+
#include "./m5wide.h"
9+
10+
11+
namespace Eloquent {
12+
namespace Vision {
13+
namespace Cam {
14+
namespace Esp32 {
15+
/**
16+
* M5 wide
17+
* Grayscale
18+
* QQVGA
19+
*/
20+
class BaseJpegCamera : public M5WideCamera {
21+
public:
22+
23+
/**
24+
*
25+
* @return
26+
*/
27+
virtual framesize_t getFrameSize() = 0;
28+
29+
/**
30+
*
31+
* @return
32+
*/
33+
pixformat_t getPixFormat() {
34+
return PIXFORMAT_JPEG;
35+
}
36+
37+
/**
38+
*
39+
* @param buffer
40+
*/
41+
void setFrameBuffer(uint8_t *buffer) {
42+
// do nothing
43+
}
44+
45+
/**
46+
* Set jpeg quality
47+
* @param quality
48+
*/
49+
void setQuality(uint8_t quality) {
50+
_quality = quality;
51+
}
52+
53+
protected:
54+
uint8_t _quality = 30;
55+
56+
/**
57+
*
58+
*/
59+
void setConfig() {
60+
setHighFreq();
61+
_config.jpeg_quality = _quality;
62+
}
63+
};
64+
65+
/**
66+
* QQVGA jpeg camera
67+
*/
68+
class QqvgaJpegCamera : public BaseJpegCamera {
69+
public:
70+
framesize_t getFrameSize() {
71+
return FRAMESIZE_QQVGA;
72+
}
73+
};
74+
75+
/**
76+
* QVGA jpeg camera
77+
*/
78+
class QvgaJpegCamera : public BaseJpegCamera {
79+
public:
80+
framesize_t getFrameSize() {
81+
return FRAMESIZE_QVGA;
82+
}
83+
};
84+
85+
/**
86+
* VGA jpeg camera
87+
*/
88+
class VgaJpegCamera : public BaseJpegCamera {
89+
public:
90+
framesize_t getFrameSize() {
91+
return FRAMESIZE_VGA;
92+
}
93+
};
94+
}
95+
}
96+
}
97+
}
98+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//
2+
// Created by Simone on 24/06/2022.
3+
//
4+
5+
#pragma once
6+
7+
8+
#include "../jpeg.h"
9+
10+
ELOQUENT_SINGLETON(Eloquent::Vision::Cam::Esp32::QqvgaJpegCamera camera);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//
2+
// Created by Simone on 24/06/2022.
3+
//
4+
5+
#pragma once
6+
7+
8+
#include "../jpeg.h"
9+
10+
ELOQUENT_SINGLETON(Eloquent::Vision::Cam::Esp32::QvgaJpegCamera camera);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//
2+
// Created by Simone on 24/06/2022.
3+
//
4+
5+
#pragma once
6+
7+
8+
#include "../jpeg.h"
9+
10+
ELOQUENT_SINGLETON(Eloquent::Vision::Cam::Esp32::VgaJpegCamera camera);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// Created by Simone on 24/06/2022.
3+
//
4+
5+
#pragma once
6+
7+
#include "../pins/m5wide.h"
8+
#include "../BaseEsp32Camera.h"
9+
10+
11+
namespace Eloquent {
12+
namespace Vision {
13+
namespace Cam {
14+
namespace Esp32 {
15+
class M5WideCamera : public BaseEsp32Camera {
16+
protected:
17+
/**
18+
*
19+
*/
20+
void configureSensor() {
21+
vflip();
22+
//hmirror();
23+
}
24+
};
25+
}
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)