B4A Library ABFlicB4A library for Flic buttons

cute-as-a-button-1.png

You probably have seen these nifty little IoT Flic buttons around. They are a fun and relative cheap BLE button that allows you to do something when the button is clicked, doubleclicked or hold.

Demo video:

How to use:
1. Install the Flic app from the Google Play.
2. On their developer page, create a new app: you get a key and a secret.
3. Copy the ABFlicB4A library jar and xml to your library folder and select it in B4A

Example usage code:
B4X:
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   Private flic As ABFlic
   Private Button2 As Button
   Private Button3 As Button
   Private Button4 As Button
   Private Label1 As Label
   Private Button1 As Button
   
   Private MyFlicID As String
   
   Private FlicResults As List   
End Sub

Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
   Log("created")
   Activity.LoadLayout("1")     
   FlicResults.Initialize
   FlicResults.Add("RESULTACTION_HOLD")
   FlicResults.Add("RESULTACTION_SINGLECLICK")
   FlicResults.Add("RESULTACTION_DOUBLECLICK")
End Sub

Sub Activity_Resume
   ' your key and secret
   flic.Initialize("Flic", "d60d36a0-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "db5c2b3d-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "ABFlicTest")
End Sub

Sub Button1_Click
   flic.ForgetButton(MyFlicID)
End Sub

Sub Button2_Click
   flic.GrabButton
End Sub

Sub Button3_Click
   flic.StartListening
End Sub

Sub Button4_Click
   flic.StopListening
End Sub

Sub flic_Added(buttonID As String, Name As String)
   MyFlicID = buttonID
   Log("Added: " & buttonID)
   Label1.Text = "Added: " & buttonID & CRLF & Label1.Text
End Sub

Sub flic_Clicked(buttonID As String, wasQueued As Boolean, timeDiff As Int)
   MyFlicID = buttonID
   Log("Clicked: " & buttonID)
   Label1.Text = "Clicked: " & buttonID & CRLF & Label1.Text
End Sub

Sub flic_DoubleClicked(buttonID As String, wasQueued As Boolean, timeDiff As Int)
   MyFlicID = buttonID
   Log("DoubleClicked: " & buttonID)
   Label1.Text = "DoubleClicked: " & buttonID & CRLF & Label1.Text
End Sub

Sub flic_Holded(buttonID As String, wasQueued As Boolean, timeDiff As Int)
   MyFlicID = buttonID
   Log("Holded: " & buttonID)
   Label1.Text = "Holded: " & buttonID & CRLF & Label1.Text
End Sub

Sub flic_Removed(buttonID As String)
   MyFlicID = ""
   Log("Removed: " & buttonID)
   Label1.Text = "Removed: " & buttonID & CRLF & Label1.Text
End Sub

Sub flic_Error(err As Int)
   Log("Error: " & err)
   Label1.Text = "Error: " & err & CRLF & Label1.Text
End Sub

I'm currently working on a Desktop/Raspberry Pi version of this library, which I will share in the B4J forum later.
 

Attachments

  • ABFlicB4A1.00.zip
    48.8 KB · Views: 337

bluedude

Well-Known Member
Licensed User
Longtime User
Pretty cool these buttons but you always need a device nearby and that is the weak point.
 

sorex

Expert
Licensed User
Longtime User
probably 50m in open air. with brick walls or concrete ceilings it's probably a lot less.

nifty things tho, didn't see it before.
 

tigrot

Well-Known Member
Licensed User
Longtime User
I know those devices from the first times(when they were a pjt), but apart from being a gadget I don't find any utility for them. I have 4 of them but after first tests they are still in their box. Did anybody find a use for them, apart from draining batteries?
 

alwaysbusy

Expert
Licensed User
Longtime User
@tigrot I've seen your posts. Did you ever get it working without the Flic app?

I have one in use currently: to regulate the brightness of my lamps. One click is full brightness, doubleclick is dim (movie setting), hold is turn the light off. I'm using it together with philips HUE bridge/lamp. It is sticked under my coffee table, because picking up the iPad to regulate the lights is just ridiculous. After all we don't live in the dark ages any more, no? ;)

Flow: press button -> Flic app on iPad -> HUE Bridge -> Lamps

Uses about 2 extra cables to make the lamp 'wireless'...:rolleyes:

But I'm sure I'll find some other weird uses for it :), I was thinking of using them as a cheap location beacons around the house.
 

alwaysbusy

Expert
Licensed User
Longtime User
Just a photo to show how my living room is currently looking. You have to imagine the black box on the left houses 3 more linux boxes, a couple of Raspberry Pies, routers, hubs, TV boxes, NAS and I don't how many miles of cables. My cleaning lady Madeleine (which is a Roomba), refuses to clean this room...

cables.jpg
 

tigrot

Well-Known Member
Licensed User
Longtime User
Hi AlwaysBusy,
It's a normal BLE device, you can use directly from android. The support APP from the flic company is to mantain a link between the android/IOS device. The Flic sends a packet on pressure and the support App generates the appropriate events.
I generally build my hardware to support my apps, since I love integrating systems(I have been doing it since 1972).
There are so many ready to use dimmers and BLE device that it's not worth to further study about it, but if it's an hobby, it's OK...
Ciao
Mauro
 

Cableguy

Expert
Licensed User
Longtime User
Indeed. Luckely I have a device about every 5 meters in my home...;) Haven't tried the distance they can cover. They claim about 50m, but I seriously doubt that.

The ESP8266-12F is not the smallest form for the esp8266 based boards, and is still quite small and can cover more than 300mt (max at 900m in open space without dropping packages) so why not 50m for that thing?
 

tigrot

Well-Known Member
Licensed User
Longtime User
There are also simillar products related to BLE or previous version of bluetooth, with the same format. They have also digital I/O to help to sense switches with no external processor added. I tested many with interesting results.
 

dibesw

Active Member
Licensed User
Longtime User
If you need 1000 buttons... (or more).
I have 4 and that's enough!

Ciao have a good evening
Mauro
Ciao Mauro, vorrei capire meglio come utilizzare questi flic buttons.
Posso chiederti qualche informazione?

Grazie
 

andyr00d

Member
Licensed User
Longtime User
Looking forward to the B4J version! this could certainly be useful running from a NAS or Pi etc
 
Top