#include #include #include "HX711.h" // ---------------- WIFI ---------------- const char* ssid = "EDS_Shop_24"; const char* password = "eds12345"; //const char* ssid = "MIT"; //const char* password = "kwN4@9{UwQ"; // ---------------- HX711 ---------------- #define HX711_DT A1 // D1 #define HX711_SCK A0 // D0 HX711 scale; float calibration_factor = 2280.0f; float gripStrength = 0; // ---------------- WEB SERVER ---------------- WebServer server(80); // ---------------- Age Estimation ---------------- float ageFromGripMale(float g) { float a = 52.0; float b = 0.0089; if (g > a) g = a; if (g < 5) g = 5; float term = (a - g) / b; float root = sqrt(term); return 35 + root; } float ageFromGripFemale(float g) { float a = 32.0; float b = 0.0059; if (g > a) g = a; if (g < 4) g = 4; float term = (a - g) / b; float root = sqrt(term); return 35 + root; } // GUI HTML + Chart.js const char GUI_PAGE[] PROGMEM = "" "Grip Strength" "" "" "" "

Grip Strength Monitor

" "
" "
Sex
" "" "" "
" "
" "
Estimated Age
" "
--
" "
" "
" "
Grip Strength (kg)
" "
--
" "
" "
" "
" "
" "" ""; void handleGUI() { server.sendHeader("Cache-Control", "no-cache"); server.send_P(200, "text/html; charset=utf-8", GUI_PAGE); } void handleMetrics() { String sex = server.hasArg("sex") ? server.arg("sex") : "male"; float age = (sex == "female") ? ageFromGripFemale(gripStrength) : ageFromGripMale(gripStrength); String json = "{"; json += "\"grip\":" + String(gripStrength,1) + ","; json += "\"age\":" + String(age,1); json += "}"; server.send(200, "application/json", json); } void setup() { Serial.begin(115200); delay(300); // HX711 scale.begin(HX711_DT, HX711_SCK); scale.set_scale(calibration_factor); scale.tare(); // WiFi WiFi.begin(ssid, password); Serial.print("Connecting to WiFi"); while(WiFi.status() != WL_CONNECTED){ delay(300); Serial.print("."); } Serial.print("\nIP: "); Serial.println(WiFi.localIP()); // Webserver server.on("/", handleGUI); server.on("/metrics", handleMetrics); server.begin(); } unsigned long lastRead=0; void loop() { server.handleClient(); unsigned long now = millis(); if(now - lastRead > 200){ lastRead = now; if(scale.is_ready()){ gripStrength = scale.get_units(3); // smoothed if(gripStrength < 0) gripStrength = 0; } } }