...ho fatto come mi hai consigliato e ho utilizzato il metodo JSON.Parse() per passare ad una variabile di appoggio di tipo oggetto x.body:
codice:
phaseAOfOtherEM = JSON.parse(x.body);
; ho poi utilizzato la notazione a punti per accedere al valore di act_power:
codice:
print("Phase A other EM: W " + phaseAOfOtherEM.act_power);
Grazie per il consiglio, prezioso!
Altra domanda (e spero l'ultima), perché così funziona
codice:
function startMonitorOtherEM() { let phaseAOfOtherEM = null;
let phaseBOfOtherEM = null;
let totalPhaseOfOtherEM = null;
let ip = "192.168.178.170";
Timer.set(10000, true, function status() {
Shelly.call("HTTP.GET", {"url":"http://" + ip + "/rpc/EM1.GetStatus?id=0"}, function(result, error_code, error_msg, ud) {
phaseAOfOtherEM = JSON.parse(result.body);
print("Phase A of other EM: W " + phaseAOfOtherEM.act_power);
})
Shelly.call("HTTP.GET", {"url":"http://" + ip + "/rpc/EM1.GetStatus?id=1"}, function(result, error_code, error_msg, ud) {
phaseBOfOtherEM = JSON.parse(result.body);
print("Phase B of other EM: W " + phaseBOfOtherEM.act_power);
totalPhaseOfOtherEM = (phaseBOfOtherEM.act_power) + (phaseBOfOtherEM.act_power);
print("Total phase of other EM: W " + totalPhaseOfOtherEM);
})
})
}
startMonitorOtherEM();
mentre così
codice:
function startMonitorOtherEM() { let phaseAOfOtherEM = null;
let phaseBOfOtherEM = null;
let totalPhaseOfOtherEM = null;
let ip = "192.168.178.170";
Timer.set(10000, true, function status() {
Shelly.call("HTTP.GET", {"url":"http://" + ip + "/rpc/EM1.GetStatus?id=0"}, function(result, error_code, error_msg, ud) {
phaseAOfOtherEM = JSON.parse(result.body);
print("Phase A of other EM: W " + phaseAOfOtherEM.act_power);
})
Shelly.call("HTTP.GET", {"url":"http://" + ip + "/rpc/EM1.GetStatus?id=1"}, function(result, error_code, error_msg, ud) {
phaseBOfOtherEM = JSON.parse(result.body);
print("Phase B of other EM: W " + phaseBOfOtherEM.act_power);
})
totalPhaseOfOtherEM = (phaseBOfOtherEM.act_power) + (phaseBOfOtherEM.act_power);
print("Total phase of other EM: W " + totalPhaseOfOtherEM);
})
}
startMonitorOtherEM();
ricevo l'errore [COLOR=var(--secondary)]Uncaught Error: Cannot read property 'act_power' of null [/COLOR][COLOR=var(--secondary)]at ...fOtherEM = (phaseBOfOtherEM.act_power) + (phaseBOfOtherEM.ac...[/COLOR][COLOR=var(--secondary)]^[/COLOR][COLOR=var(--secondary)]in function called from system?[/COLOR][COLOR=var(--secondary)]
[/COLOR]