I have been basing my script on some examples that parse JSON from an external service back to the IMP.
However, the request is made, but the set(1) function seemingly is never called back, as the log() or show() does not kick in.
Here is the code, anyone see any problems on this?
`
// Receive JSON Data from External
local astronomy = OutputPort(“Astronomy”,“number”);
// this class receives the json data
class Astronomy extends InputPort {
function set(payload) {
server.log("data received");
server.show("data received");
//to figure out json structure uncomment the following and check the log output
//dumptable("",payload);
//all the data is considered a string, so convert to integer or whatever as necessary
local variable = payload.moon_phase.sunset.hour.tointeger();
//doSomethingWith(variable);
//schedule another update in 1 minute
imp.wakeup(10, getAstronomyData);
}
}
function getAstronomyData() {
server.log(“data requested”);
server.show(“data requested”);
astronomy.set(1); //initiates outbound connection to retrieve astronomy data
//imp.wakeup(10, getAstronomyData);
}
function dumptable(p, t) {
foreach(key, value in t) {
if (typeof value == "table") {
dumptable(p+"."+key, value);
}
else server.log(p+"."+key + " = " + value);
}
}
server.log(“IMP started”);
server.show(“IMP started”);
imp.configure(“Outdoor Activation”, [Astronomy(“astronomy”,“string”) ], [astronomy]);
getAstronomyData();
// END OF CODE
`