Flic2 Hub & http Request



  • I’ve just taken delivery of my new flic2 and Hub LR. I’m using it for mostly http requests. I have this working for some devices but one requiring authentication won’t work. I’ve read through the guidance on this thread:
    http request

    However whatever I do can’t get the request to work but I can’t see what is happening when I send the request as there is no feedback within the app.

    Anyone else solved this and got it working?



  • OK as Flic support failed to respond to my emails and haven't been much help generally I ended up turning to Global Cache support and they solved the issue for me. I thought it might be helpful to someone else if I posted the solution. This may also work for other http requests using JSON.
    So if you have the IR code for a device and function then this can easily be added as an http request within the Flic app. First you need the code to be in JSON format. The best way to do this is with iLearn which is available for Windows and Mac. The Mac version isn't an official application from Global Cache but a third party. However it works well as I am a Mac only user.
    In my case the JSON code for the IR commands was:
    {"frequency":38095,"irCode":"342,171,22,21,21,22,21,21,22,21,22,21,21,21,22,21,22,21,21,21,22,21,22,21,22,21,21,64,21,21,22,21,22,21,21,21,22,63,22,63,22,21,22,63,22,21,21,21,22,21,22,63,22,21,22,21,21,64,21,21,22,63,22,63,22,63,22,1829,342,85,21,3661,342,85,22,3660,342,85,22,3660,342,85,22,3809","preamble":"","repeat":1}
    So once you have this then go into the Flic app, select which button function you want to assign and select HTTP REQUEST. In the URL field, enter the IP address of your unit followed by the send IR api:
    http://[ip address of your unit]/api/v1/irports/[port number]/sendir
    You need to make sure you enter the correct ir port number. If you have the tri IR lead connected to a Global Cache Flex then the port numbers are 1,2 & 3. The IR emitters should also be labelled. So if the device you're looking to control has emitter 1 connected to it, then enter:
    http://[ip address of your unit]/api/v1/irports/1/sendir
    Then ensure you select POST as the method for sending the packet.
    In Content Type enter:
    application/json
    Under Body paste in the IR code in JSON format. It must be enclosed within {}. iLearn will do this automatically for you so it's just a matter of copying and pasting.
    Click Done to ensure the entry is saved and it should now work.

    I hope this helps someone else and I hope that Flic Support takes note of their poor levels of response and technical support. I'm a Kickstarter backer and think the new hub and buttons are excellent. I couldn't be happier with the hardware but please improve your technical support or at the very least have more documentation for http requests through Flic. For me it's pretty much all I'm using the hub for as most of my devices aren't natively listed and I therefore need to send http api commands for what I want to control.



  • @Emil Have spent several hours trying with curl but no success. The code works as I’m able to send it through the test facility from Global Cache. However I can’t get the formatting correct for the http api request.



  • @Emil Thanks for the reply. I’ve used an application called POST but I haven’t been able to get it to work which is why I was hoping for some guidance on the formatting.
    If anyone can help with the correct format to enter this it would be appreciated.


  • FlicTeam

    @andy I suggest you use "curl" or something to fiddle around with the request to format it correctly, to make sure it works. Once you got it working, you should only need to copy the headers and the body to the Internet Request form in the flic app.



  • OK having successfully got one http request working I now need to integrate an IR command sent to a Global Cache Flex IP2IR unit. I’ve successfully captured the correct IR code and having tested this code, it works. However I cannot work out the format within the Flic Internet Request to successfully send the command. Global Cache have a very useful API document which shows the format the http request needs sent. It must be a POST request and the format is as follows:

    IR COMMAND TRANSMISSION
    When sending IR commands to a Flex unit via HTTP, an HTTP POST is used to send the JSON packet as shown below.
    HTTP/1.1 POST
    <Base URL>/irports/<IR port number>/sendir
    Header Values:
    "crossDomain" must be true if issuing this command from the web page of a different Flex unit
    {
    “frequency”:“<FrequencyString>”,
    “preamble”:“<PreamblePulseTrain>”,
    “irCode”:“<IRCodePulseTrain>”,
    “repeat”:“<RepeatCount>”
    }

    Where:
    <FrequencyString> is the frequency of the command in hertz (Hz)
    <PreamblePulseTrain> is a comma separated list of numeric values signifying the first portion of the IR command that is only fired once. This portion is not repeated when using a repeat count.
    <IRCodePulseTrain> is a comma separated list of numeric values signifying the full IR command when not using a preamble. This portion of the code is repeated when using a repeat count.
    <RepeatCount> is the number of times that the
    <IRCodePulseTrain> is to be repeated after sending the preamble of the command in the case that it is used.

    Can anyone help with how to enter this within the Flic app under Internet Request? The IR code I need to send is:

    sendir,1:1,1,40506,1,1,343,182,22,22,22,22,22,22,21,22,22,22,22,22,21,22,22,22,22,22,21,22,22,22,22,22,22,67,22,22,21,22,22,22,22,67,22,67,22,22,21,68,21,68,21,22,22,22,22,22,21,22,22,22,22,67,22,22,22,22,21,68,21,68,21,68,21,1945,342,90,22,3892,342,90,22,3893,342,90,21,3893,342,90,21,3893,342,90,22,3892,342,90,22,3893,342,90,21,3893,342,90,22,3892,342,90,22,3892,342,90,22,3893,342,90,21,3893,342,90,22,3892,342,90,22,3893,342,89,22,3893,342,90,21,3893,342,90,22,3892,342,90,22,3893,342,90,21,3893,342,90,21,3893,342,90,22,3892,342,90,22,3893,342,90,21,3893,342,90,22,3892,342,90,22,3892,342,90,22,3893,342,90,21,3893,342,90,22,3892,342,90,22,3893,342,89,22,3893,342,90,21,3893,342,90,22,3892,342,90,22,3893,342,90,21,3893,342,90,21,4050 sendir,1:1,1,40506,1,1,343,182,22,22,22,22,22,22,21,22,22,22,22,22,21,22,22,22,22,22,21,22,22,22,22,22,22,67,22,22,21,22,22,22,22,67,22,67,22,22,21,68,21,68,21,22,22,22,22,22,21,22,22,22,22,67,22,22,22,22,21,68,21,68,21,68,21,1945,342,90,22,3892,342,90,22,3893,342,90,21,3893,342,90,21,3893,342,90,22,3892,342,90,22,3893,342,90,21,3893,342,90,22,3892,342,90,22,3892,342,90,22,3893,342,90,21,3893,342,90,22,3892,342,90,22,3893,342,89,22,3893,342,90,21,3893,342,90,22,3892,342,90,22,3893,342,90,21,3893,342,90,21,3893,342,90,22,3892,342,90,22,3893,342,90,21,3893,342,90,22,3892,342,90,22,3892,342,90,22,3893,342,90,21,3893,342,90,22,3892,342,90,22,3893,342,89,22,3893,342,90,21,3893,342,90,22,3892,342,90,22,3893,342,90,21,3893,342,90,21,4050



  • @Emil OK after a lot of experimenting I managed to get it working. Think it was finger trouble on my part. It is Basic authentication and it’s now working well.
    Thanks for the reply.



  • @Emil I’m not 100% sure but think it’s actually Digest Authentication.
    If I enter the following in a browser window the command works perfectly:
    http://username:password@10.33.22.126:85/cgi-bin/split.cgi?action=enableTour&channel=1&enable=true

    I’ve converted the actual username:password to base64 but the command is not being sent correctly by the hub.


  • FlicTeam

    Hi. Are you trying to use "Basic Authentication"? In that case make sure you Base64-encode your credentials correctly.

    In any case, you can use some service like requestbin.net to see what request the hub sends.


Log in to reply