ios zway authentication - help

Discussions about Z-Way software and Z-Wave technology in general
yzheng
Posts: 8
Joined: 09 Oct 2015 23:38

ios zway authentication - help

Post by yzheng » 09 Oct 2015 23:51

Hi

I am new to zway. Please forgive me if I am asking silly questions. I am doing an ios app to control zwave device. I have used Razberry and it works fine in the browser.

Now I am trying to do the same thing from an ios app, how should I handle authentication? I am using AFNetworking for HTTP POST operations. And the firmware version is 2.1.1 (it says it is latest)

Any help would be appreciated.

Yunan

aivs
Posts: 38
Joined: 04 Mar 2011 15:26

Re: ios zway authentication - help

Post by aivs » 14 Oct 2015 13:26

Hi, Now Z-Way supports Basic Authentication, so you no need to log in. With each request you should send login and password:

Code: Select all

    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    manager.requestSerializer.cachePolicy = NSURLRequestReloadIgnoringLocalAndRemoteCacheData;
    [manager.requestSerializer setAuthorizationHeaderFieldWithUsername:@"admin" password:@"admin"];
    [manager GET:@"http://192.168.0.62:8083/ZAutomation/api/v1/notifications" parameters:nil
              success:^(AFHTTPRequestOperation *operation, id DATA) {
                  NSLog(@"notifications: %@",DATA);
              } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                  NSLog(@"getNotifications Error : %@",error.description);
     }];

yzheng
Posts: 8
Joined: 09 Oct 2015 23:38

Re: ios zway authentication - help

Post by yzheng » 14 Oct 2015 13:41

Thanks aivs. I will give this codes a try.

yzheng
Posts: 8
Joined: 09 Oct 2015 23:38

Re: ios zway authentication - help

Post by yzheng » 14 Oct 2015 17:28

Hi aivs:

I have tried the codes. I am still not able to control the light. What firmware version do I need upgrade to? I got 2.1.1 at the moment. I am using Raspberry Pi 2.

Below is the error I got:

Code: Select all

2015-10-14 15:24:54.663 ZwayDemo[17053:13748395] getNotifications Error : Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: internal server error (500)" UserInfo={NSUnderlyingError=0x7f7fc96ac870 {Error Domain=com.alamofire.error.serialization.response Code=-1016 "Request failed: unacceptable content-type: text/plain" UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x7f7fc9700f60> { URL: http://192.168.0.12:8083/ZAutomation/api/v1/devices/ZWayVDev_zway_2-0-37/command/on } { status code: 500, headers {
    "Access-Control-Allow-Credentials" = true;
    "Access-Control-Allow-Origin" = "*";
    Connection = close;
    "Content-Length" = 67;
    "Transfer-Encoding" = Identity;
} }, NSErrorFailingURLKey=http://192.168.0.12:8083/ZAutomation/api/v1/devices/ZWayVDev_zway_2-0-37/command/on, com.alamofire.serialization.response.error.data=<556e6361 75676874 20547970 65457272 6f723a20 43616e6e 6f742072 65616420 70726f70 65727479 2027746f 4c6f7765 72436173 6527206f 6620756e 64656669 6e6564>,

aivs
Posts: 38
Joined: 04 Mar 2011 15:26

Re: ios zway authentication - help

Post by aivs » 14 Oct 2015 22:33

Try to add this:

Code: Select all

manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"];
And use a latest version v2.1.2-rc2

pofs
Posts: 688
Joined: 25 Mar 2011 19:03

Re: ios zway authentication - help

Post by pofs » 15 Oct 2015 17:30

aivs wrote:Try to add this:

Code: Select all

manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"];
Valid response should always be json, so there's no need to do that.

And if you look at error.data provided, it says "Uncaught TypeError: Cannot read property 'toLowerCase' of undefined", which suggests some JS error at Z-Way side. You can check log to see stack trace and determine the exact error location.

yzheng
Posts: 8
Joined: 09 Oct 2015 23:38

Re: ios zway authentication - help

Post by yzheng » 16 Oct 2015 17:23

aivs wrote:Try to add this:

Code: Select all

manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"];
And use a latest version v2.1.2-rc2

Hi aivs, I have upgraded to 2.1.2-rc2 and added the codes you suggested. Now I am getting the error below

Code: Select all

2015-10-16 15:23:12.520 ZwayDemo[23009:15679489] getNotifications Error : Error Domain=NSCocoaErrorDomain Code=3840 "JSON text did not start with array or object and option to allow fragments not set." UserInfo={NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set., NSUnderlyingError=0x7fe0b3614410 {Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: internal server error (500)" UserInfo={com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x7fe0b35a1870> { URL: http://192.168.0.12:8083/ZAutomation/api/v1/devices/ZWayVDev_zway_2-0-37/command/on } { status code: 500, headers {
    "Access-Control-Allow-Credentials" = true;
    "Access-Control-Allow-Origin" = "*";
    Connection = close;
    "Content-Length" = 67;
    "Transfer-Encoding" = Identity;
} }, NSErrorFailingURLKey=http://192.168.0.12:8083/ZAutomation/api/v1/devices/ZWayVDev_zway_2-0-37/command/on, com.alamofire.serialization.response.error.data=<556e6361 75676874 20547970 65457272 6f723a20 43616e6e 6f742072 65616420 70726f70 65727479 2027746f 4c6f7765 72436173 6527206f 6620756e 64656669 6e6564>, NSLocalizedDescription=Request failed: internal server error (500)}}}

yzheng
Posts: 8
Joined: 09 Oct 2015 23:38

Re: ios zway authentication - help

Post by yzheng » 16 Oct 2015 17:24

pofs wrote:
aivs wrote:Try to add this:

Code: Select all

manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"];
Valid response should always be json, so there's no need to do that.

And if you look at error.data provided, it says "Uncaught TypeError: Cannot read property 'toLowerCase' of undefined", which suggests some JS error at Z-Way side. You can check log to see stack trace and determine the exact error location.

Hi pofs, where can I find the log files?

pofs
Posts: 688
Joined: 25 Mar 2011 19:03

Re: ios zway authentication - help

Post by pofs » 16 Oct 2015 18:01

/var/log/z-way-server.log

yzheng
Posts: 8
Joined: 09 Oct 2015 23:38

Re: ios zway authentication - help

Post by yzheng » 16 Oct 2015 22:04

pofs wrote:/var/log/z-way-server.log
I have checked the log file, this is the stack trace information. What should/can I do?

Code: Select all

Callback execution error: TypeError: Cannot read property 'toLowerCase' of undefined
    at ZAutomationAPIWebRequest.ZAutomationWebRequest.handleRequest (automation/WebserverRequestRouter.js:246:71)
    at automation/WebserverRequestRouter.js:32:35
    at WebServer.document_root (automation/Webserver.js:27:11)

Post Reply