B4A Library WeMo

WeMo
Comment:
WeMo is a series of products from Belkin International, Inc. that allows users to control home electronics. The product suite includes the WeMo Switch, WeMo Motion Sensor and WeMo App. The WeMo Switch can be plugged into any home outlet, which can then be controlled from an iOS or Android smartphone running the WeMo App, via home WiFi or mobile phone network.

See http://www.belkin.com/us/Products/home-automation/c/wemo-home-automation/ for more detail.

WeMoSDK provides classes and methods to display, search and control WeMo devices and NotificationListener interface to get notifications from them.

VERY IMPORTANT NOTE: The Belkin WeMo SDK currently only works over local WiFi networks, it does NOT allow control over the internet. This is a limitation of the SDK and not the library.

Author: Trevor Hart
Version: 1
  • WeMoDevice
    Methods:
    • IsInitialized As Boolean
    • isAvailable As Boolean
      It returns the availability of the device (not in official SDK documentation).
    Properties:
    • FriendlyName As String [read only]
      It returns the name of device. Different devices may have same friendly names.
    • Logo As String [read only]
      It returns the path to logo file in local storage. The return value may be null if local storage is not available. It is recommended to use this method to get the logo.
    • LogoURL As String [read only]
      It returns the URL to device logo. The logo may be downloaded by http.
    • SerialNumber As String [read only]
      It returns the serial number of the device (not in official SDK documentation).
    • State As String [read only]
      It returns the current state of the device. It may be WEMO_DEVICE_ON, WEMO_DEVICE_OFF and WEMO_DEVICE_UNDEFINED (if a problem has occurred during the state update) for switches and sensors. The state of Insight device may be also WEMO_DEVICE_STAND_BY.
    • Type As String [read only]
      It returns the type of device.The possible types are WEMO_TYPE_DEFAULT, WEMO_TYPE_SWITCH, WEMO_TYPE_SENSOR, WEMO_TYPE_LIGHT_SWITCH and WEMO_TYPE_INSIGHT.
    • UDN As String [read only]
      UDN uniquely identifies the device. All notification contains this parameter as argument.
  • WeMoSDKContext
    Fields:
    • WEMO_DEVICE_OFF As String
    • WEMO_DEVICE_ON As String
    • WEMO_DEVICE_STAND_BY As String
    • WEMO_DEVICE_UNDEFINED As String
    • WEMO_NOTIFY_ADD_DEVICE As String
    • WEMO_NOTIFY_CHANGE_STATE As String
    • WEMO_NOTIFY_REFRESH_LIST As String
    • WEMO_NOTIFY_REMOVE_DEVICE As String
    • WEMO_NOTIFY_SET_STATE As String
    • WEMO_NOTIFY_UPDATE_DEVICE As String
    • WEMO_TYPE_DEFAULT As String
    • WEMO_TYPE_INSIGHT As String
    • WEMO_TYPE_LIGHT_SWITCH As String
    • WEMO_TYPE_SENSOR As String
    • WEMO_TYPE_SWITCH As String
    Methods:
    • Initialize (EventName As String)
      Initializes the WeMoSDKContext and creates the listener from the event name.
    • IsInitialized As Boolean
    • getDeviceState (udn As String) As String
      This method returns the state of a device with the udn. If there is no such device it returns WEMO_DEVICE_UNDEFINED value. This method is analogue to WeMoDevice.getState().
    • getWeMoDeviceByUDN (udn As String) As WeMoDevice
      The method returns the WeMoDevice with provided udn if it exists and null otherwise.
    • refreshListOfWeMoDevicesOnLAN
      This method updates the list of discovered devices and their parameters (the friendly name, the state, the logo). It sends WEMO_NOTIFY_REFRESH_LIST notification on task completion.
    • setDeviceState (state As String, udn As String)
      It changes the state of the device with provided udn to the state passed as 1st parameter and sends notification with WEMO_NOTIFY_SET_STATE event. It is recommended to check the new state of the device by using getState() methods to detect If a problem has occurred during the state update.
    Permissions:
    • android.permission.ACCESS_COARSE_LOCATION
    • android.permission.ACCESS_FINE_LOCATION
    • android.permission.ACCESS_NETWORK_STATE
    • android.permission.ACCESS_WIFI_STATE
    • android.permission.CHANGE_WIFI_STATE
    • android.permission.INTERNET
    • android.permission.READ_PHONE_STATE
    • android.permission.WRITE_EXTERNAL_STORAGE
    Properties:
    • ListOfWeMoDevicesOnLAN As List [read only]
      It returns the list with UDNs of discovered devices. This method should be called on WEMO_NOTIFY_REFRESH_LIST notification to get up-to-date information. It doesn't update the device parameters.
 

