This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

How to use android app to control LM
#1
Hi, 

I want to try making my own app in android studio for my smart home. Is there anyway to do this?
If it is, can someone guide me where to start in LM?
Reply
#2
You can use a WebSocket connection to read/write object values. There are built-in JavaScript libraries in LM that can be used in your app if using Cordova (https://cordova.apache.org/) instead of native Android app SDK. See this thread for more info: https://forum.logicmachine.net/showthread.php?tid=525
Reply
#3
(28.04.2021, 05:31)admin Wrote: You can use a WebSocket connection to read/write object values. There are built-in JavaScript libraries in LM that can be used in your app if using Cordova (https://cordova.apache.org/) instead of native Android app SDK. See this thread for more info: https://forum.logicmachine.net/showthread.php?tid=525

Hi, but I still create my app in android studio or should I use a different program?
Reply
#4
It's up to you to decide which tools to use. What do you want your app to do?
Reply
#5
(28.04.2021, 10:37)admin Wrote: It's up to you to decide which tools to use. What do you want your app to do?

Ok, I want to try to control lights and heating at first. 
I have KNX with LM installed and I use Mosaic at the moment, but I wanna try making my own if it is possible.
Reply
#6
That's not something that we can help you with unfortunately. My suggestion to use Cordova still stands because LM libraries can be reused directly. With native app you will have to handle the communication and data decoding yourself.
Reply
#7
(28.04.2021, 12:43)admin Wrote: That's not something that we can help you with unfortunately. My suggestion to use Cordova still stands because LM libraries can be reused directly. With native app you will have to handle the communication and data decoding yourself.

Ok, that's fine.

One last question then, how can I get the scripting visual in LM? Like if I just use Lua scripting for my "app" not visualization or Mosaic.
Reply
#8
If you mean that you want to use scripting in your external app then this is not possible. Android apps are written in Java not Lua and LM libraries are not available for external use.
Reply
#9
(29.04.2021, 07:43)admin Wrote: If you mean that you want to use scripting in your external app then this is not possible. Android apps are written in Java not Lua and LM libraries are not available for external use.

Hi, I found a way to implement websocket client in android. But how do I implement websocket server in LM?
Reply
#10
(01.05.2021, 08:40)Alexander Wrote:
(29.04.2021, 07:43)admin Wrote: If you mean that you want to use scripting in your external app then this is not possible. Android apps are written in Java not Lua and LM libraries are not available for external use.

Hi, I found a way to implement websocket client in android. But how do I implement websocket server in LM?

Hi Again,

Do I have to create a script in user libraries to activate LM as a websocket server?
Reply
#11
(28.04.2021, 05:31)admin Wrote: You can use a WebSocket connection to read/write object values. There are built-in JavaScript libraries in LM that can be used in your app if using Cordova (https://cordova.apache.org/) instead of native Android app SDK. See this thread for more info: https://forum.logicmachine.net/showthread.php?tid=525

Hi Admin,

Let me understand.
If I am going to implement a websocket server in LM, I first create a resident script with this script under:
Do I have to change anything in this script or add something? 

Code:
local copas = require'copas'

-- create a copas webserver and start listening
local server = require'websocket'.server.copas.listen
{
  -- listen on port 8080
  port = 8080,
  -- the protocols field holds
  --   key: protocol name
  --   value: callback on new connection
  protocols = {
    -- this callback is called, whenever a new client connects.
    -- ws is a new websocket instance
    echo = function(ws)
      while true do
        local message = ws:receive()
        if message then
           ws:send(message)
        else
           ws:close()
           return
        end
      end
    end
  }
}

-- use the copas loop
copas.loop()
Reply
#12
You don't need a script because the websocket server is already implemented (ws://LM_IP/apps/localbus.lp). Implementing the client in an Android app won't be a trivial task though.
Reply
#13
(12.05.2021, 05:56)admin Wrote: You don't need a script because the websocket server is already implemented (ws://LM_IP/apps/localbus.lp). Implementing the client in an Android app won't be a trivial task though.

Then I understand.

No, but I am trying with apache and a websocket plugin, but if it is to much work I'll maybe just use Mosaic for now Smile
Reply


Forum Jump: