It worked!! Thanks! However, I got a lot of:
2018-09-01 16:36:16.466 [ERROR] [.smarthome.model.script.actions.HTTP] - Fatal transport error: java.util.concurrent.TimeoutException
but if I executed the rules twice it did the second time without error. Very strange.
However, it turned out that the token expires and I have to renew it. I can get it to post the json
That is because the returned String is NOT a valid JSON
Try:
logInfo("Reolink ", ReolinkToken)
var String Json_test = ReolinkToken.substringBetween("[", "]") // Remove first pair of "[ ]"
Json_test = Json_test.substringBetween("{", "}") // Remove first pair of "{ }" Now we have a valid JSON
Json_test = transform( "JSONPATH", "$.value.Token.name", Json_test )
logInfo("Reolink Token ", Json_test)
It worked, but it still very unreliable. Some time I get these error messages:
2018-09-01 22:10:01.025 [ERROR] [.smarthome.model.script.actions.HTTP] - Fatal transport error: java.util.concurrent.TimeoutException
2018-09-01 22:10:03.055 [INFO ] [pse.smarthome.model.script.Reolink 1] - null
I tried to run the script 3 time in the hope that it would work more reliable
rule "UpdateReolinkToken"
when
Time cron "0 0/5 * 1/1 * ? *"
then
var String ReolinkString ="[{\"cmd\":\"Login\",\"action\":0,\"param\":{\"User\":{\"userName\":\"admin\",\"password\":\"MyPassword\"}}}]"
val String ReolinkPost = "http://192.168.2.39/cgi-bin/api.cgi?cmd=Login&token=null"
val String ReolinkPayloadType = "application/json"
var String RelolinkToken = sendHttpPostRequest(ReolinkPost, ReolinkPayloadType, ReolinkString )
Thread::sleep(2000)
logInfo("Reolink 1", RelolinkToken)
RelolinkToken = sendHttpPostRequest(ReolinkPost, ReolinkPayloadType, ReolinkString )
logInfo("Reolink 2", RelolinkToken)
Thread::sleep(2000)
RelolinkToken = sendHttpPostRequest(ReolinkPost, ReolinkPayloadType, ReolinkString )
logInfo("Reolink 3", RelolinkToken)
Json_ReolinkToken = RelolinkToken.substringBetween("[", "]") // Remove first pair of "[ ]"
Json_ReolinkToken = transform( "JSONPATH", "$.value.Token.name", Json_ReolinkToken )
logInfo("Reolink Token ", Json_ReolinkToken)
end