Page 1 of 1
Http Request
Posted: 28 Jul 2016 15:06
by kamlipin
Hello

Sorry for my English. Its not very well
Can I start from the beginning.
My goal is to visualize (port 80 ), KNX and Z-Wave .
I managed to already realize KNX , but I have a problem with the bus Z-Wave .
As you know Z-Wave comes on port 8,083th If I am trying to perform query HttpRequest on my visualization , or from port 80 to port 8083 , something like this :
http://192.168.0.103:8083/ZWaveAPI/Run/ ... 7].Set(255 )
.
It gives me an error Allow Access Control Origin and authentication error and so on.
Do you have an idea how to help me.
This is very important because this is my thesis
Re: Http Request
Posted: 28 Jul 2016 19:42
by pz1
You need to authenticate. See this
FAQ paragraph
How to execute API commands via HTTP API?
Re: Http Request
Posted: 29 Jul 2016 01:17
by kamlipin
pi@raspberrypi:~ $ curl -v -u admin:admin 192.168.0.103:8083/ZAutomation/ap i/v1/devices/ZWayVDev_zway_6-0-37/command/on
* Hostname was NOT found in DNS cache
* Trying 192.168.0.103...
* Connected to 192.168.0.103 (192.168.0.103) port 8083 (#0)
* Server auth using Basic with user 'admin'
> GET /ZAutomation/api/v1/devices/ZWayVDev_zway_6-0-37/command/on HTTP/1.1
> Authorization: Basic YWRtaW46a2FtaWxvczIwNw==
> User-Agent: curl/7.38.0
> Host: 192.168.0.103:8083
> Accept: */*
>
< HTTP/1.1 404 Not Found
* Server Mongoose/6.4 is not blacklisted
< Server: Mongoose/6.4
< Content-Type: application/json; charset=utf-8
< X-API-VERSION: 2.0.1
< Date: Thu, 28 Jul 2016 22:12:21 GMT
< Access-Control-Expose-Headers: Accept-Ranges, Content-Encoding, Content-Length , Content-Range, Content-Type, ETag, X-API-VERSION, Date, Cache-Control, If-None -Match, Content-Language, Accept-Language, ZWAYSession
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
< Connection: close
< Content-Length: 102
<
* Closing connection 0
{"data":null,"code":404,"message":"404 Not Found","error":"Device ZWayVDev_zway_ 6-0-37 doesn't exist"}
Hmm. Something i do like wrong ;(
Maybe someone want to help ??
Re: Http Request
Posted: 29 Jul 2016 15:49
by the wife
The
curl example
pz1 directed you to was just to show you how to pass your 'username' and 'password' to the zway server.
ZWayVDev_zway_6-0-37 is just a sample virtual device id.
It looks like the authentication has worked, but
ZWayVDev_zway_6-0-37 is not a device in your network which is why you are seeing an error.
From your original post
http://192.168.0.103:8083/ZWaveAPI/Run/ ... ].Set(255)
would suggest that
ZWayVDev_zway_3-0-37 is a valid device in your case?
Try:
curl -v -u admin:admin 192.168.0.103:8083/ZAutomation/ap i/v1/devices/ZWayVDev_zway_3-0-37/command/on
If that does not work, then:
curl -v -u admin:admin 192.168.0.103:8083/ZAutomation/ap i/v1/devices
would give you all the device ids so that you could try the original request again with one of your own device ids. Remember though, that this was just an example command to show you how to authenticate. I am not very familiar with
curl but can see that two examples were given:
1.
- Sends a login request with the username & password in the body.
Extracts the cookie and places it in 'cookie.txt'.
Sends a second request to switch on device ZWayVDev_zway_6-0-37 passing in the stored cookie.
2.
- Sends the same request to switch on device ZWayVDev_zway_6-0-37 but provides the username & password in the request itself
For my project I have been using the first model - ie login, obtain a cookie and use that in future requests.
I do this in Java for an Android app. However, to quickly test my requests I use a Windows PC. From the PC I either use Python or a RESTClient plugin for the Firefox browser. Both are free. To trace the requests and responses I use a Windows tool called Fiddler (also free). If these are available to you, they will give a good insight into the api and what is required.
I hope that helps.
Re: Http Request
Posted: 01 Aug 2016 22:03
by kamlipin
Ok. Thanks U for reply.
But i have one question more.
How can I do request login if i have in FAQ something like this:
curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X POST -d '{"form": true, "login": "admin", "password": "admin", "keepme": false, "default_ui": 1}' 192.168.0.62:8083/ZAutomation/api/v1/login -c cookie.txt
My code now is:
Code: Select all
$('#btn_click').click(function() {
$.ajax
({
type: "GET",
url: "http://127.0.0.1:8083/ZWaveAPI/Run/devices[3].instances[0].commandClasses[37].Set(255)",
dataType: 'json',
async: false,
beforeSend: function (xhr) {
xhr.setRequestHeader ("Authorization", "Basic " + btoa('admin' + ":" + 'kamilos207'));
},
data: '',
success: function (){
alert('Thanks for your comment!');
}
});
});
Ok. I add anonymous client, and now it work. I hope so.
But I have another problem. What Can I do to test or check status of device?