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¶m=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¶m=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.
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.
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.
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¶m=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