fix updater and other things
This commit is contained in:
		
							
								
								
									
										
											BIN
										
									
								
								_FIRMWARE/firmwares/Sonoff_Basic/Arduino_ide_setting.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								_FIRMWARE/firmwares/Sonoff_Basic/Arduino_ide_setting.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 19 KiB  | 
@@ -98,20 +98,19 @@ void setup() {
 | 
			
		||||
              Serial.printf("HTTP_UPDATE_FAILD Error (%d): %s", ESPhttpUpdate.getLastError(), ESPhttpUpdate.getLastErrorString().c_str());
 | 
			
		||||
              Serial.println();
 | 
			
		||||
              Serial.println();
 | 
			
		||||
              Serial.println();
 | 
			
		||||
              break;
 | 
			
		||||
  
 | 
			
		||||
          case HTTP_UPDATE_NO_UPDATES:
 | 
			
		||||
              Serial.println("HTTP_UPDATE_NO_UPDATES");
 | 
			
		||||
              Serial.println();
 | 
			
		||||
              Serial.println();
 | 
			
		||||
              Serial.println();
 | 
			
		||||
              break;
 | 
			
		||||
  
 | 
			
		||||
          case HTTP_UPDATE_OK:
 | 
			
		||||
              Serial.println("HTTP_UPDATE_OK");
 | 
			
		||||
              Serial.println();
 | 
			
		||||
              Serial.println();
 | 
			
		||||
              Serial.println();
 | 
			
		||||
              break;
 | 
			
		||||
      }
 | 
			
		||||
      delay(500);
 | 
			
		||||
