HOME Forums Gateways Raspberry Pi REST HowTo?

Viewing 15 posts - 1 through 15 (of 20 total)
  • Author
    Posts
  • Anonymous
    Inactive
    Post count: 6

    The examples given in the wiki aren’t as easy to follow at it seems. Can you provide any real examples I can use?

    curl http://192.168.*.*:50333/devices -XGET

    – returns “Not authenticated”. I’ve tried authentication with Postman (Chrome App) as well and not succeeding. Is the default username admin? I’d like to learn more and use the REST capabilities.

    Thanks!

    Anonymous
    Inactive
    Post count: 6

    Not that I’d consider this progress but looking at config.ini I discovered the default username appears to be RasperrryPi. PwdFlag=False though so when I try to authenticate with RESTClient in Firefox I still get “not authenticated”. Under the [client] section of config.ini I tried to use that password along with RaspberryPi to no avail.

    No idea how to authenticate using ‘curl’ or if I can disable authentication. Anybody got some insight?!

    Anonymous
    Inactive
    Post count: 259

    Hey,

    REST is in development mode, and in this mode the System API’s are not yet fully functioning. As of now you can only access the REST API with a Computer (or other device) in the same network as the Gateway.

    So to help you move forward, please ignore the System API’s. I’m a Postman fan myself… so here’s a collection you can use to test/develop the REST API.
    https://www.getpostman.com/collections/a7e361d5a8f7f0d82410

    Please let us know if you find any issues or have any kind of feedback regarding the API. Will appreciate it very much.

    Thanks,

    Anonymous
    Inactive
    Post count: 22

    At the risk of resurrecting a dead thread…

    I am attempting to use the REST API on my gateway. The documentation on the authenticate method seems light, but I think I understand that in order to authenticate, you would send a POST message with the hash of the password.

    this seems like the appropriate syntax to me, looking at examples of other POST examples in the API docs:

    curl http://MyServer:MySocket/system/authenticate -d”Password=MyHashValue” -XPOST

    this command connects but yields a Not Authenticated message

    { "Password" : "d13a9c616a3f2772e2aa406d7ecc9470dd2dc605", "action" : "post", "args" : null, "error" : "Not authenticated", "id" : 0, "objs" : [ "system", "authenticate" ], "session_id" : "" }

    The log file shows that the session is initiated and the the parameter is getting parsed

    ZBPServer[23867]: Incoming connection.
    ZBPServer[23867]: http_parser:: POST /system/authenticate/
    ZBPServer[23867]: http:: param: Password value:d13a9c616a3f2772e2aa406d7ecc9470dd2dc605

    but then the session ends
    ZBPServer[23867]: Scheduler:: socket removed

    So, how to debug this further..
    is Password the correct parameter name? the exact same results occur if I change the parameter name to any random string

    the docs say that the password should be the SHA1 hash value. I tried using shasum to create the hash, as well as using the actual hash value in the config.ini file, and just for grins using clear text.

    are other parameters expected in addition to password? Not sure why the return says Args:null..

    thanks for any pointers. this seems like a simple thing to start with.
    Jay

    Anonymous
    Inactive
    Post count: 259

    Hi Jay,

    The System API’s are not yet completely activated. As of now you can only consume the REST API within the LAN.

    So to help you move forward, please skip the System API calls, you will be able to consume other API without authentication.

    We have a collection of API’s to help get started and that’s what I would recommend, you can use the Postman REST Client to start testing, here’s the link of collections:
    https://www.getpostman.com/collections/a7e361d5a8f7f0d82410

    Please let us know if you find any issues or have any kind of feedback regarding the API. Will appreciate it very much.

    Thanks,

    Anonymous
    Inactive
    Post count: 22

    Thanks,

    so continuing along, I expect the next simplest command would be:

    curl http://MyGateway:MyPort/devices -XGET

    which returns:

    { "action" : "get", "args" : null, "error" : "Not authenticated", "id" : 0, "objs" : [ "devices" ], "session_id" : "" }

    and the log also shows this as connecting and parsing more or less as I would expect:

    ZBPServer[1156]: Incoming connection.
    ZBPServer[1156]: Scheduler:: socket added
    ZBPServer[1156]: http_parser:: GET /devices
    but then…
    ZBPServer[1156]: Scheduler:: socket removed

    I tried this both from a LAN device on the same network and on the local host – same result

    thanks
    Jay

    Anonymous
    Inactive
    Post count: 22

    I followed your suggestion and installed PostMan. I installed your collection as well. thanks for that.

    I setup my globals with my IP and PORT, then executed the devices sample from your collection.

    the result is shown in the attached screenshot but the important part is:

    “error”: “Not authenticated”,

    both the MacBook running PostMan and the Pi are on the same LAN (192.168.1.x)

    additional troubleshooting / debugging suggestions appreciated.

    thanks

    Anonymous
    Inactive
    Post count: 259

    Hi Jay,

    For REST API use port 50334
    Port 50333 is for the XML API which uses Authentication.

    Try
    GET http://GatewayIP:50334/devices

    Anonymous
    Inactive
    Post count: 22

    thanks
    using port 50334 works fine 🙂

    jay

    Anonymous
    Inactive
    Post count: 22

    I expected the Get Devices Capabilities command to provide the methods available for each device. it does not. there’s no significant difference between the result of Get Devices vs Get Devices Capabilities except that the later does not return the MAC.

    is there a list somewhere of the methods for each device type? or some other function to call that responds with the available methods per device?

    thanks

    Jay

    Anonymous
    Inactive
    Post count: 259

    It looks like the components did not get discovered. This could happen if the zbpserver plugins are not installed. Can you please check if the plugins are installed:

    ls /usr/lib/zbp/plugins

    If they are not installed, then install them using:

    sudo apt-get install zbpserver*

    Take a look at this post:
    http://forum.smartenit.com/viewtopic.php?f=48&t=1020

    If the plugins are installed, then could you please email me the logs: /var/log/zbp

    Thanks

    Anonymous
    Inactive
    Post count: 22

    true – the plugins were not installed.

    I resolved that, thank you. restarted the server.
    I then attempted to rediscover the capabilities of a few devices, but still the results are the same.

    snippet from log file is below

    May 9 12:35:07 raspberrypi ZBPServer[20849]: http_parser:: POST /devices/15237/capabilities/discover
    May 9 12:35:08 raspberrypi ZBPServer[20849]: NodeMgmt::post method called for device 15237
    May 9 12:35:08 raspberrypi ZBPServer[20849]: NodeMgmt:: Rediscovering device capabilities: id:3b85
    May 9 12:35:08 raspberrypi ZBPServer[20849]: Scheduler:: socket removed
    May 9 12:35:10 raspberrypi ZBPServer[20849]: Scheduler:: socket removed
    May 9 12:35:28 raspberrypi ZBPServer[20849]: Incoming connection.
    May 9 12:35:28 raspberrypi ZBPServer[20849]: Scheduler:: socket added
    May 9 12:35:28 raspberrypi ZBPServer[20849]: http_parser:: GET /devices/capabilities/
    May 9 12:35:28 raspberrypi ZBPServer[20849]: Scheduler:: socket removed
    May 9 12:35:52 raspberrypi ZBPServer[20849]: Incoming connection.
    May 9 12:35:52 raspberrypi ZBPServer[20849]: Scheduler:: socket added
    May 9 12:35:52 raspberrypi ZBPServer[20849]: http_parser:: POST /devices/15851/capabilities/discover
    May 9 12:35:52 raspberrypi ZBPServer[20849]: NodeMgmt::post method called for device 15851
    May 9 12:35:52 raspberrypi ZBPServer[20849]: NodeMgmt:: Rediscovering device capabilities: id:3deb
    May 9 12:35:52 raspberrypi ZBPServer[20849]: Scheduler:: socket removed
    May 9 12:36:00 raspberrypi ZBPServer[20849]: Incoming connection.
    May 9 12:36:00 raspberrypi ZBPServer[20849]: Scheduler:: socket added
    May 9 12:36:00 raspberrypi ZBPServer[20849]: http_parser:: GET /devices/capabilities/
    May 9 12:36:00 raspberrypi ZBPServer[20849]: Scheduler:: socket removed
    May 9 12:36:25 raspberrypi ZBPServer[20849]: Incoming connection.
    May 9 12:36:25 raspberrypi ZBPServer[20849]: Scheduler:: socket added
    May 9 12:36:25 raspberrypi ZBPServer[20849]: http_parser:: GET /devices/15851/capabilities
    May 9 12:36:25 raspberrypi ZBPServer[20849]: Scheduler:: socket removed

    Anonymous
    Inactive
    Post count: 259

    Glad to hear that.

    Feel free to ask any questions you have. Are you working on an App?

    Anonymous
    Inactive
    Post count: 22

    I still don’t have any device capabilities

    [attachment=0:37zu3y9m]Screen Shot 2016-05-09 at 12.04.58 PM.png[/attachment:37zu3y9m]

    Anonymous
    Inactive
    Post count: 22

    i find these lines at the beginning of the log file when I restart the server. does this provide anything useful?

    May 9 12:31:11 raspberrypi ZBPServer[20849]: LoadPostProcessingLst:: Loading Post Processing list.
    May 9 12:31:11 raspberrypi ZBPServer[20849]: LoadPostProcessingLst:: File not found!
    May 9 12:31:11 raspberrypi ZBPServer[20849]: LoadHistoryRecordsLst:: Loading Post Processing list.
    May 9 12:31:11 raspberrypi ZBPServer[20849]: LoadHistoryRecordsLst:: File not found!
    May 9 12:31:11 raspberrypi ZBPServer[20849]: LoadModelReference:: File not found!
    May 9 12:31:11 raspberrypi ZBPServer[20849]: LoadPluginMappingReference:: File not found!

Viewing 15 posts - 1 through 15 (of 20 total)
  • You must be logged in to reply to this topic.