Unfortunately, I don't think the easy-to-use HTTPDevice app supports passing the on/off command as a JSON object in a POST request. Fortunately, there are other ways to accomplish what you want. One approach is to create a virtual binary switch using Virtual Device (JavaScript) app. You can read how to send an HTTP POST request with a "Content-type: application/json" from here:
Code: Select all
https://z-wave.me/manual/z-way/JavaScript_Engine.html#SECTION001321000000000000000
A second approach is to run a local python http server (something like: /usr/bin/python3 -m http.server --cgi 8000) and use the HTTPDevice app to
http://127.0.0.1:8000/on or off or stat that invokes a cgi script that's nothing more than a shell script that runs a wget or curl command. The idea is to create the correct POST request in the CGI script from a Z-Way GET request. Be sure to set a timeout on the command. Your CGI shell script should be located in a cgi-bin directory in the home directory of the user that ran the python http server command (which I named "my_cgi_script.sh") and look something like this:
Code: Select all
#!/usr/bin/bash
case $1 in
on)
wget -t 2 -T 5 --connect-timeout=5 -w 2 --no-http-keep-alive --max-redirect=0 --header="Content-type: application/json" --post-data '{"mode":0}' -q -O /dev/null http://192.168.0.57/control
echo -n "on"
;;
off)
wget -t 2 -T 5 --connect-timeout=5 -w 2 --no-http-keep-alive --max-redirect=0 --header="Content-type: application/json" --post-data '{"mode":1}' -q -O /dev/null http://192.168.0.57/control
echo -n "off"
;;
stat)
if `wget -t 2 -T 5 --connect-timeout=5 -w 2 --no-http-keep-alive --max-redirect=0 -q -O - "http://192.168.0.57/status" | grep -q :0`; then echo -n on; else echo -n off; fi
;;
I suggest testing the wget/curl command from a shell prompt. Once you get the switch to turn on and off and report status, use the commands in the CGI script. To test your CGI script, run: curl
http://127.0.0.1:8000/cgi-bin/my_cgi_script.sh to verify the python http server is working correctly.
Good luck.