openhab / openhab-js

openHAB JavaScript Library for JavaScript Scripting Automation
https://www.openhab.org/addons/automation/jsscripting/
Eclipse Public License 2.0
38 stars 31 forks source link

ACTION HTTP - debuging? #352

Closed JacekKac closed 3 months ago

JacekKac commented 3 months ago

i am not able to send a valid http request with action.HTTP, not sure how to debug the problem, i will be grateful for your help. i tried to set TRACE log level on my script LOG:SET TRACEopenhab.automation.script.file.Teedee.js but i don't see any details what is going wrong.


var CryptoJS = require('crypto-js');
rules.JSRule({
  name: `Tede`,
  id: `Tede`,
  tags: [`_DYNAMIC_`],
  overwrite: `true`,
  description: `Wlacznik tede`,
  triggers: [triggers.ItemCommandTrigger('teedeeaction')],
  execute: (event) => {
                            var API_TOKEN = "abcdefg"
                            var TIMESTAMP = new Date().getTime();
                            var hash = CryptoJS.SHA256(API_TOKEN+TIMESTAMP).toString()
                            var API_KEY = hash+TIMESTAMP
                            console.log(hash);
                            console.log(API_KEY)
                            console.log(event.receivedCommand)
                            var api = "http://192.168.0.14:1880/lock/12345678/lock?api_token="+API_KEY;
                    console.log("dostał 2 otwieram")
                    console.log(api);
                    actions.HTTP.sendHttpPostRequest(api,1000)
            }
});

2024-06-30 14:54:38.976 [INFO ] [hab.automation.script.file.Teedee.js] - dostał 2 otwieram 2024-06-30 14:54:38.978 [INFO ] [hab.automation.script.file.Teedee.js] - http://192.168.0.14:1880/lock/126396/lock?api_token=92e3793fb4f8abc4ddc801a9281da5dc20c58eddc03d78830781b3291c3c221719752078951 2024-06-30 14:55:42.839 [INFO ] [hab.automation.script.file.Teedee.js] - 3722f747354dbd59d2e40e3bcaf7fc3cf1ed186bd625c229cc4f68623fffaa 2024-06-30 14:55:42.840 [INFO ] [hab.automation.script.file.Teedee.js] - 3722f747354dbd59d2e40e3bcaf7fc3cf1ed186bd625c229cc4f68623fffaa1719752142831 2024-06-30 14:55:42.841 [INFO ] [hab.automation.script.file.Teedee.js] - undefined

JacekKac commented 3 months ago

ok i got it, bad endpoint address and added a result = action.HTTP* to get the result