script and json

I wanted to monitor with domoticz the temperature of a modem on a RBM11 routerboard.
I detect the temperature of the modem with a script that is saved every minute in the variable temp2.
with the command via browser http://10.100.0.202:8080/json.htm?username=xxx&password=xxx&type=command&param=udevice&idx=27&nvalue=0&svalue=30
where 10…is the home automation server idx=27 the virtual sensor on domoticz and svalue=30 the temperature entered manually.
With this command from the browser everything works.

However, if I try via mikrotik script nothing works
/tool fetch http-method=post http-header-field=“Content-Type: application/json” http-data=“{username=xxx&password=xxx&type=command&param=udevice&idx=27&nvalue=0&svalue=$temp2}” url=“http://10.100.0.202:8080
what is the correct line to write?
There are no instructions in the mikrotik manual.

Search first:
http://forum.mikrotik.com/t/fetch-post-to-azure-function-results-in-bad-request/150878/5

and url must be …202:8080/json.htm not only …202:8080

and your command via browser is not even “post”, but “get”, equivalent with fetch would be to use http-method=get and the same full URL as in the browser.

:local url "http://10.100.0.202:8080/json.htm?username=xxx&password=xxx&type=command&param=udevice&idx=27&nvalue=0&svalue="
/tool fetch http-method=get http-header-field="content-type:application/json" url=$url $temp2

I have modified it this way but the script does not work
the variable $temp2 seems to be ignored

$temp2 is writed at random position?
At least url=“$url$temp2”


For terminal adding { } and \ before ?, removig anything you do not do in browser, like set content or specify get or post:

{
:local url="http://10.100.0.202:8080/json.htm?username=xxx&password=xxx&type=command&param=udevice&idx=27&nvalue=0&svalue=$temp2"
/tool fetch keep-result=no url=$url
}

For script (useless { } \ )

:local url="http://10.100.0.202:8080/json.htm?username=xxx&password=xxx&type=command&param=udevice&idx=27&nvalue=0&svalue=$temp2"
/tool fetch keep-result=no url=$url

temp2.png
I modified the script like yours above but it still doesn’t work.
temp2 is a global variable obtained from another script every minute

if you place, for test, a right value instead of $temp2, work?

post the temp2 script

no if I enter a value it does not work.
I think it’s not a problem with the variable but with the way fetch works.
Here is the script

:set temp1 55
:global temp (:tostr(:put [/ interface lte at-chat input="at+qtemp" lte1 wait=yes as-value]));
:global tempstring ([:pick $temp 0]);
:global temp2 ([:pick $tempstring 47] . [:pick $tempstring 48]);
:if ($temp2 > $temp1) do= {/tool fetch url="https://api.telegram.org/xxxxxx/text=EM160 Warning!!! Temperature is $temp2 Degrees" keep-result=no}

I do not know the format returned, but this is the right way to do that, :put is only for display on terminal the items, not for read results of operation.
The script is all it? You cut something (ignore censoring)???

# dice allo script di considerare la variabile temp1 gia' esistente
:global temp1
:set temp1 55
# mette in temp2 il risultato della richiesta, ma va tagliato con :pick, come hai già fatto, se non da un numero e basta
:global temp2 ([/interface lte at-chat input="at+qtemp" lte1 wait=yes as-value]->"output")
:if ($temp2 > $temp1) do={
    /tool fetch keep-result=nourl="https://api.telegram.org/xxxxxx/text=EM160 Warning!!! Temperature is $temp2 Degrees"
}

yes that’s it, that script sends a telegram message if the modem temperature is above 55 degrees and monitors the temperature every minute.
My problem, however, is to send that string http: //10.100.0.202 … and retrieve the temperature from the temp2 variable. i can’t find documentation for scripts with json .

but if pasted on browser work, without doing anything special, on fetch url must wokrs, but all non “a-z” and “0-9” on censored values must be url converted, browser do it automatically.
For example if you have & or ! on password, you must urlencode it and put on fetch url

the censored parts do not have any special characters or spaces they are only letters and numbers, I also tried to convert the whole string http://10.100.0… with an on line urlencoder but it does not work. the script does not create any url variable in Environment. I have Ros 7.1rc1.

I solved by forwarding port 8443 !!!!

script on the LTE router and should be scheduled every 4-5 minutes

#temperature read by another script
:global temp2

#temp value transfer to domoticz on idx27 through NAT port 8443   
:global url "https://192.168.x.x:8443/json.htm?username=user&password=password&type=command&param=udevice&idx=27&nvalue=0&svalue=$temp2";
/tool fetch keep-result=no url=$url mode=https

#forwarding rule on the main router
/ip firewall nat add chain=dstnat dst-port=8443 action=dst-nat protocol=tcp to-address=10.100.0.202 to-port=8443

Nice work. Congratulations succeeding in this.