@@ -34,6 +34,7 @@ static char MQTT_ORGID[7]; // Watson IoT 6 character orgid
34
34
#define MQTT_TOPIC_SEND10SEC " iot-2/cmd/10secondhistory/fmt/json"
35
35
#define MQTT_TOPIC_SENDACCEL " iot-2/cmd/sendacceldata/fmt/json"
36
36
#define MQTT_TOPIC_RESTART " iot-2/cmd/forcerestart/fmt/json"
37
+ #define MQTT_TOPIC_THRESHOLD " iot-2/cmd/threshold/fmt/json"
37
38
char deviceID[13 ];
38
39
39
40
// Store the Download Server PEM and Digicert CA and Root CA in SPIFFS
@@ -169,12 +170,31 @@ int channel = 0;
169
170
int resolution = 8 ;
170
171
int io = 5 ;
171
172
173
+ // --------------------------------------------------------------------------------------------
174
+ // STA/LTA Algorithm globals
175
+ bool bPossibleEarthQuake = false ;
176
+ double thresh = 4.0 ;
177
+ double stalta[3 ] = { 0 , 0 , 0 };
178
+ double sample[3 ] = { 0 , 0 , 0 };
179
+ double sampleSUM[3 ] = { 0 , 0 , 0 };
180
+ double ltSUM[3 ] = { 0 , 0 , 0 };
181
+ double sample1[3 ] = { 0 , 0 , 0 };
182
+ double LTAsample1[3 ] = { 0 , 0 , 0 };
183
+ double offset[3 ] = { 0 , 0 , 0 };
184
+ double sampleABS[3 ] = { 0 , 0 , 0 };
185
+ double sample1ABS = 0 ;
186
+ double LTAsample1ABS = 0 ;
187
+ double stav[3 ] = { 0 , 0 , 0 };
188
+ double ltav[3 ] = { 0 , 0 , 0 };
189
+
190
+
172
191
// --------------------------------------------------------------------------------------------
173
192
void IRAM_ATTR isr_adxl () {
174
193
fifoFull = true ;
175
194
// fifoCount++;
176
195
}
177
196
197
+
178
198
void StartADXL355 () {
179
199
// odr_lpf is a global
180
200
adxl355.start ();
@@ -285,6 +305,14 @@ void callback(char* topic, byte* payload, unsigned int length) {
285
305
breathedirection = true ;
286
306
}
287
307
jsonMQTTReceiveDoc.clear ();
308
+ } else if ( strcmp (topic, MQTT_TOPIC_THRESHOLD) == 0 ) {
309
+ // Override the `thresh` global
310
+ char newthreshmsg[50 ];
311
+ snprintf ( newthreshmsg, 49 , " Previous STA/LTA Shake Threshold : %5.2f" , thresh);
312
+ Serial.println (newthreshmsg);
313
+ thresh = cmdData[" ThresholdOverride" ].as <double >();
314
+ snprintf ( newthreshmsg, 49 , " Override STA/LTA Shake Threshold : %5.2f" , thresh);
315
+ Serial.println (newthreshmsg);
288
316
} else if ( strcmp (topic, MQTT_TOPIC_RESTART) == 0 ) {
289
317
Serial.println (" Restarting Device..." );
290
318
esp_restart ();
@@ -457,6 +485,7 @@ void Connect2MQTTbroker() {
457
485
mqtt.subscribe (MQTT_TOPIC_SEND10SEC);
458
486
mqtt.subscribe (MQTT_TOPIC_SENDACCEL);
459
487
mqtt.subscribe (MQTT_TOPIC_RESTART);
488
+ mqtt.subscribe (MQTT_TOPIC_THRESHOLD);
460
489
mqtt.setBufferSize (2000 );
461
490
mqtt.loop ();
462
491
} else {
@@ -796,20 +825,6 @@ void setup() {
796
825
digitalWrite (io, LOW); // turn off buzzer
797
826
}
798
827
799
- bool bPossibleEarthQuake = false ;
800
- double thresh = 3.0 ;
801
- double stalta[3 ] = { 0 , 0 , 0 };
802
- double sample[3 ] = { 0 , 0 , 0 };
803
- double sampleSUM[3 ] = { 0 , 0 , 0 };
804
- double ltSUM[3 ] = { 0 , 0 , 0 };
805
- double sample1[3 ] = { 0 , 0 , 0 };
806
- double LTAsample1[3 ] = { 0 , 0 , 0 };
807
- double offset[3 ] = { 0 , 0 , 0 };
808
- double sampleABS[3 ] = { 0 , 0 , 0 };
809
- double sample1ABS = 0 ;
810
- double LTAsample1ABS = 0 ;
811
- double stav[3 ] = { 0 , 0 , 0 };
812
- double ltav[3 ] = { 0 , 0 , 0 };
813
828
814
829
void loop () {
815
830
mqtt.loop ();
0 commit comments