HTTP response code 400

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);
}

Welcome to the forum

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

You do not seem to have asked a question or described a problem in your post

This function is all wrong... what is the web service you are trying to connect to?

I'm trying to connect my with IFTTT that is connected with my email

So why you don't send your request as described in the IFTTT API reference?

Try to follow a simple tutorial like this as start point and then add the required IMA data to your request payload.

I know my notification works when I trigger my code but I can't get notification when ever MPU6050 gets motion.

I moved your topic to a more appropriate forum category @antl25.

The Nano ESP32 category you chose is only used for discussions directly related to the Arduino Nano ESP32 board.

In the future, please take the time to pick the forum category that best suits the subject of your question. There is an "About the _____ category" topic at the top of each category that explains its purpose.

Thanks in advance for your cooperation.

image

Your point is? Do you really expect us to have a category named "Fire Beetle ESP32 is not available."?

I think it should be obvious that you must look through the available categories and pick the one that is best suited for the subject of your topic. If you can't do that then you aren't a good fit for this forum and probably not for Arduino in general.

Do you think its the code I got wrong that's why I'm getting the error? When I verified my code no error appeared.

If my board is listed in board management shouldn't it be available here anyways?

No. We're not going to add a category for every one of the ever increasing thousands of random third party boards.

Do you mind if you could direct me to the right code to sending my request for that part?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.