-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfall detection version 1.c
79 lines (64 loc) · 2.2 KB
/
fall detection version 1.c
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
#include <WiFi.h>
#include <HTTPClient.h>
#include <Wire.h>
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
const char* ssid = "Hackathon";
const char* password = "Intel@Kp6!3t";
// Central server URL
const char* serverUrl = "http://172.168.72.89:5000/upload_data"; // Use your Flask server IP
const char* apiKey = "jobin"; // Replace with your actual API key
Adafruit_MPU6050 mpu;
void setup() {
Serial.begin(115200);
Wire.begin();
// Initialize MPU6050
if (!mpu.begin()) {
Serial.println("Could not find a valid MPU6050 sensor, check wiring!");
while (1) {
delay(10);
}
}
// Connect to WiFi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
}
void loop() {
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
sensors_event_t a, g, temp;
mpu.getEvent(&a, &g, &temp);
// Build the data string
String data = "sensor=mpu6050&acc_x=" + String(a.acceleration.x) +
"&acc_y=" + String(a.acceleration.y) +
"&acc_z=" + String(a.acceleration.z) +
"&api_key=" + apiKey; // Include the API key
// Send the POST request
http.begin(serverUrl);
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
int httpResponseCode = http.POST(data);
// Debugging information
Serial.print("Sending data: ");
Serial.println(data);
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
if (httpResponseCode > 0) {
String response = http.getString();
Serial.println("Response: " + response);
} else {
Serial.print("Error on sending POST: ");
Serial.println(http.errorToString(httpResponseCode).c_str());
}
http.end();
} else {
Serial.println("WiFi not connected, trying to reconnect...");
WiFi.reconnect();
}
delay(5000); // Send data every 5 seconds
}