diff --git a/app/class/DeviceManager.php b/app/class/DeviceManager.php index d7177b5..4947112 100644 --- a/app/class/DeviceManager.php +++ b/app/class/DeviceManager.php @@ -18,6 +18,10 @@ class DeviceManager{ return Db::loadOne("SELECT * FROM devices WHERE token = ?", array($deviceToken)); } + function getDeviceByMac($deviceMac) { + return Db::loadOne("SELECT * FROM devices WHERE mac = ?", array($deviceMac)); + } + function getDeviceById($deviceId) { return Db::loadOne("SELECT * FROM devices WHERE device_id = ?", array($deviceId)); } diff --git a/update.php b/update.php index d1087ae..cecc76a 100644 --- a/update.php +++ b/update.php @@ -53,7 +53,8 @@ function sendFile($path) readfile($path); } -$localBinary = "./app/updater/" . str_replace(':', '', $_SERVER['HTTP_X_ESP8266_STA_MAC']) . ".bin"; +$macAddress = $_SERVER['HTTP_X_ESP8266_STA_MAC']; +$localBinary = "./app/updater/" . str_replace(':', '', $macAddress) . ".bin"; $logManager->write("[Updater] url: " . $localBinary, LogRecordType::INFO); $logManager->write("[Updater] version: " . $_SERVER['HTTP_X_ESP8266_SKETCH_MD5'], LogRecordType::INFO); if (file_exists($localBinary)) { @@ -61,10 +62,11 @@ if (file_exists($localBinary)) { if ($_SERVER['HTTP_X_ESP8266_SKETCH_MD5'] != md5_file($localBinary)) { sendFile($localBinary); //notification + $deviceName = DeviceManager::getDeviceByMac($macAddress)['name']; $notificationMng = new NotificationManager; $notificationData = [ 'title' => 'Info', - 'body' => 'Someone device was just updated to new version', + 'body' => $deviceName.' was just updated to new version', 'icon' => BASEDIR . '/app/templates/images/icon-192x192.png', ]; if ($notificationData != []) {