function Zwavecancelaction()
{
    global $domoticzurl;
    $zwaveurl = $domoticzurl . 'ozwcp/admpost.html';
    $zwavedata = array('fun' => 'cancel');
    $zwaveoptions = array('http' => array('header' => 'Content-Type: application/x-www-form-urlencoded\\r\\n', 'method' => 'POST', 'content' => http_build_query($zwavedata)));
    $zwavecontext = stream_context_create($zwaveoptions);
    $result = file_get_contents($zwaveurl, false, $zwavecontext);
}
if (!empty($argv[1]) && !empty($argv[2])) {
    RefreshZwave2($argv[1], $argv[2]);
    //$mc->set('RefreshZwave'.$argv[1], $time);
} else {
    logwrite("RefreshZwave: no idx or name defined");
}
sleep(3);
if ($mc->get('deadnodes') < $eenmin) {
    foreach ($devices as $node => $data) {
        if ($node == "result") {
            foreach ($data as $index => $eltsNode) {
                if ($eltsNode["State"] == "Dead") {
                    telegram('Node ' . $eltsNode['NodeID'] . ' ' . $eltsNode['Description'] . ' (' . $eltsNode['Name'] . ') marked as dead, reviving ' . ZwaveHasnodefailed($eltsNode['NodeID']));
                    sleep(2);
                    Zwavecancelaction();
                    //shell_exec('/var/www/secure/reboot.sh');
                }
            }
        }
    }
    $mc->set('deadnodes', $time);
}
function RefreshZwave($node, $name = 'auto', $device = '')
{
    global $domoticzurl, $time, $zwaveidx, $vijfmin, $actions;
    $devices = json_decode(curl($domoticzurl . 'json.htm?type=openzwavenodes&idx=' . $zwaveidx), true);
    //logwrite('Refreshing node '.$node.' '.$device.' '.$name);
    $zwaveurl = $domoticzurl . 'ozwcp/refreshpost.html';
    $zwavedata = array('fun' => 'racp', 'node' => $node);
    $zwaveoptions = array('http' => array('header' => 'Content-Type: application/x-www-form-urlencoded\\r\\n', 'method' => 'POST', 'content' => http_build_query($zwavedata)));
    $zwavecontext = stream_context_create($zwaveoptions);
    for ($k = 1; $k <= 5; $k++) {
        $result = file_get_contents($zwaveurl, false, $zwavecontext);
        $actions = $actions + 1;
        if ($result === 'OK') {
            cset('timerefresh-' . $device, $time);
            break;
        }
        sleep(1);
    }
    if (cget('timedeadnodes') < $vijfmin) {
        cset('timedeadnodes', $time);
        foreach ($devices as $node => $data) {
            if ($node == "result") {
                foreach ($data as $index => $eltsNode) {
                    if ($eltsNode["State"] == "Dead" && !in_array($eltsNode['NodeID'], array(50))) {
                        $actions = $actions + 1;
                        telegram('Node ' . $eltsNode['NodeID'] . ' ' . $eltsNode['Description'] . ' (' . $eltsNode['Name'] . ') marked as dead, reviving ' . ZwaveHasnodefailed($eltsNode['NodeID']));
                        sleep(2);
                        Zwavecancelaction();
                    }
                }
            }
        }
    }
    return $result;
}