Better Notification on Device Update.
This commit is contained in:
parent
9d52a86aa8
commit
aaa713e646
@ -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));
|
||||
}
|
||||
|
@ -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 != []) {
|
||||
|
Loading…
Reference in New Issue
Block a user