Better Notification on Device Update.

This commit is contained in:
JonatanRek 2020-03-13 14:45:12 +01:00
parent 9d52a86aa8
commit aaa713e646
2 changed files with 8 additions and 2 deletions

View File

@ -18,6 +18,10 @@ class DeviceManager{
return Db::loadOne("SELECT * FROM devices WHERE token = ?", array($deviceToken)); 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) { function getDeviceById($deviceId) {
return Db::loadOne("SELECT * FROM devices WHERE device_id = ?", array($deviceId)); return Db::loadOne("SELECT * FROM devices WHERE device_id = ?", array($deviceId));
} }

View File

@ -53,7 +53,8 @@ function sendFile($path)
readfile($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] url: " . $localBinary, LogRecordType::INFO);
$logManager->write("[Updater] version: " . $_SERVER['HTTP_X_ESP8266_SKETCH_MD5'], LogRecordType::INFO); $logManager->write("[Updater] version: " . $_SERVER['HTTP_X_ESP8266_SKETCH_MD5'], LogRecordType::INFO);
if (file_exists($localBinary)) { if (file_exists($localBinary)) {
@ -61,10 +62,11 @@ if (file_exists($localBinary)) {
if ($_SERVER['HTTP_X_ESP8266_SKETCH_MD5'] != md5_file($localBinary)) { if ($_SERVER['HTTP_X_ESP8266_SKETCH_MD5'] != md5_file($localBinary)) {
sendFile($localBinary); sendFile($localBinary);
//notification //notification
$deviceName = DeviceManager::getDeviceByMac($macAddress)['name'];
$notificationMng = new NotificationManager; $notificationMng = new NotificationManager;
$notificationData = [ $notificationData = [
'title' => 'Info', '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', 'icon' => BASEDIR . '/app/templates/images/icon-192x192.png',
]; ];
if ($notificationData != []) { if ($notificationData != []) {