I am using FireBeetle ESP32 and a MPU6050.
I cannot connect my code with my phone notification. Everything else works thanks
#include "WiFi.h"
#include <HTTPClient.h>
#include "arduino_secrets.h"
#include <Adafruit_Sensor.h>
#include <Adafruit_MPU6050.h>
#include <Wire.h>
Adafruit_MPU6050 mpu;
WiFiClient client;
HTTPClient http;
sensors_event_t event;
const char* serverName = "webkey";
const char* SSID = "SSID goes here";
const char* PASS = "PASS goes here";
const char* DEVICE_KEY = "Key goes here";
const char* EVENT_NAME = "If_MPU_Detects_Motion_V2";
int httpResponseCode; // Declare httpResponseCode here
int motionDetectionFlag = 1; // Initialize the motion detection flag to 1 (motion detected)
bool motionIsDetected = 1; // Declare and initialize the motion detection flag
void Sendrequest()
{
Serial.println(" Start");
http.begin(client, serverName);
http.addHeader("Motion_Detected!!!", "Webkey goes here");
httpResponseCode = http.POST("test");
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
Serial.println("successfully connected to host");
http.end();
Serial.println(" End");
}
void setup(void) {
Serial.begin(115200);
WiFi.begin(SSID, PASS);
Serial.print("Connecting to WiFi ");
Serial.print(SSID);
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(300);
Serial.print(".");
}
Serial.println(" Connected!");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
Serial.begin(115200);
while (!Serial)
delay(10); // will pause Zero, Leonardo, etc until serial console opens
Serial.println("Adafruit MPU6050 test!");
// Try to initialize!
if (!mpu.begin()) {
Serial.println("Failed to find MPU6050 chip");
while (1) {
delay(10);
}
}
Serial.println("MPU6050 Found!");
//setupt motion detection
mpu.setHighPassFilter(MPU6050_HIGHPASS_0_63_HZ);
mpu.setMotionDetectionThreshold(1);
mpu.setMotionDetectionDuration(20);
mpu.setInterruptPinLatch(true); // Keep it latched. Will turn off when reinitialized.
mpu.setInterruptPinPolarity(true);
mpu.setMotionInterrupt(true);
Serial.println("");
delay(100);
}
void loop() {
if (mpu.getMotionInterruptStatus()) {
motionIsDetected = true;
Sendrequest(); // Call the function when motion is detected
} else {
motionIsDetected = false;
}
/* Get new sensor events with the readings */
sensors_event_t a, g, temp;
mpu.getEvent(&a, &g, &temp);
/* Print out the values */
Serial.print("AccelX:");
Serial.print(a.acceleration.x);
Serial.print(",");
Serial.print("AccelY:");
Serial.print(a.acceleration.y);
Serial.print(",");
Serial.print("AccelZ:");
Serial.print(a.acceleration.z);
Serial.print(", ");
Serial.print("GyroX:");
Serial.print(g.gyro.x);
Serial.print(",");
Serial.print("GyroY:");
Serial.print(g.gyro.y);
Serial.print(",");
Serial.print("GyroZ:");
Serial.print(g.gyro.z);
Serial.println("");
Serial.print(millis());
Serial.println(" Sent notify - check it");
delay(10000);
}