Attachments

  • WeMo.zip
    241.5 KB · Views: 256
Last edited:

Douglas Farias

Expert
Licensed User
Longtime User
this is a very good way to make cash, but dont have 220v and dont have in brasil =(
 

tchart

Well-Known Member
Licensed User
Longtime User
Douglas, in New Zealand/Australia we use 220-240V and Belkin WeMo supports that voltage.

You could import one for use with an adaptor if you wanted one.
 

Douglas Farias

Expert
Licensed User
Longtime User
i dont have WeMo produts to test now, but with this lib is possible to make a app to turn on lamps, tvs, ventilator etc?
if i buy WeMo products will work with this lib app ?
 

tchart

Well-Known Member
Licensed User
Longtime User
i dont have WeMo produts to test now, but with this lib is possible to make a app to turn on lamps, tvs, ventilator etc?
if i buy WeMo products will work with this lib app ?

Correct.

However please note that the SDK (not the library) is limited to WiFi connection only. It does not expose this functionality through the internet/cloud at present. So yes you could activate lamps, tv's etc if you were on the same network as the WeMo plug. I don't know if Belkin will release an SDK to allow control over the internet/cloud.
 

Alberto Iglesias

Well-Known Member
Licensed User
Longtime User
Hello tchart,

I´m have a Wemo in Brazil and in my city is 220v and works very well.

In a lot of cities in Brazil the base of voltage is 220v in anothers, like SAO PAULO, is 110v.


Can you implement the REMOTE Wemo devices access ? With this option can access your internal devices through external internet, this is locate in wemo app settings, look:

With this option ENABLED I can turn On/off my switch through internet and not only inside intranet


wemoRemote.png
 

tchart

Well-Known Member
Licensed User
Longtime User
Alberto, the SDK from Belkin only support local connections. Im afraid its not possible right now.
 

canalrun

Well-Known Member
Licensed User
Longtime User
Thank you, tchart, for this library. I'm just playing with WeMo. I see it's about a year and a half since this library was created.

I found I had to download the WeMo SDK. It's up to version 1.1, but I just renamed it to 1.0 and everyone seems happy.
http://developers.belkin.com/wemo/sdk (scroll to the bottom)

I have two WeMo devices on my network – a switch and a link (controls two light bulbs).

The switch is detected by the library, but the link is not detected (not included in the returned list of devices).

I see there does not even seem to be a predefined TYPE constant for the link (lightbulbs).

The actual WeMo app from Belkin detects the switch, link and lightbulbs.

Is not detecting a link a known "feature" of the Belkin WeMo SDK? I wonder how they detect the link (lightbulbs)?

Barry.
 

tchart

Well-Known Member
Licensed User
Longtime User
Barry, thanks for notifying me. I only have the switches (well 3 of them). I didn't realise they had updated the SDK. I'll check the wrapper tonight.
 

canalrun

Well-Known Member
Licensed User
Longtime User
Thanks for the reply.

I contacted Belkin (WeMo) and they got back to me within a couple hours.

I told him that I had used the sample app that they provided with their 1.1 SDK and it also did not detect the link (lightbulbs) although it did detect the switch.

He told me that they were falling behind keeping the SDK up to the same version as the WeMo app on Google Play. The WeMo app has new features and more capability than the latest version of the SDK supports. He also said there were currently no plans to bring the SDK up to date – I got the feeling the reason was lack of interest from third-party developers.

He mentioned I might give them a little push if I could mention some enhancements third-party developers are working on.

A few emails from the B4X community expressing interest might go a long way. The email for the Belkin SDK comments I was given is:
[email protected]

I think your current library supports everything even in the 1.1 SDK version. I was able to just rename the jar to: WeMoSDK_1.0.jar and it seems to work.

Barry.
 
Top