-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmultistatic_interference_radar_esp_example.ino
198 lines (134 loc) · 6.09 KB
/
multistatic_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
194
195
196
197
198
// multistatic interference radar, basic example for the ESP32.
#include "multistatic_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 = 1000; // in milliseconds
// PLEASE NOTE: by default configuration, it takes 32 iterations to collect enough data to produce a meaningful output. PLEASE BE PATIENT AND WAIT about 2 minutes 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 enableSecondOrderFilter = 1; // 0 disable, 1 enable // if enabled, it dynamically filters out any long term offset in the variance output. Useful for crowded environments with many weak unstable signals.
int wifiRadarLevel = RADAR_BOOTING; // initial value = -1, any values < 0 are errors, see multistatic_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
//// setup is very simple: there is no need to set anything up if the defaults are ok for you.
//multistatic_interference_radar_debug_via_serial(1); // show debugging information, at the simplest debugging level. Level 0 means no output.
//multistatic_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!
Serial.println("TX0,TX1,TX2,TX3");
multistatic_interference_radar_enable_serial_CSV_graph_data(enableCSVgraphOutput); // output CSV data only
}
multistatic_interference_radar_enable_second_order_variance_filtering(enableSecondOrderFilter);
//// 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') {
multistatic_interference_radar_set_debug_level(serParVal);
}
if (serCom == 'f') {
multistatic_interference_radar_enable_second_order_variance_filtering(serParVal);
}
if (serCom == 'c') {
multistatic_interference_radar_enable_aggressive_cleaning_low_RSSI(serParVal);
}
if (serCom == 'g') {
multistatic_interference_radar_enable_serial_CSV_graph_data(serParVal);
}
if (serCom == 's') {
multistatic_interference_radar_debug_via_serial(serParVal);
}
if (serCom == 'a') {
multistatic_interference_radar_set_Second_Order_Attenutation_Coefficient(serParVal);
}
if (serCom == 'n') {
multistatic_interference_radar_set_txN_limit(serParVal);
}
if (serCom == 'm') {
multistatic_interference_radar_set_minimum_RSSI(serParVal);
}
if (serCom == 'a') {
multistatic_interference_radar_enable_alarm(serParVal);
}
if (serCom == 't') {
multistatic_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);
wifiRadarLevel = multistatic_interference_radar(); // if the connection fails, the radar will automatically try to switch to different operating modes by using ESP32 specific calls.
if (enableCSVgraphOutput == 0) {
Serial.print("wifiRadarLevel: ");
Serial.println(wifiRadarLevel);
}
manageSerialCommands();
}