Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Calling animations through REST
#11
(11-26-2015, 07:59 AM)Adam Wrote: Oops... yeah. Important bit. http://myhost:8080/api
That last /api is where all the calls go through.

Great Scott! It works! Thanks!
#12
(11-25-2015, 05:38 PM)Adam Wrote: @Buhlinky - Thanks! Glad you like it.
So... PixelWeb *does* have a REST interface. It's how the UI communicates with everything. It's just not... documented. I should probably do that Smile
The API is similar to what I mentioned before. For example this would run Bloom:

{"action":"startAnim","config":{"id":"Bloom","config":{"dir":true},"run":{"amt":1,"fps":30,"max_steps":0,"untilComplete":false,"max_cycles":1}}}

It's a JSON POST call and it returns JSON

I don't currently have a way of calling a preset by name. You always have to pass in config and run... basically specify ALL details.

If in the javascript console you run this: ___printAPIOutput=true
It will print all REST calls to the console so you can get a better idea of how things work.

I'll try to do some better documentation soon.

Hey Adam,

I tried executing the above command (including "/api" at end), but I get Error 500. This is my command:

Code:
curl -H "Content-Type: application/json" -X POST --data "{"action":"startAnim","config":{"id":"all_softwhite","config":{"color1":[255,255,140],"max_led":-1},"run":{"amt":1,"fps":30,"seconds":null,"max_steps":0,"untilComplete":false,"max_cycles":1}}}" "http://192.168.1.110:8080/api"

"all_softwhite" is indeed an animation that works fine from the web interface. This is the response that I obtain:

Code:
C:\Users\Tushar\Desktop>curl -H "Content-Type: application/json" -X POST --data "{"action":"startAnim","config":{"id":"all_softwhite","config":{"color1":[255,255,140],"max_led":-1},"run":{"amt":1,"fps":30,"seconds":null,"max_steps":0,"untilComplete":false,"max_cycles":1}}}" "http://192.168.1.110:8080/api"

   <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
   <html>
       <head>
           <title>Error: 500 Internal Server Error</title>
           <style type="text/css">
             html {background-color: #eee; font-family: sans;}
             body {background-color: #fff; border: 1px solid #ddd;
                   padding: 15px; margin: 15px;}
             pre {background-color: #eee; border: 1px solid #ddd; padding: 5px;}
           </style>
       </head>
       <body>
           <h1>Error: 500 Internal Server Error</h1>
           <p>Sorry, the requested URL <tt>'http://192.168.1.110:8080/api'</tt>
              caused an error:</p>
           <pre>Internal Server Error</pre>
       </body>
   </html>

C:\Users\Tushar\Desktop>

I need this for controlling my LEDs using external equipment that is connected to my wifi.

Thanks
#13
Two questions:

a) is the data you are sending exactly what gets sent by PixelWeb itself? Set ___printAPIOutput=true in the JS console to see what it sends.
b) If it throws this error to curl, it should show an error in the console. What does that say?
#14
(05-29-2016, 08:23 AM)Adam Wrote: Two questions:

a) is the data you are sending exactly what gets sent by PixelWeb itself? Set ___printAPIOutput=true in the JS console to see what it sends.
b) If it throws this error to curl, it should show an error in the console. What does that say?

Hey Adam,

a) Yes, I tried that and the data that I am sending is copied from console.
b) I do not get any errors in the console when using PixelWeb.

Thanks

Regards

T
#15
Ahh.. solved it. It's your quotes. you put double quotes around the data and the data contains double quotes. Use single quotes (', not ") to wrap the data portion. I also wrapped the URL in single instead of double for good measure and then it worked fine.
#16
(05-29-2016, 10:56 PM)Adam Wrote: Ahh.. solved it. It's your quotes. you put double quotes around the data and the data contains double quotes. Use single quotes (', not ") to wrap the data portion. I also wrapped the URL in single instead of double for good measure and then it worked fine.

Just tried that, but cURL for windows has issues with single quotes (and this unfortunately needs to be done on windows).

But this worked:
Code:
curl -d @C:\Users\Tushar\Desktop\all.json -H "Content-Type: application/json" http://192.168.1.110:8080/api

and all.json:
Code:
{
    "action":"startAnim",
    "config":{
        "id":"all_softwhite",
        "config":{
            "color1":[255,255,140],
            "max_led":-1
        },
        "run":{
            "amt":1,
            "fps":30,
            "seconds":null,
            "max_steps":0,
            "untilComplete":false,
            "max_cycles":1
        }
    }
}

Thanks for your hint about quotes. I was able to dig around and found the solution.

Regards

T
#17
Ah.... yeah windows cURL is kind of a pain. Didn't realize. I saw cURL and just assumed linux of some sort. Tested it on Fedora.
Glad you have a working solution now. What's actually calling all of this in the first place?
#18
Greetings -- I have been using BiblioPixel in a Raspberry-Pi-based lighting project that allow for a Lutron RadioRA2 system to control preset LED lighting scenes.

Recently I discovered PixelWeb and have been studying its operation and code in an effort to see how I can upgrade my project with many of its awesome features.
I really like the animation configuration features and the ability to save presets, and all in a rather nice web-GUI -- it's exactly the kind of stuff I'm looking for.
I was happy to run across this thread, as it shows I'm not the only one looking for to integrate this stuff into a larger (lighting) control system.

From what I've gleaned so far, there are some of features I'd like to see in PixelWeb that would make it perfect for my application.  

The biggest is the ability to start an animation by referencing the QS List / QS Item name (REST/API approach)  instead of the current JSON object with all the parameters.

This would allow a novice operator to configure, test, and save their different scenes and my Lutron RadioRA2 integration app to launch them based just a simple naming convention.

At this point, it's not clear to me how to add such a features.   I've been studying the code for a about a week, but much of different technologies are new to me so it's a slow process.
I figure by talking about what I'm looking for, there might be some help or pointers in this effort.  In any case, I'll keep plugging away at it because I like learning new stuff.

Any and all help is appreciated --  Cheers!
#19
 
ToddW - Thanks for your interest!
So, that's definitely the direction I've always wanted to move with PixelWeb... especially the ability to call out an animation by name.
There's a couple reasons I haven't yet...
1) I'm not sure all that many people actually USE PixelWeb. Honestly I only say this because there's actually a decently annoying bug in the current version that I cannot figure out so far and no one has reported it Tongue I would have if I was a user that found it. 
2) You're not the only one that finds the code a little confusing Wink Me too... here's the thing. That was my first web app, ever. So, the code isn't the greatest, and at this point I'm seriously considering a rewrite as opposed to adding new features on the current code base. That may sound drastic, by there's just too many problems I have with the currently chosen technologies  that have made me feel like the best option would be to make better choices Wink
If I were to do a "call my animation name", it's entirely possible. Since the data that gets sent to the web client is in the server side config, it's there you would need to start. look in actions.py: getQS() and you can see were it loads a quick select and sends it over. You would then just have to iterrate over the animations in that to find the matching name, then call startAnim() (server-side) with the full config to load the animation.
#20
Cool - Thanks for the pointers.  I'll take a stab at this to see if I can't get something going here in the near-term.

I admit that I'm finding web-apps I bit of a challenge atm.  Which is why I wanted to leverage PixelWeb as much as possible.
I am learning a lot by reading your code (even if it isn't the best example -- according to you).  It would take me months to get to its current level (if ever).

Looking forward to some future version with "better choices".  
Would also be interesting in what you think those better choices are -- might influence the direction I go in learning more about developing Web-Apps.

-Cheers!


Forum Jump:


Users browsing this thread: 1 Guest(s)