-
Notifications
You must be signed in to change notification settings - Fork 5
/
bistatic_interference_radar_esp_example.ino
193 lines (127 loc) · 6.11 KB
/
bistatic_interference_radar_esp_example.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
// Bistatic interference radar, basic example for the ESP32.
#include "bistatic_interference_radar.h"
#include <WiFi.h>
int enableCSVgraphOutput = 1; // 0 disable, 1 enable // if enabled, you may use Tools-> Serial Plotter to plot the variance output for each transmitter.
int scanInterval = 500; // in milliseconds
// PLEASE NOTE: by default configuration, it takes 64 iterations to collect enough data to produce a meaningful output. PLEASE BE PATIENT AND WAIT about 32 seconds for that.
// While initializing, the output is tipically < 0 and meaningless.
// My suggestion is to use Tools->Serial plotter to see the actual graph, also don't forget you can change most runtime parameters for this library by sending simple serial commands
// (see the manageSerialCommands() function down below)
// set the access point and password to connect to. THIS IS MANDATORY FOR THE MOMENT.
const char* ssid = "my access point name";
const char* password = "my wifi password";
// also configure the onboard soft AP
const char *soft_ap_ssid = "MyESP32AP";
const char *soft_ap_password = "testpassword";
int wifiRadarLevel = RADAR_BOOTING; // initial value = -1, any values < 0 are errors, see bistatic_interference_radar.h , ERROR LEVELS sections for details on how to intepret any errors.
void setup()
{
Serial.begin(115200);
delay(10);
// We start by connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.mode(WIFI_MODE_APSTA);
WiFi.softAP(soft_ap_ssid, soft_ap_password);
// uncomment this block if you prefer connecting the ESP32 to an external access point
/*
WiFi.begin(ssid, password);
int connCounter = 0;
while ((WiFi.status() != WL_CONNECTED) && (connCounter < 20)) {
delay(500);
Serial.print(".");
connCounter++;
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
*/
// setting up the wifi radar
bistatic_interference_radar_init(); // initializes the storage arrays in internal RAM
// reconfigure the library with new parameters:
// sample buffer depth (how many samples to store in the circular buffer), = 64
// mobile average filter size, = 16
// variance threshold ( >= 0, how much the interference signal deviates from the norm before triggering a detection result, in variance arbitrary units), = 3
// variance integrator limit (how many variance samples we cumulate before evaluating the variance threshold level), = 3
// finally bolean var set to true -> enable autoregressive filtering (default is false -> disable autoregressive filtering) = false
// look into bistatic_interference_radar.cpp for more details and to eventually modify any hard configuration limits in the #define lines.
bistatic_interference_radar_config(64, 16, 3, 3, false);
bistatic_interference_radar_debug_via_serial(1); // show debugging information, at the simplest debugging level. Level 0 means no output.
bistatic_interference_radar_set_debug_level(3); // set a very verbose level for operating the radar.
if (enableCSVgraphOutput > 0) { // USE THE Tools->Serial Plotter to graph the live data!
bistatic_interference_radar_enable_serial_CSV_graph_data(enableCSVgraphOutput); // output CSV data only
}
//// trying to reduce overall power usage
setCpuFrequencyMhz(80);
Serial.setTimeout(1000);
}
void manageSerialCommands() { // receives simple commands via serial port in the form CommandParamenter where command is a single character and Parameter is an ascii string representing a number, for example: d1 sets command d (debug level) to 1. I expect the string received to be null terminated.
// for example, to set the minimum acceptable RSSI threshold to -80 dBm, send via serial the string m-80
// to enable debugging messages at level 3, send via serial the string d3
// and so on.
char serBuf[32] = {0}; // don't make these global: character buffers NEED to be reinitialized to zero after each use. Just leave this to the function code itself.
char serCom = 0;
char serPar[64] = {0};
int serBytesAvail = 0;
int serParVal = 0;
serBytesAvail = Serial.available();
if (serBytesAvail >=32 ) {
serBytesAvail = 0;
Serial.flush();
}
if (serBytesAvail >= 2) {
Serial.readBytes(serBuf, serBytesAvail);
Serial.flush();
serCom = serBuf[0];
for (int paridx = 1; paridx < serBytesAvail; paridx++) {
serPar[paridx -1] = serBuf[paridx];
if (serBuf[paridx] == 0) {
break;
}
}
serPar[serBytesAvail] = 0;
serParVal = atoi(serPar);
if (serCom == 'd') {
bistatic_interference_radar_set_debug_level(serParVal);
}
if (serCom == 'g') {
bistatic_interference_radar_enable_serial_CSV_graph_data(serParVal);
}
if (serCom == 's') {
bistatic_interference_radar_debug_via_serial(serParVal);
}
if (serCom == 'm') {
bistatic_interference_radar_set_minimum_RSSI(serParVal);
}
if (serCom == 'a') {
bistatic_interference_radar_enable_alarm(serParVal);
}
if (serCom == 't') {
bistatic_interference_radar_set_alarm_threshold(serParVal);
}
if (serCom == 'r') {
Serial.println("REBOOT REQUESTED");
ESP.restart();
}
if (serCom == 'q') {
Serial.println("SERIAL FLUSH REQUESTED");
Serial.flush();
}
if (serCom == 'i') { // set the scan interval in milliseconds
scanInterval = serParVal;
}
}
}
void loop()
{
delay(scanInterval);
manageSerialCommands();
wifiRadarLevel = bistatic_interference_radar_esp(); // if the connection fails, the radar will automatically try to switch to different operating modes by using ESP32 specific calls.
if (enableCSVgraphOutput == 0) { // for the graph via serial, we just let the library do the job.
Serial.print("wifiRadarLevel: ");
Serial.println(wifiRadarLevel);
}
}