#include <WiFi.h>
#include <HTTPClient.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_MAX30100.h>
#include <TinyGPS++.h>
const char* ssid = "your_network_name";
const char* password = "your_network_password";
const char* serverAddress = "http://your_server_ip_or_domain/rest_api.php";
// Sensor setup
Adafruit_MAX30100 max30100;
TinyGPSPlus gps;
HardwareSerial gpsSerial(1);
void setup() {
Serial.begin(115200);
gpsSerial.begin(9600, SERIAL_8N1, 16, 17); // TX, RX pins
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
if (!max30100.begin()) {
Serial.println("MAX30100 not found");
while (1);
}
max30100.setMode(MAX30100_MODE_SPO2_HR);
}
void loop() {
// Read GPS data
while (gpsSerial.available() > 0) {
gps.encode(gpsSerial.read());
}
if (gps.location.isUpdated()) {
float latitude = gps.location.lat();
float longitude = gps.location.lng();
// Read heart rate and SpO2
uint16_t irValue, redValue;
max30100.update();
irValue = max30100.getIR();
redValue = max30100.getRed();
// Dummy calculation for demonstration purposes
float heartRate = (irValue % 100); // Replace with actual heart rate calculation
float oxygenLevel = (redValue % 100); // Replace with actual SpO2 calculation
// Create JSON data
String jsonData = "{\"heartRate\":";
jsonData += heartRate;
jsonData += ", \"oxygenLevel\":";
jsonData += oxygenLevel;
jsonData += ", \"latitude\":";
jsonData += latitude;
jsonData += ", \"longitude\":";
jsonData += longitude;
jsonData += "}";
// Send data to server
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
http.begin(serverAddress);
http.addHeader("Content-Type", "application/json");
int httpResponseCode = http.POST(jsonData);
if (httpResponseCode > 0) {
String response = http.getString();
Serial.println(httpResponseCode);
Serial.println(response);
} else {
Serial.println("Error sending POST request");
}
http.end();
}
}
delay(5000);
}