Skip to content
Permalink
Browse files

set values startup, pulse, pulseWidth in device

view ip, updated
fixes edit device
fixes links in about form
  • Loading branch information...
Anisan committed Sep 30, 2019
1 parent 86d3513 commit 214b998608541076ed641dc592b4a5a9dfd38dfe
@@ -233,25 +233,20 @@ function edit_sonoff_diy_data(&$out, $id) {
require(DIR_MODULES.$this->name.'/sonoff_diy_data_edit.inc.php');
}
function propertySetHandle($object, $property, $value) {
$this->getConfig();
//registerError('sonoff_diy', $object .$property. $value );
$this->getConfig();
$table='sonoff_diy_data';
$properties=SQLSelect("SELECT * FROM $table WHERE LINKED_OBJECT LIKE '".DBSafe($object)."' AND LINKED_PROPERTY LIKE '".DBSafe($property)."'");
$total=count($properties);
//registerError('sonoff_diy', "find - ".$total );
if ($total) {
for($i=0;$i<$total;$i++) {
$device_id = $properties[$i]["DEVICE_ID"];
//registerError('sonoff_diy', "device_id - ".$device_id );
$table='sonoff_diy_devices';
$rec=SQLSelectOne("SELECT * FROM $table WHERE ID=$device_id");
//registerError('sonoff_diy', "device - ".print_r($rec) );
if ($rec['ID']) {
$ip = $rec["IP"];
$port = $rec["PORT"];
//registerError('sonoff_diy', "device - ".print_r($rec) );
if ($properties[$i]["TITLE"] == "switch")
{
$ip = $rec["IP"];
$port = $rec["PORT"];
if ($properties[$i]["TITLE"] == "switch")
{
$url = "http://$ip:$port/zeroconf/switch";
if ($value == 1) $val = 'on';
if ($value == 0) $val = 'off';
@@ -261,7 +256,59 @@ function propertySetHandle($object, $property, $value) {
$data['data']['switch'] = $val;
//registerError('sonoff_diy', $url . print_r($data));
$this->callApi($url,$data);
}
}
if ($properties[$i]["TITLE"] == "startup") // on off stay
{
$url = "http://$ip:$port/zeroconf/startup";
$data = array();
$data['deviceid'] = $rec['DEVICE_ID'];
$data['data'] = array();
$data['data']['startup'] = $value;
$this->callApi($url,$data);
}
if ($properties[$i]["TITLE"] == "sledOnline")
{
$url = "http://$ip:$port/zeroconf/ledOnline";
if ($value == 1) $val = 'on';
if ($value == 0) $val = 'off';
$data = array();
$data['deviceid'] = $rec['DEVICE_ID'];
$data['data'] = array();
$data['data']['ledOnline'] = $val;
$this->callApi($url,$data);
}
if ($properties[$i]["TITLE"] == "pulse")
{
$url = "http://$ip:$port/zeroconf/pulse";
if ($value == 1) $val = 'on';
if ($value == 0) $val = 'off';
$table='sonoff_diy_data';
$pulseWidth=SQLSelectOne("SELECT * FROM $table WHERE DEVICE_ID=". $rec['ID'] ." and TITLE = 'pulseWidth'");
$data = array();
$data['deviceid'] = $rec['DEVICE_ID'];
$data['data'] = array();
$data['data']['pulse'] = $val;
$data['data']['pulseWidth'] = intval($pulseWidth["VALUE"]);
$this->callApi($url,$data);
}
if ($properties[$i]["TITLE"] == "pulseWidth")
{
$url = "http://$ip:$port/zeroconf/pulse";
$table='sonoff_diy_data';
$pulse=SQLSelect("SELECT * FROM $table WHERE DEVICE_ID=". $rec['ID'] ." and TITLE = 'pulse'");
if ($pulse["VALUE"] == 1) $val = 'on';
if ($pulse["VALUE"] == 0) $val = 'off';
$data = array();
$data['deviceid'] = $rec['DEVICE_ID'];
$data['data'] = array();
$data['data']['pulse'] = $val;
$data['data']['pulseWidth'] = intval($value);
$this->callApi($url,$data);
}
}
}
}
@@ -272,7 +319,7 @@ function callAPI($url, $params = 0)
try
{
$data_string = json_encode($params);
registerError('sonoff_diy', $url. " " . $data_string);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
@@ -283,13 +330,20 @@ function callAPI($url, $params = 0)
);
$result = curl_exec($ch);
//registerError('sonoff_diy', 'result - '.$url.' == '.$result);
registerError('sonoff_diy', 'Result query - '.$url.' == '. $result);
$result = json_decode($result);
}
catch (Exception $e)
{
registerError('sonoff_diy', 'Error send query - '.$url.' == '.get_class($e) . ', ' . $e->getMessage());
$result = array();
$result["error"] = 1;
$result["data"] = array();
$result["data"]["class"] = get_class($e);
$result["data"]["message"] = $e->getMessage();
}
return true;
return $result;
}
@@ -347,7 +401,7 @@ function updateData($name, $data)
$value["VALUE"] = $val;
SQLUpdate($table_name, $value);
if ($value['LINKED_OBJECT'] && $value['LINKED_PROPERTY']) {
setGlobal($value['LINKED_OBJECT'] . '.' . $value['LINKED_PROPERTY'], $val);
setGlobal($value['LINKED_OBJECT'] . '.' . $value['LINKED_PROPERTY'], $val, array($this->name => '0'));
}
}
}
@@ -424,6 +478,7 @@ function processCycle() {
print_r($d);
$this->updateDevice($name,"DEVICE_ID",$d['id']);
$this->updateDevice($name,"UPDATED",date('Y-m-d H:i:s'));
//update data device
$this->updateData($name,json_decode($d['data1']));
}
@@ -11,17 +11,12 @@
$ok=1;
// step: default
if ($this->tab=='') {
//updating '<%LANG_TITLE%>' (varchar, required)
//updating TITLE (varchar, required)
$rec['TITLE']=gr('title');
if ($rec['TITLE']=='') {
$out['ERR_TITLE']=1;
$ok=0;
}
//updating '<%LANG_UPDATED%>' (datetime)
global $updated_date;
global $updated_minutes;
global $updated_hours;
$rec['UPDATED']=toDBDate($updated_date)." $updated_hours:$updated_minutes:00";
}
// step: data
if ($this->tab=='data') {
@@ -82,10 +77,6 @@
for($i=0;$i<$total;$i++) {
if ($properties[$i]['ID']==$new_id) continue;
if ($this->mode=='update') {
global ${'title'.$properties[$i]['ID']};
$properties[$i]['TITLE']=trim(${'title'.$properties[$i]['ID']});
global ${'value'.$properties[$i]['ID']};
$properties[$i]['VALUE']=trim(${'value'.$properties[$i]['ID']});
global ${'linked_object'.$properties[$i]['ID']};
$properties[$i]['LINKED_OBJECT']=trim(${'linked_object'.$properties[$i]['ID']});
global ${'linked_property'.$properties[$i]['ID']};
@@ -81,15 +81,15 @@ <h4 class="modal-title">Sonoff DIY</h4>
<img src="/img/modules/sonoff_diy.png" width="48" height="48">
</div>
<p class="float-left"> Sonoff DIY.<br>
Обсуждение модуля <a href="http://majordomo.smartliving.ru/forum/viewtopic.php?f=5" target="_blank">здесь</a>.<br>
Обсуждение модуля <a href="http://majordomo.smartliving.ru/forum/viewtopic.php?f=5&t=6720" target="_blank">здесь</a>.<br>
</p>
<hr size="1">
<p class="float-left">
Поддержать автора материально:
<ul>
<li>Yandex: <a href="https://money.yandex.ru/to/410012076838296/100" target="_blank">410012076838296</a></li>
<li>WebMoney: R366396529511</li>
<li><a href="https://connect.smartliving.ru/profile/186" target="_blank">Connect</a></li>
<li><a href="https://connect.smartliving.ru/tasks/543.html" target="_blank">Connect</a></li>
</ul>
</p>
</div>
@@ -25,8 +25,8 @@
</tr>
[#begin PROPERTIES#]
<tr>
<td valign="top"><input type="text" name="title[#ID#]" id="title[#ID#]" value="[#TITLE#]"></td>
<td valign="top"><input type="text" name="value[#ID#]" id="value[#ID#]" value="[#VALUE#]"></td>
<td valign="top">[#TITLE#]</td>
<td valign="top">[#VALUE#]</td>
<td valign="top"><input type="text" name="linked_object[#ID#]" id="linked_object[#ID#]" value="[#LINKED_OBJECT#]"></td>
<td valign="top"><input type="text" name="linked_property[#ID#]" id="linked_property[#ID#]" value="[#LINKED_PROPERTY#]"></td>
<td valign="top"><input type="text" name="linked_method[#ID#]" id="linked_method[#ID#]" value="[#LINKED_METHOD#]"></td>
@@ -26,14 +26,22 @@
<tbody>
[#begin RESULT#]
<tr>
<td
>
<td>
<b>
[#TITLE#]
</a></b>
</td>
<td
>
<td>
<b>
[#IP#]
</a></b>
</td>
<td>
<b>
[#ONLINE#]
</a></b>
</td>
<td>
[#if UPDATED!=""#]
[#UPDATED#]
[#else#]

0 comments on commit 214b998

Please sign in to comment.
You can’t perform that action at this time.