I have been trying the last few days to use the Spark Core https://www.spark.io/ to replace a whole lot of things in my garage. This includes four switches to open garage doors and switch lights on and off. The switches I got going easy enough.
I also want to use the digitalread on the rest of the pins to read the state of the garage doors. The simplest implementation with my limited knowledge was to read the state of the digital pins from two simple Megatronix-Magnetic-Switch-Sensors on the doors and to write it to a variable in the Variable container plugin. While testing I did this using the code below:
local socket = require("socket") local https = require("ssl.https") local ltn12 = require("ltn12") https.TIMEOUT = 5 -- Read the state of Pin A3 from the body by finding then isolating the return value in the body local body, code, headers, status = https.request("https://api.spark.io/v1/devices/[MY_DEVICE_ID]/analogread", "access_token=[MY_ACCESS_TOKEN]&args=A3") luup.log("A3 status:" .. status) local rvlocation = string.find(body, "return_value") local state = string.sub(body,rvlocation+15,rvlocation+16) -- Write the value to the variable container device 143 luup.variable_set("urn:upnp-org:serviceId:VContainer1","Variable1",state,143)
It worked well in the Test Luup code section so I made a scene that runs this every minute… On refresh, the dreaded “Luup engine is taking longer to reload” message. So it took me about 4 hours to get back to where I was. The solution by the way was this:
Find the password in a previous backup file, SSH using Putty and run the following commands:
cp user_data.json.lzo user_data.json.lzo-1
cp user_data.json.lzo.1 user_data.json.lzo-2
cp user_data.json.lzo.1 user_data.json.lzo
See if that fixes it … If not then try:
cp user_data.json.lzo.2 user_data.json.lzo-3
cp user_data.json.lzo.2 user_data.json.lzo
So, back to square one.
Then, since I thought that every minute might be too much I made the scene run every 10 minutes. This worked a while (maybe twice) and then again, “Luup engine is taking longer to reload”…
The second time round the solution above did not work. I basically had to factory reset the device doing the following:
- Plug all out of the device
- Plug in the power plug
- Hold down the reset button for something like 30 seconds.
- Wait (5-10 minutes) One by one the Power light then the ZWave light and then the internet light will go on
- Then restore the last backup.
Ok, so here is my question: Am I doing something stupid in the code above? Is there a better way to do this? How can I do this without destroying my Vera and subsequently get more sleep?
Any help would be appreciated.
PS. I’m typing this all to try and help the next guy with this problem.