// 5. PROCESS REQUESTS // --------------------------------------------------- // A. HANDLE DATA UPLOAD (POST) // (This part stays the same, keep your existing POST logic here) if ($requestMethod == 'POST' && !empty($postBody)) { // ... [Keep your existing POST insert code here] ... // ... // ... file_put_contents($logFile, "-> SAVED $count RECORDS. Sending OK.\n", FILE_APPEND); echo "OK"; exit; } // B. HANDLE HEAD REQUESTS (The Fix) if ($requestMethod == 'HEAD') { // CRITICAL: We return 405 to tell the device "Stop Pinging, Send Data!" // This forces the device to switch to GET or POST immediately. http_response_code(405); header("Allow: POST, GET"); exit; } // C. HANDLE HANDSHAKE (GET) // Only send config when device uses GET if ($requestMethod == 'GET') { file_put_contents($logFile, "-> SENDING HANDSHAKE CONFIG (GET).\n", FILE_APPEND); header("Content-Type: text/plain"); echo "GET OPTION FROM: " . $sn . "\n"; echo "ATTLOGStamp=0\n"; echo "OPERLOGStamp=0\n"; echo "ATTPHOTOStamp=0\n"; echo "ErrorDelay=30\n"; echo "Delay=10\n"; echo "TransTimes=00:00;14:05\n"; echo "TransInterval=1\n"; echo "TransFlag=1111000000\n"; echo "TimeZone=7\n"; echo "Realtime=1\n"; echo "Encrypt=0\n"; exit; } echo "OK"; ?>