Du hast es nicht anders gewollt 
Ich benutze KVS um Daten zwischen master und worker auszutauschen. Z.B. in diesem Fall die Config. Das könnte auch das Problem des TE lösen.
Müsste er dann nur für sein Problem anpassen.
master:
let Config = {
//############# comfig ##########################################################
net : "172.16.0.",
devices : ["62","64","67","68","69","70","71","72","73","75","76"],
user : "",
pass : "",
//report_at : "00:15",
report_at : "12:00",
//Messages based on https://www.callmebot.com
//phone_number : "+4917112345678",
phone_number : "",
//Signal e.g. : "" empty string, if not needed
//sig_api_key : "123456",
sig_api_key : "",
//WhatsApp e.g. : "" empty string, if not needed
//wap_api_key : "123456",
wap_api_key : ""
//###############################################################################
};
function report() {
if (Shelly.getComponentStatus("sys").time === Config.report_at) {
Shelly.call("kvs.getmany", {"key":Config["net"]},
function(result, error_code, error_message) {
let m = "";
let d = "";
let v = "";
let items = result["items"];
for (let i=0;i<Config["devices"].length; i++) {
d = Config["net"] + Config["devices"][i];
v = items[Config["net"] + Config["devices"][i]]["value"]["batt"];
m += d + "+batt:+" + JSON.stringify(v) + "%+" + "%0A%0A";
}
send_message(m);
}
);
}
};
function send_message(message) {
message = Shelly.getComponentStatus("sys").time + "%0A%0A" + message;
if (Config.sig_api_key) {
let sig_url = "https://signal.callmebot.com/signal/send.php?phone=";
sig_url += Config.phone_number;
sig_url += "&apikey=" + Config.sig_api_key + "&text=";
Shelly.call("http.get", {url:sig_url + message,timeout:30});
}
if (Config.wap_api_key) {
let wap_url = "https://api.callmebot.com/whatsapp.php?phone=";
wap_url += Config.phone_number;
wap_url += "&text=" + message + "&apikey=" + Config.wap_api_key;
Shelly.call("http.get", {url:wap_url,timeout:30});
}
};
function log(what) {
time = Shelly.getComponentStatus("sys").time;
console.log(time + " " + what);
};
function get_worker_id(){
Shelly.call("Script.List","",
function(result, error_code, error_message){
let a = result["scripts"];
for (let i=0; i<a.length; i++) {
if (a[i]["name"].slice(0, 6) === "worker"){
worker_id = a[i]["id"];
}
}
if (worker_id === 0) {
log("script stopped: worker script not found.");
Shelly.call("script.stop", {"id":Shelly.getCurrentScriptId()});
}
}
);
};
function configure() {
let val = {"ts":Shelly.getComponentStatus("sys").unixtime,"batt":100};
counter ++;
if (counter < Config["devices"].length) {
let dev = Config["net"] + Config["devices"][counter];
log("configure device " + dev);
Shelly.call("kvs.set", {"key":dev,"value":val});
}
else {
log("configure timeout " + JSON.stringify(timeout) + " seconds");
log("configure done");
Timer.clear(t1);
counter = -1;
t1 = Timer.set(timeout * 1000,true,run);
}
};
function run () {
Shelly.call("script.stop", {"id":worker_id});
if (counter >= Config.devices.length - 1) {
counter = -1;
}
counter += 1;
item = Config["net"] + Config["devices"][counter];
let val = {"dev":item, "Config":Config};
Shelly.call("kvs.set", {"key":"current","value":val});
Shelly.call("script.start", {"id":worker_id});
Shelly.call("kvs.get", {"key":item},
function(result, error_code, error_message) {
let delta = Shelly.getComponentStatus("sys").unixtime - result["value"]["ts"];
if (delta > 1200) {
log(item + " R E B O O T");
Shelly.call("http.get", {url:pre + item + "/reboot",timeout:60});
send_message(item + "%0AR+E+B+O+O+T");
let val2 = {"ts":Shelly.getComponentStatus("sys").unixtime};
Shelly.call("kvs.set", {"key":item,"value":val2});
}
}
);
};
let worker_id = 0;
let counter = -1;
let pre = "";
let item = "";
let time = "";
let wait = 165000/Config["devices"].length;
let timeout = Math.round(wait/1000) - 1;
log("start up...");
if (Config["user"].length > 0) {
pre = "http://" + Config["user"] + ":" + Config["pass"] + "@";
}
get_worker_id();
send_message('master+started');
let t1 = Timer.set(300,true,configure);
if (Config.report_at) {
let t2 = Timer.set(60000,true,report);
}
Alles anzeigen
worker:
function send_message(message) {
message = Shelly.getComponentStatus("sys").time + "%0A" + message;
if (Config.sig_api_key) {
let sig_url = "https://signal.callmebot.com/signal/send.php?phone=";
sig_url += Config.phone_number;
sig_url += "&apikey=" + Config.sig_api_key + "&text=";
Shelly.call("http.get", {url:sig_url + message,timeout:30});
}
if (Config.wap_api_key) {
let wap_url = "https://api.callmebot.com/whatsapp.php?phone=";
wap_url += Config.phone_number;
wap_url += "&text=" + message + "&apikey=" + Config.wap_api_key;
Shelly.call("http.get", {url:wap_url,timeout:30});
}
};
function go (){
Shelly.call("http.get", {url:pre + cur + "/psovrd2"},
function(result, error_code, error_message) {
Shelly.call("http.get", {url:pre + cur + "/status"},
function(res, err_code, err_message) {
let json = JSON.parse(res.body);
let percent = json["bat"]["value"];
let rssi = json["wifi_sta"]["rssi"];
let temp = JSON.stringify(json["thermostats"]["0"]["tmp"]["value"]);
if (temp.indexOf(".") === -1) {
temp += ".0";
}
temp = temp.slice(0,4);
let unit = json["thermostats"]["0"]["target_t"]["units"];
if (percent === 100) {
percent = 99;
}
let time = Shelly.getComponentStatus("sys").time;
let tolog = time + " " + cur + " batt: " + JSON.stringify(percent) + "% ";
tolog += "rssi: " + JSON.stringify(rssi) + "dBm ";
tolog += "tmp: " + temp + " degrees " + unit;
console.log(tolog);
let val = {"ts":Shelly.getComponentStatus("sys").unixtime,"batt":percent};
Shelly.call("kvs.set", {"key":cur,"value":val});
}
);
}
);
};
let cur = "";
let pre = "";
let Config = {};
Shelly.call("kvs.get", {"key":"current"},
function(result, error_code, error_message) {
cur = result["value"]["dev"];
Config = result["value"]["Config"];
if (Config["user"].length > 0) {
pre = "http://" + Config["user"] + ":" + Config["pass"] + "@";
}
go();
}
);
Alles anzeigen