@@ -214,7 +213,6 @@ void loadDataFromWeb() {
 | 
			
		||||
  } else if (requestState == "succes") {
 | 
			
		||||
    unsuccessfulRounds = 0;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  WiFi.hostname(hostName);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										3
									
								
								api.php
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								api.php
									
									
									
									
									
								
							@@ -164,7 +164,7 @@ if (!DeviceManager::approved($token)) {
 | 
			
		||||
if ($settings != null || $settings != ""){
 | 
			
		||||
	$data = ['mac' => $settings["network"]["mac"], 'ip_address' => $settings["network"]["ip"]];
 | 
			
		||||
	if (array_key_exists("firmware_hash", $settings)) {
 | 
			
		||||
		$data .= ['firmware_hash'=>$settings["firmware_hash"]];
 | 
			
		||||
		$data['firmware_hash'] = $settings["firmware_hash"];
 | 
			
		||||
	}
 | 
			
		||||
	DeviceManager::editByToken($token, $data);
 | 
			
		||||
}
 | 
			
		||||
@@ -217,6 +217,7 @@ if ($values != null || $values != "") {
 | 
			
		||||
 | 
			
		||||
	$hostname = strtolower($device['name']);
 | 
			
		||||
	$hostname = str_replace(' ', '_', $hostname);
 | 
			
		||||
	//upravit format na setings-> netvork etc
 | 
			
		||||
	$jsonAnswer = [
 | 
			
		||||
		'device' => [
 | 
			
		||||
			'hostname' => $hostname,
 | 
			
		||||
 
 | 
			
		||||
@@ -49,7 +49,7 @@ class DeviceManager{
 | 
			
		||||
 | 
			
		||||
	public function editByToken ($token, $values = []) {
 | 
			
		||||
		try {
 | 
			
		||||
			Db::edit ('devices', $values, 'WHERE token = ?', array($deviceId));
 | 
			
		||||
			Db::edit ('devices', $values, 'WHERE token = ?', array($token));
 | 
			
		||||
		} catch(PDOException $error) {
 | 
			
		||||
			echo $error->getMessage();
 | 
			
		||||
			die();
 | 
			
		||||
 
 | 
			
		||||
@@ -17,7 +17,7 @@ class NotificationManager
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	function getSubscription () {
 | 
			
		||||
		return Db::loadAll('SELECT * FROM notifications;', array());
 | 
			
		||||
		return Db::loadAll ("SELECT * FROM notifications");
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	function sendSimpleNotification(string $serverKey, string $to, array $data, bool $timeStamp = false){
 | 
			
		||||
 
 | 
			
		||||
@@ -7,8 +7,9 @@ if (isset($_POST) && !empty($_POST)){
 | 
			
		||||
		$sleepTime = 0;
 | 
			
		||||
		if (isset($_FILES['deviceFirmware']) && isset($_FILES['deviceFirmware']['tmp_name']) && $_FILES['deviceFirmware']['tmp_name'] != "") {
 | 
			
		||||
			$file = $_FILES['deviceFirmware'];
 | 
			
		||||
			$fileName = (isset ($_POST['deviceMac']) ? str_replace(":", "", $_POST['deviceMac']) . ".bin" : "");
 | 
			
		||||
			if (file_exists("./app/updater/" . $fileName)) {
 | 
			
		||||
			$deviceMac = DeviceManager::getDeviceById($deviceId)['mac'];
 | 
			
		||||
			$fileName = (isset ($deviceMac) && $deviceMac != "" ? str_replace(":", "", $deviceMac) . ".bin" : "");
 | 
			
		||||
			if ($fileName != "" && file_exists("./app/updater/" . $fileName)) {
 | 
			
		||||
				unlink("./app/updater/" . $fileName);
 | 
			
		||||
			}
 | 
			
		||||
			if ($fileName != "") {
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										13
									
								
								update.php
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								update.php
									
									
									
									
									
								
							@@ -22,6 +22,10 @@ $files = array_diff($files, array(
 | 
			
		||||
foreach($files as $file) {
 | 
			
		||||
	include './app/class/'.  $file;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//DB Conector
 | 
			
		||||
Db::connect (DBHOST, DBUSER, DBPASS, DBNAME);
 | 
			
		||||
 | 
			
		||||
$logManager = new LogManager();
 | 
			
		||||
 | 
			
		||||
header('Content-type: text/plain; charset=utf8', true);
 | 
			
		||||
@@ -52,12 +56,10 @@ function sendFile($path)
 | 
			
		||||
$localBinary = "./app/updater/" . str_replace(':', '', $_SERVER['HTTP_X_ESP8266_STA_MAC']) . ".bin";
 | 
			
		||||
$logManager->write("[Updater] url: " . $localBinary, LogRecordType::INFO);
 | 
			
		||||
$logManager->write("[Updater] version: " . $_SERVER['HTTP_X_ESP8266_SKETCH_MD5'], LogRecordType::INFO);
 | 
			
		||||
 | 
			
		||||
if (file_exists($localBinary)) {
 | 
			
		||||
	$logManager->write("[Updater] version PHP: " . md5_file($localBinary), LogRecordType::INFO);
 | 
			
		||||
	if ($_SERVER['HTTP_X_ESP8266_SKETCH_MD5'] != md5_file($localBinary)) {
 | 
			
		||||
		sendFile($localBinary);
 | 
			
		||||
 | 
			
		||||
		//notification
 | 
			
		||||
		$notificationMng = new NotificationManager;
 | 
			
		||||
		$notificationData = [
 | 
			
		||||
@@ -65,12 +67,11 @@ if (file_exists($localBinary)) {
 | 
			
		||||
			'body' => 'Someone device was just updated to new version',
 | 
			
		||||
			'icon' => BASEDIR . '/app/templates/images/icon-192x192.png',
 | 
			
		||||
		];
 | 
			
		||||
		
 | 
			
		||||
		if ($notificationData != []) {
 | 
			
		||||
				$subscribers = $notificationMng::getSubscription();
 | 
			
		||||
			$subscribers = $notificationMng->getSubscription();
 | 
			
		||||
			foreach ($subscribers as $key => $subscriber) {
 | 
			
		||||
				$logManager->write("[NOTIFICATION] SENDING TO " . $subscriber['id'] . " ", LogRecordType::INFO);
 | 
			
		||||
					$notificationMng::sendSimpleNotification(SERVERKEY, $subscriber['token'], $notificationData);
 | 
			
		||||
				$answer = $notificationMng->sendSimpleNotification(SERVERKEY, $subscriber['token'], $notificationData);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	} else {
 | 
			
		||||
@@ -79,6 +80,4 @@ if (file_exists($localBinary)) {
 | 
			
		||||
} else {
 | 
			
		||||
	header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
 | 
			
		||||
}
 | 
			
		||||
	header($_SERVER["SERVER_PROTOCOL"].' 500 no version for ESP MAC', true, 500);
 | 
			
		||||
die();
 | 
			
		||||
	
 | 
			
		||||
		Reference in New Issue
	
	Block a user