Beginner questions

General discussions about Automagic and automation in general

Moderator: Martin

robchoc
Posts: 81
Joined: 20 Jun 2018 12:38

Re: Beginner questions

Post by robchoc » 26 Sep 2018 17:20

Unfortunately, I'm still getting the same error: sh: syntax error: '(' unexpected

Ok, this is what I'm doing exactly, maybe I misinterpreting some of your instructions.


I'm typing the following in the script:

Code: Select all

message = pounds;

js = newMapFromValues(
"text", message,
"callSignNames", "m0tff",
"transmitterGroupNames", "all",
"emergency", false);
Then in the execute command I'm using the following:

Code: Select all

command = 'curl -H "Content-Type: application/json" -X POST -u "m0tff:MyPassword" -d ' + toJSON(js, false) + ' http://hampager.de/api/calls';
Does that all look correct?
I will try the HTTP Request once I have this bit working.

Thanks

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Beginner questions

Post by Desmanto » 26 Sep 2018 17:31

Ah, so that's the problem. The command = .... is together in the script, not separated as your reply above.

Code: Select all

message = pounds;

js = newMapFromValues(
"text", message,
"callSignNames", "m0tff",
"transmitterGroupNames", "all",
"emergency", false);

command = 'curl -H "Content-Type: application/json" -X POST -u "m0tff:MyPassword" -d ' + toJSON(js, false) + ' http://hampager.de/api/calls';
In the execute command, the field command only use {command}

Action : Execute Command
Command : {command}

Because we have assigned the full complete command to the variable {command} in the previous script.
I prefer to use this practice, since I can have better view of the command when troubleshooting it in debug dialog.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

robchoc
Posts: 81
Joined: 20 Jun 2018 12:38

Re: Beginner questions

Post by robchoc » 26 Sep 2018 18:31

Still not working but I have a lot of debug data that might help:

command

Code: Select all

curl -H "Content-Type: application/json" -X POST -u "m0tff:Password" -d {"text":"1.52","callSignNames":"m0tff","transmitterGroupNames":"all","emergency":false} http://hampager.de/api/calls
stderr

Code: Select all

curl: (6) Couldn't resolve host 'callSignNames'
curl: (6) Couldn't resolve host 'transmitterGroupNames'
curl: (6) Couldn't resolve host 'emergency'
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100   132  100   123  100     9    777     56 --:--:-- --:--:-- --:--:--  1108
stdout

Code: Select all

{
  "code": 4003,
  "name": "Invalid Json",
  "message": "Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $"
}
Thanks

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Beginner questions

Post by Desmanto » 27 Sep 2018 01:27

Oh, i get the same when test it in terminal. So it seems the json part still have to be single quoted. I just add 2 escaped single quote surrounding the json

Code: Select all

message = "1.52";

js = newMapFromValues(
"text", message,
"callSignNames", "m0tff",
"transmitterGroupNames", "all",
"emergency", false);

command = 'curl -H "Content-Type: application/json" -X POST -u "m0tff:Password" -d \'' + toJSON(js, false) + '\' http://hampager.de/api/calls';
Now it will be (additional single quote surrounding the json).

Code: Select all

curl -H "Content-Type: application/json" -X POST -u "m0tff:Password" -d '{"text":"1.52","callSignNames":"m0tff","transmitterGroupNames":"all","emergency":false}' http://hampager.de/api/calls
I got not authorized. It should be correct now. You only need to change the code to your password.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

robchoc
Posts: 81
Joined: 20 Jun 2018 12:38

Re: Beginner questions

Post by robchoc » 27 Sep 2018 07:00

Still, something not quite right I get the following now in stdout:

{
"code": 4003,
"name": "Invalid Json",
"message": "Expected BEGIN_ARRAY but was STRING at line 1 column 38 path $.callSignNames"
}

I hope the HTTP version is simpler to get working. It's very frustrating moving over to a new language when you are not sure what you are doing, so I really appreciate all the time you are putting into helping me.

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Beginner questions

Post by Desmanto » 27 Sep 2018 08:52

The error actually already making me questioning whether call sign is an array (list object). And turns out yes it is. I googled the API and found it here : https://hampager.de/dokuwiki/doku.php?i ... pisendcall
Call sign and transmitter group is a list. I double check your original tasker command and found out the []. My bad, I ignore these, thinking it is something related to tasker. Should pay attention more when converting the json.

So now, we have to create newList() at the call sign and transmitter.

Code: Select all

message = "1.52";

js = newMapFromValues(
"text", message,
"callSignNames", newList("m0tff"),
"transmitterGroupNames", newList("all"),
"emergency", false);

command = 'curl -H "Content-Type: application/json" -X POST -u "m0tff:Password" -d \'' + toJSON(js, false) + '\' http://hampager.de/api/calls';
The command should contain this.

Code: Select all

curl -H "Content-Type: application/json" -X POST -u "m0tff:Password" -d '{"text":"1.52","callSignNames":["m0tff"],"transmitterGroupNames":["all"],"emergency":false}' http://hampager.de/api/calls
Note the difference is at the [ ]. The http version should be working too if the json is correct already.

Sorry, it should be not so hard actually. I just forgot what I have been using in tasker. It is my typical troubleshooting when creating new flow. And it is thru the case usage like this, I have been learning so much until now.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

robchoc
Posts: 81
Joined: 20 Jun 2018 12:38

Re: Beginner questions

Post by robchoc » 27 Sep 2018 10:54

Working perfectly, really appreciate all the help.

Dare I try the HTTP version...I think so as I want to learn as much as I can about how to use Automagic and then try to help others with it in my other automation groups. :)

HTTP is working perfectly too. Yay :D

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Beginner questions

Post by Desmanto » 27 Sep 2018 17:36

Wow, that's nice. So it seems the username password in HTTP request is working fine for the login. I should try it later then to my router, to see if it works too.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Post Reply