Created
May 3, 2026 04:04
-
-
Save Anas-jaf/923e096aaffc1646686edfc3e5649b1d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <WiFi.h> | |
| #include <WebServer.h> | |
| #include "DHT.h" | |
| #include <OneWire.h> | |
| #include <DallasTemperature.h> | |
| const char* ssid = "Smart_Shoe"; | |
| const char* password = "12345678"; | |
| WebServer server(80); | |
| // DHT11 | |
| #define DHTPIN 5 | |
| #define DHTTYPE DHT11 | |
| DHT dht(DHTPIN, DHTTYPE); | |
| // DS18B20 | |
| #define ONE_WIRE_BUS 4 | |
| OneWire oneWire(ONE_WIRE_BUS); | |
| DallasTemperature sensors(&oneWire); | |
| // FSR | |
| int fsrPin = 34; | |
| // Buzzer | |
| int buzzer = 15; | |
| // التحكم بالضغط | |
| unsigned long startPress = 0; | |
| bool pressing = false; | |
| int pressureThreshold = 600; | |
| int timeThreshold = 5000; // 5 ثواني | |
| // HTML عربي جميل | |
| String page = R"rawliteral( | |
| <!DOCTYPE html> | |
| <html dir="rtl"> | |
| <head> | |
| <meta name="viewport" content="width=device-width, initial-scale=1"> | |
| <title>الحذاء الذكي</title> | |
| <style> | |
| body { | |
| font-family: Arial; | |
| text-align: center; | |
| background: #0f172a; | |
| color: white; | |
| } | |
| .card { | |
| background: #1e293b; | |
| margin: 15px; | |
| padding: 20px; | |
| border-radius: 15px; | |
| font-size: 20px; | |
| } | |
| h1 {color: #38bdf8;} | |
| .value {font-size: 30px; color: #22c55e;} | |
| .danger {color: red;} | |
| </style> | |
| </head> | |
| <body> | |
| <h1>👟 الحذاء الذكي لمرضى السكري</h1> | |
| <div class="card"> | |
| 🌡️ الحرارة: <span id="t" class="value">--</span> | |
| </div> | |
| <div class="card"> | |
| 💧 الرطوبة: <span id="h" class="value">--</span> | |
| </div> | |
| <div class="card"> | |
| 👣 الضغط: <span id="p" class="value">--</span> | |
| </div> | |
| <div class="card"> | |
| ⏱️ مدة الضغط (ثواني): <span id="time" class="value">0</span> | |
| </div> | |
| <div class="card"> | |
| ⚠️ الحالة: <span id="status" class="value">طبيعي</span> | |
| </div> | |
| <script> | |
| setInterval(()=>{ | |
| fetch("/data") | |
| .then(res=>res.json()) | |
| .then(d=>{ | |
| document.getElementById("t").innerText=d.t + " °C"; | |
| document.getElementById("h").innerText=d.h + " %"; | |
| document.getElementById("p").innerText=d.p; | |
| document.getElementById("time").innerText=d.time; | |
| let status = document.getElementById("status"); | |
| if(d.alert == 1){ | |
| status.innerText = "خطر ⚠️"; | |
| status.classList.add("danger"); | |
| } else { | |
| status.innerText = "طبيعي"; | |
| status.classList.remove("danger"); | |
| } | |
| }); | |
| },1000); | |
| </script> | |
| </body> | |
| </html> | |
| )rawliteral"; | |
| void handleRoot(){ | |
| server.send(200, "text/html; charset=UTF-8", page); | |
| } | |
| void handleData(){ | |
| float h = dht.readHumidity(); | |
| sensors.requestTemperatures(); | |
| float t = sensors.getTempCByIndex(0); | |
| int p = analogRead(fsrPin); | |
| unsigned long currentTime = millis(); | |
| int pressSeconds = 0; | |
| bool alert = false; | |
| if(p > pressureThreshold){ | |
| if(!pressing){ | |
| pressing = true; | |
| startPress = currentTime; | |
| } | |
| pressSeconds = (currentTime - startPress)/1000; | |
| if(currentTime - startPress > timeThreshold){ | |
| digitalWrite(buzzer, HIGH); | |
| alert = true; | |
| } | |
| } else { | |
| pressing = false; | |
| digitalWrite(buzzer, LOW); | |
| } | |
| String json = "{"; | |
| json += "\"t\":\""+String(t)+"\","; | |
| json += "\"h\":\""+String(h)+"\","; | |
| json += "\"p\":\""+String(p)+"\","; | |
| json += "\"time\":\""+String(pressSeconds)+"\","; | |
| json += "\"alert\":\""+String(alert)+"\""; | |
| json += "}"; | |
| server.send(200,"application/json",json); | |
| } | |
| void setup(){ | |
| Serial.begin(115200); | |
| dht.begin(); | |
| sensors.begin(); | |
| pinMode(buzzer, OUTPUT); | |
| // تشغيل Access Point | |
| WiFi.softAP(ssid,password); | |
| Serial.println("\n=============================="); | |
| Serial.println("✅ تم تشغيل الحذاء الذكي بنجاح!"); | |
| Serial.println("=============================="); | |
| Serial.print("📡 اسم الشبكة (WiFi): "); | |
| Serial.println(ssid); | |
| Serial.print("🔑 كلمة المرور: "); | |
| Serial.println(password); | |
| Serial.print("🌐 افتح المتصفح واكتب: http://"); | |
| Serial.println(WiFi.softAPIP()); | |
| Serial.println("📱 ادخل من أي موبايل على نفس الشبكة"); | |
| Serial.println("==============================\n"); | |
| server.on("/",handleRoot); | |
| server.on("/data",handleData); | |
| server.begin(); | |
| Serial.println("🚀 السيرفر يعمل الآن وجاهز لاستقبال الطلبات!"); | |
| } | |
| void loop(){ | |
| server.handleClient(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment