lifx / lifx-sdk-android Goto Github PK
View Code? Open in Web Editor NEWLIFX Android SDK
Home Page: http://lifx.co/
License: MIT License
LIFX Android SDK
Home Page: http://lifx.co/
License: MIT License
Several SDK users have mentioned that the Available lights do not seem to be populated on the first app launch, leaving the app and returning allows the lights to be seen.
lightCollectionDidAddLight() may not be being triggered for some reason.
I'm trying to control some LIFX bulbs from a BroadCastReceiver.
Im trying to connect using:
LFXNetworkContext localNetworkContext = LFXClient.getSharedInstance(context.getApplicationContext()).getLocalNetworkContext();
localNetworkContext.addNetworkContextListener(this);
localNetworkContext.connect();
Then in the listener I Call
@Override
public void networkContextDidConnect(LFXNetworkContext networkContext) {
Log.d(LOG_TAG, "----!CONNECTED!-----");
if(networkContext.isConnected()){
Log.d(Constants.LOG_TAG, "----!Really CONNECTED?----");
}
networkContext.getAllLightsCollection().setPowerState(LFXPowerState.OFF);
networkContext.disconnect();
}
The message "connected" is printed to the log, "Really connected" however, is not. Also the lights do not turn off.
Similar code worked flawlessly inside an activity.
Any suggestions? Or should I just wait for the new lib?
There is a leak in the LFXSocketUPD class. As it is run in a thread, it opens a local DatagramSocket but that socket is never closed after the message is sent.
What happens then is that all the available system UDP sockets can potentially be opened locally. As they are not referenced, I suspect they are closed by the garbage collection.
I believe the .setReuseAddress(true) call was to reduce this kind of problem, however, the no-arg constructor bind the DatagramSocket to the magic port 0 which bind it to any available port so I believe the reuseAddress doesn't do anything here.
I don't know much about the lifx protocol, but another improvment could be to put the opening statement of the socket outside of the loop (according that multiple message can be sent on the same socket). Also, the datagram sending socket should either be closed at the end of the process, or keep the very first available port that was taken when opening the first socket (through getPort()), keep it in a class variable locally and reuse it so that reuseAddress works better. Also, when isClosed() returns false, another attempt to open a local UDP socket could be made.
With all those fixes, at best a single UDP socket would be created, at worst N where N is the number of messages, and the opened socket would all be closed at the end of the method (or socket itself could be kept in a local class variable).
Is Lifx on Android dead? This SDK is broken with new bulbs, and theres no sign of a update from anyone in a whole year now.
This is really bad customer service here :(
In my application, users are able to adjust hue+saturation separate of brightness. Since the LIFX SDK doesn't allow these to be sent separately, my current approach is to get and send the existing values for parameters I don't want to change
LFXLight mLight;
LFXHSBKColor.getColor(desiredHue, desiredSat, mLight.getColors().getBrightness(), 0);
However, sometimes getColors() returns null for no apparent reason, thus breaking this approach. Any suggestions?
Hi - is there a Unity plugin available? (Looks like your Android app is in Unity)
Hi,
I am a developer new to IoT. Can I ask a bit about the mechanism behind how a device can be discovered and connected to a mobile app. I know this can be done with your sdk, but I want to know the more general mechanism. I am aware that you are a member of Allseen Alliance, do you use the AllJoyn framework. Any help will be greatly appreciated.
Many thanks,
Leon
Process: com.kuxhausen.huemore, PID: 4440
java.lang.NullPointerException: Attempt to invoke virtual method 'lifx.java.android.entities.internal.LFXSiteID lifx.java.android.entities.internal.LFXBinaryPath.getSiteID()' on a null object reference
at lifx.java.android.entities.internal.LFXMessage.getMessageDataRepresentation(LFXMessage.java:487)
at lifx.java.android.network_context.internal.transport_manager.gateway_connection.LFXUDPGatewayConnection.sendNextMessageFromOutbox(LFXUDPGatewayConnection.java:174)
at lifx.java.android.network_context.internal.transport_manager.gateway_connection.LFXUDPGatewayConnection.access$000(LFXUDPGatewayConnection.java:32)
at lifx.java.android.network_context.internal.transport_manager.gateway_connection.LFXUDPGatewayConnection$3.run(LFXUDPGatewayConnection.java:72)
at android.os.Handler.handleCallback(Handler.java:738)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5070)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:836)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:631)
I'm still trying to get told when my light gets switched off and still getting nowhere, I'm either mad or this is a poor API, possibly both!
When you get a lightCollectionDidAddLight() call and then do addLightListener() on the given light there are a number of bugs/issues:
I've set a listener on context.getAllLightsCollection() and whilst it's getting called correctly the arg0 & arg1 elements are returning bad labels ("Unknown"), if I use the arg1 (LFXLight) and choose getLabel() it will always return "Unknown" as will the collection in arg0 when the listener is called.
However when I iterate the LFXLightCollection in arg0 I will find that previous lights that did gave label "Unknown" are now correct, and if I force a short delay and call context.getAllLightsCollection() again then all labels are now correct.
I've also got a listener on change label but that never gets called.
Surely lightCollectionDidAddLight should only be called once the label is known OR called again when the label is known.
Any chance of a fix? or is this just me?
Version 1.3 firmware seems to bring noticeable improvements in reliability/connectivity, and I plan on only testing my app against Version 1.3 and newer. Is there a way I can check the firmware version to notify users that are running older firmware?
So I've now got working lights, a fudged listener to pick up new lights in the collection with the correct labels.
Can anyone explain what should happen when I physically switch off a light??
My expectation what that it would timeout in the library and I would get a lightCollectionDidRemoveLight() callback in the same way we get a callback when one is added.
However I'm not getting any callback to lightCollectionDidRemoveLight(), the only way I can seem to make a light vanish is to switch it off, wait a couple of minutes and then restart my app and then its gone from mLIFXContext.getAllLightsCollection().
I can see logcat messages from the system warning of "Idle timeout occured on UDP connection ...... disconnecting.....Connection state did change called. Getting those message about every 20 seconds after a short time after switchoff.
But it seems whatever I do mLIFXContext.getAllLightsCollection() is still returning the switched off bulb, even 10 minutes after power off. What I do see is a networkContextDidDisconnect() if only one bulb was switched on. With two bulbs I see networkContextDidDisconnect() and networkContextDidConnect() if I switch off the gateway bulb but still no damn DidRemoveLight().
So at the moment I'm stuck with bulbs that get added but never removed.
I am assuming if I use ;
lfxLight.setColorOverDuration(newcolor,10000);
The color should crossfade from its current one to the new one over a 10 second period right?
Because it doesn't, if just changes straight away.
getLabel() result is garbled words after setLabel in chinese on Android.
Does adding a light to LFXTaggedLightCollection work ?
I seem to be having troubles.
I tried a few methods;
LFXTaggedLightCollection tlc = ConnectionPage.getLocalNetworkContext().getTaggedLightCollectionForTag("TestTag");
(The collection already exists and has one entry)
However, if I want to add "bulbToEdit" I try a few methods;
bulbToEdit.setTags(tags);
Results in;
06-02 00:11:31.338: I/System.out(25523): Error: Creating tag TestTag in site * with tagField 0100000000000000
I also tried;
ConnectionPage.getLocalNetworkContext().addLightToTaggedLightCollection(bulbToEdit, tlc);
But that also results in;
06-02 00:11:31.338: I/System.out(25523): Error: Creating tag TestTag in site * with tagField 0100000000000000
If I do
tlc.addLight(bulbToEdit);
Also gives the same error.
However, the last one (and only the last one) does seem too add the bulb to the Tagged collection. If I test the number of bulbs straight after its increased by 1.
However, this doesn't save. Restarting my app its back to 1 bulb in the list.
Any ideas?
The sdk's documentation of the LIFX HSBK colorspace
doesn't mention the reference whitepoint or absolute scale
The documentation should list the white point, max red, max green, and max red, and gamma curve in an absolute system such as CIE_1931, so that colors can be accurately converted to other colorspaces such as Wide RGB or accurately previewed on Android in sRGB
Explained in the title
java.lang.NullPointerException
at com.kuxhausen.huemore.net.lifx.LifxRegistrationDialog.updateCandidateList(LifxRegistrationDialog.java:192)
at com.kuxhausen.huemore.net.lifx.LifxRegistrationDialog.onLoadFinished(LifxRegistrationDialog.java:253)
at com.kuxhausen.huemore.net.lifx.LifxRegistrationDialog.onLoadFinished(LifxRegistrationDialog.java:38)
at android.support.v4.app.LoaderManagerImpl$LoaderInfo.callOnLoadFinished(LoaderManager.java:427)
at android.support.v4.app.LoaderManagerImpl$LoaderInfo.onLoadComplete(LoaderManager.java:395)
at android.support.v4.content.Loader.deliverResult(Loader.java:104)
at android.support.v4.content.CursorLoader.deliverResult(CursorLoader.java:73)
at android.support.v4.content.CursorLoader.deliverResult(CursorLoader.java:35)
at android.support.v4.content.AsyncTaskLoader.dispatchOnLoadComplete(AsyncTaskLoader.java:223)
at android.support.v4.content.AsyncTaskLoader$LoadTask.onPostExecute(AsyncTaskLoader.java:61)
at android.support.v4.content.ModernAsyncTask.finish(ModernAsyncTask.java:461)
at android.support.v4.content.ModernAsyncTask.access$500(ModernAsyncTask.java:47)
at android.support.v4.content.ModernAsyncTask$InternalHandler.handleMessage(ModernAsyncTask.java:474)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
Whats to stop the API working on Android <4?
I did some investigating myself, and the connection seems to stop at:
LFXLANTransportManager.gatewayDiscoveryControllerDidUpdateEntry( LFXGatewayDiscoveryController table, LFXGatewayDiscoveryTableEntry tableEntry, boolean entryIsNew)
Theres no actual error anywhere, its just no connection is made and it seems like gatewayConnections should have entries in it.
Looking for where those entries are put in, I find the problem seems to be here;
discoveryTable.transportManager.addMessageObserverObjectWithCallback( discoveryTable, new LFXMessageObserverCallback()
{
@Override
public void run( Object context, LFXMessage message)
{
Log.i("LFX Gateway Discovery", "LFXMessageObserverCallback run:"+ message.getType().name());
LFXGatewayDiscoveryController discoveryTable = (LFXGatewayDiscoveryController) context;
if( message.getType() != Type.LX_PROTOCOL_DEVICE_STATE_PAN_GATEWAY)
{
return;
}
discoveryTable.handleStatePANGatewayMessage( message);
}
});
The log I added shows the value of the message is never the correct type;
I/LFX Gateway Discovery(29241): LFXMessageObserverCallback run:LX_PROTOCOL_DEVICE_GET_PAN_GATEWAY
I/LFX Gateway Discovery(29241): LFXMessageObserverCallback run:LX_PROTOCOL_DEVICE_GET_PAN_GATEWAY
I/LFX Gateway Discovery(29241): LFXMessageObserverCallback run:LX_PROTOCOL_DEVICE_GET_PAN_GATEWAY
....
*Is this to do with the bulbs broadcast?
Something unique with the way the Android OS handles connections?
Anything else?*
I am curious as I dont mind putting a bit of time in to get it working on older phones, seeing as my bulb app works on them already interface wise.
my full log from the moment I hit connection
05-11 20:39:05.516: I/System.out(29241): Debug: LFXLAN Initializer
05-11 20:39:05.526: I/LFX Gateway Discovery(29241): addMessageObserverObjectWithCallback
05-11 20:39:05.526: I/System.out(29241): DISCOVERYMODE: NORMAL
05-11 20:39:05.536: I/System.out(29241): Making Discovery Timer task. Period: 30000
05-11 20:39:05.536: I/System.out(29241): Debug: Setup UDP Connections
05-11 20:39:05.606: I/System.out(29241): Debug: ConnectionState: NOT_CONNECTED
05-11 20:39:05.606: I/System.out(29241): Verbose: Connecting UDP Socket 192.168.178.255:56700
05-11 20:39:05.626: I/System.out(29241): UDP SOCKET MONITOR IS ONLINE - ip: /192.168.178.255, port: 56700
05-11 20:39:05.626: I/System.out(29241): Debug: ConnectionState: NOT_CONNECTED
05-11 20:39:05.626: I/System.out(29241): Verbose: Connecting UDP Socket 192.168.178.255:56750
05-11 20:39:05.626: I/System.out(29241): Debug: Start Discovery
05-11 20:39:05.626: I/System.out(29241): DISCOVERYMODE: ACTIVELY_SEARCHING
05-11 20:39:05.626: I/System.out(29241): Making Discovery Timer task. Period: 1000
05-11 20:39:05.626: I/System.out(29241): UDP SOCKET MONITOR IS ONLINE - ip: /192.168.178.255, port: 56750
05-11 20:39:05.626: I/LFX Gateway Discovery(29241): LFXMessageObserverCallback run:LX_PROTOCOL_DEVICE_GET_PAN_GATEWAY
05-11 20:39:05.636: I/System.out(29241): Connection State did change called.
05-11 20:39:05.636: I/System.out(29241): Connection State did change called.
05-11 20:39:06.627: I/LFX Gateway Discovery(29241): LFXMessageObserverCallback run:LX_PROTOCOL_DEVICE_GET_PAN_GATEWAY
05-11 20:39:07.628: I/LFX Gateway Discovery(29241): LFXMessageObserverCallback run:LX_PROTOCOL_DEVICE_GET_PAN_GATEWAY
05-11 20:39:08.629: I/LFX Gateway Discovery(29241): LFXMessageObserverCallback run:LX_PROTOCOL_DEVICE_GET_PAN_GATEWAY
05-11 20:39:09.630: I/LFX Gateway Discovery(29241): LFXMessageObserverCallback run:LX_PROTOCOL_DEVICE_GET_PAN_GATEWAY
When this event fires my log statement returns false.
If I query the bulbs state straight away I cant - because it isnt connected.
I do seem to be able to control the bulbs at some unspecified seconds after, however.
So how do I know when I really can get data from the bulbs? (ie, their current hue)
localNetworkContext.addNetworkContextListener(new LFXNetworkContextListener() {
..
@Override
public void networkContextDidConnect(LFXNetworkContext networkContext) {
Log.i("connected","Connected:"+localNetworkContext.isConnected());
}
thanks.
The equals() method should take Object as its argument type, or else it won't override the parent's equals method. This bug causes LFXRoutingTable to add multiple copies of the same LFXSiteID to its member "mutableSiteIDs", since none of them seem "equal".
This is a simple and obvious fix, and I'm happy to do it for you if you tell me how to submit my code for your review.
.. any ETA?
E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: *, PID: 17927
java.lang.NullPointerException: Attempt to invoke virtual method 'lifx.java.android.entities.internal.LFXSiteID lifx.java.android.entities.internal.LFXBinaryPath.getSiteID()' on a null object reference
at lifx.java.android.entities.internal.LFXMessage.getMessageDataRepresentation(LFXMessage.java:487)
at lifx.java.android.network_context.internal.transport_manager.gateway_connection.LFXUDPGatewayConnection.sendNextMessageFromOutbox(LFXUDPGatewayConnection.java:174)
at lifx.java.android.network_context.internal.transport_manager.gateway_connection.LFXUDPGatewayConnection.access$000(LFXUDPGatewayConnection.java:32)
at lifx.java.android.network_context.internal.transport_manager.gateway_connection.LFXUDPGatewayConnection$3.run(LFXUDPGatewayConnection.java:72)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:155)
at android.app.ActivityThread.main(ActivityThread.java:5696)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
If use the sample code and do this:
networkContext = LFXClient.getSharedInstance(getApplicationContext()).getLocalNetworkContext();
networkContext.connect();
bulbList = networkContext.getAllLightsCollection().getLights();
Log.i(TAG, "Lights: " + bulbList.size());
bublList
is 0 where I expected it to be 1
If I use the SampleSDK I can see the bulb in the LFXSDKLightListAdapter
and turn it on and off.
If I turn it on using the SampleSDK or the official app, my app returns 1.
Am I doing something incorrectly?
Edit: I just noticed something else. If I close the app, and restart it sometimes it returns a bulb, however if I redeploy the app it returns 0.
Sometimes when I open after sometime, it does return 1.
How long does it take to get the list and how do I know when it gets a response?
This doesn't seem to be possible for some reason. I've tested connecting within an Activity, just to make sure I was doing things correctly. Then I moved the functionality into a service and it never connects.
I used this
as well as getApplicationContext()
for my Context and neither seem to allow connection.
Does this project include firmware 2.0 support? I'm looking for working examples...
java.lang.NullPointerException
at lifx.java.android.entities.internal.LFXMessage.getPayloadFromMessageData(LFXMessage.java:198)
at lifx.java.android.entities.internal.LFXMessage.initWithMessageData(LFXMessage.java:283)
at lifx.java.android.entities.internal.LFXMessage.messageWithMessageData(LFXMessage.java:248)
at lifx.java.android.network_context.internal.transport_manager.gateway_connection.LFXUDPGatewayConnection.udpSocketDidReceiveDataFromAddressWithFilterContext(LFXUDPGatewayConnection.java:274)
at lifx.java.android.network_context.internal.transport_manager.gateway_connection.LFXUDPGatewayConnection.notifyMessageReceived(LFXUDPGatewayConnection.java:324)
at lifx.java.android.network_context.internal.transport_manager.gateway_connection.LFXSocketGeneric.notifyAllListenersMessageReceived(LFXSocketGeneric.java:238)
at lifx.java.android.network_context.internal.transport_manager.gateway_connection.LFXSocketGeneric$1.handleMessage(LFXSocketGeneric.java:168)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5146)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:732)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)
at dalvik.system.NativeStart.main(Native Method)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.