Page 1 of 1

MQTT support?

Posted: Mon Dec 21, 2020 12:12 am
by takilara
I tried to search, but the search wouldnt work. If this has already been asked, i apologize.

As i frequently run many sessions, and often several instances of Mudlet, and sometimes even on different computers. I was thinking it would have been good to have a way to communicate between instances, preferably independent from the computer the instance is running at.

Mqtt might be one way to solve that.

I would also think that MQTT support could be a good way for users to easily implement telemetry.
(I do my telemetry using postHTTP() to InfluxDb, then show them in a grafana dashboard, but for most i would think simple mqtt dashboards would be simpler:)

best regards
Espen

Re: MQTT support?

Posted: Mon Dec 21, 2020 6:59 am
by Vadi
If you'd like you can install a Luarock that does it - https://luarocks.org/search?q=mqtt and then load it in.

Re: MQTT support?

Posted: Mon Dec 21, 2020 10:58 pm
by takilara
Thanks, I'll give that a try.
I actually think i tried loading luarocks before for something else (luasocket i believe), and got somewhat stuck on getting it (luarocks) to work.
I guess its just me being a newbie in using Lua (outside of Mudlet), i think i actually got stuck on getting a Lua interpreter built :D. I will give it some more attempts. (I have managed to build a lua executable now, but still struggling with getting luarocks to work right on windows)

Is there a wiki/doc for using luarocks with Mudlet? (on windows)
After i get luarocks to install the desired luarock, do i just copy the entire folder into Mudlet? or can Mudlet tie in to the "luarocks paths"? and use them directly?

would it be possible for me to run luarocks in wsl2? then possibly just copy the scripts out to mudlet?

*feeling dumb*
thanks again
Espen

Re: MQTT support?

Posted: Mon Dec 21, 2020 11:56 pm
by takilara
Update:
Still unable to get luarocks to work correct in windows, but at least on the path there...

I did the following interesting experiments in WSL2 though:
  • installed luarocks
  • installed luasocket and luamqtt
  • now i tried to copy the script folders out to the windows instance Mudlet and then tried to import it. No go
  • had a bright idea, installed x and mudlet in WSL2, running x server on my windows machine
  • started mudlet in wsl2, made a script, and imported mqtt, worked perfectly!
So my understanding at this point:
  • If i manage to install (and get luarocks) to work properly on windows, then the various rocks will be available in path, i should be able to just "require" them
  • wsl2 is awesome (thought it wont really be available on the vm i currently run mudlet on)
  • I kinda want to move to a linux based vm for mudlet, though i havent found a remoting solution i like/is as fast as RDP/and that i can connect/disconnect while leaving running
quest continues

Re: MQTT support?

Posted: Tue Dec 22, 2020 3:33 am
by SlySven
Mudlet will (and whatever Lua interpreter you are using should) consider the LUA_PATH (Lua script modules) and LUA_CPATH (C binary library modules) environmental variables as places where they will locate for the libraries/modules that Lua and Luarocks provide that are asked for when you do a require "moduleName" in your lua scripts.

It might be worth pointing out that Mudlet uses Lua 5.1 which is not the most current Lua version (that is 5.3 or 5.4 I believe) and the differences are such that your rocks need to be built to the major.minor version - though a third number suffixed onto those two (the release number) is not as significance. See https://www.lua.org/versions.html for the gory details if you really want to!

FTR I develop Windows versions of Mudlet using a MSYS2/Mingw-w64 setup ( https://www.msys2.org/ ; https://wiki.mudlet.org/w/Compiling_Mud ... rnative.29 ) which has suitable Luarocks packages - though you might need to tweak some configuration details if you wish to build code for BOTH i686 (32-Bit) and x86_64 (64-Bit) Windows systems - as the default configuration put the modules that are built for a particular user (with the --local option to the luarocks tool) in the same directory for both bitnesses even though 32-Bit Windows cannot execute the 64-bit ones - this is not a problem for the system-wide (available to all users) rocks as those are put in locations that are 32/64 bit specific.

Re: MQTT support?

Posted: Wed Dec 23, 2020 10:28 pm
by takilara
Thanks,
Yea, understood the luarocks would go into the path, when i got that to work on the linux build.

I am looking abit more at build chains now. have gotten a linux container to build mudlet on linux for me, and ill try to setup the windows build flow(s) also. However looking into if i can get the linux container to build the windows binaries for me :)

You mention building both for 32bit and 64bit. I was under the impression that the official windows builds are only 32bit? Would a 64bit build work?

Re: MQTT support?

Posted: Sat Jan 02, 2021 4:43 am
by SlySven
My 64-bit builds work for me - but I am not entirely sure of the form of the release builds. A lot of places in the Windows CI make mention of "Mingw" stuff - which is confusing because they might actually be the "Mingw-w64" fork - only the latter actually natively supports 64 Bit Windows whereas the original Mingw itself only makes 32-bit executables but they can also run on 64-Bit Windows as it automatically runs them in its WindowsOnWindows64 (WOW64) sub-system. Looking more closely it seems that Qt might actually be using the (better IMHO) fork for their Windows SDK offerings these days but I have not really got a grip on how that meshes into our current build system...

Re: MQTT support?

Posted: Sun Jan 03, 2021 2:15 pm
by takilara
SlySven wrote:
Tue Dec 22, 2020 3:33 am
Mudlet will (and whatever Lua interpreter you are using should) consider the LUA_PATH (Lua script modules) and LUA_CPATH (C binary library modules) environmental variables as places where they will locate for the libraries/modules that Lua and Luarocks provide that are asked for when you do a require "moduleName" in your lua scripts.
I did manage to get luarocks installed on windows, i then managed to get the luamqtt compiled and installed :) (i also needed to install luabitop?)
At this point i was able to run the luamqtt in the lua interpreter in my command prompt, after adding the LUA_PATH from luarocks path --bin manually in the command prompt.

I am still struggling with paths for mudlet though...

Launching Mudlet, its package.path and cpath was purely Mudlet folders, none of the luarocks folders. (at this point my machine did not have a LUA_PATH variable)

If i set the LUA_PATH system environment variable to the output of luarocks path --bin then Mudlet will only use this path, and not the mudlet APPDATA paths.

At this point i am guessing i need to somehow make mudlet aware of the luarocks path without replacing the full LUA_PATH.
(i assume not having the mudlet folders in the package.path is bad...)

(this was mighty easier in linux :D, well learning something new is good, and i still think enabling mqtt for cross profile communication (and telegram integration) will be awesome :D)

package.path (without LUA_PATH set)

Code: Select all

lua print(package.path)
C:\Users\austade\.config\mudlet\profiles\offline\?.lua;C:\Users\austade\.
config\mudlet\profiles\offline\?\init.lua;.\?.lua;C:\Users\austade\AppData\Local\Mudlet\app-4.10.
1\lua\?.lua;C:\Users\austade\AppData\Local\Mudlet\app-4.10.1\lua\?\init.
lua;C:\Users\austade\AppData\Local\Mudlet\app-4.10.1\?.
lua;C:\Users\austade\AppData\Local\Mudlet\app-4.10.1\?\init.lua  


package.path (with LUA_PATH set to output of luarocks path --bin)

Code: Select all

lua print(package.path)
C:\Users\austade\.config\mudlet\profiles\offline\?.lua;C:\Users\austade\.
config\mudlet\profiles\offline\?\init.lua;C:\Program Files (x86)\LuaRocks\lua\?.lua;C:\Program 
Files (x86)\LuaRocks\lua\?\init.lua;.\?.lua;C:\Program Files (x86)\LuaRocks\?.lua;C:\Program Files 
(x86)\LuaRocks\?\init.lua;C:\Users\austade\AppData\Roaming/luarocks/share/lua/5.1/?.
lua;C:\Users\austade\AppData\Roaming/luarocks/share/lua/5.1/?/init.lua;C:\Program Files 
(x86)\LuaRocks\systree/share/lua/5.1/?.lua;C:\Program Files (x86)\LuaRocks\systree/share/lua/5.
1/?/init.lua  
Edit: added outputs of package.path

Re: MQTT support?

Posted: Sun Jan 03, 2021 6:19 pm
by takilara
Update:
So, adding the LUA_PATH and LUA_CPATH from luarocks path --bin almost works. At this point:
  • Lua interpreter started from command line can now happily require rocks ive installed (tested with mqtt, luasocket and luacjson).
  • Trying the same in Mudlet yields a "The specified module could not be found" for some modules, and a circular loop for others. It seems to look in the correct folder though. (error message for the "could not be found" points to the correct files. These files are in the indicated location ...)
The only main difference between the interpreter and Mudlet i suspect is that it may be something related to bitness, however this seems "opposite" to what i expected.
Using

Code: Select all

if(0xfffffffff==0xffffffff) then return 32 else return 64 end
to check bitness:
  • Mudlet returns 64
  • Interpreter returns 32
Anyone have any idea? At this point im not sure what i should do?
  • Keep trying to get Mudlet to recognize the luarocks (try to compile luarocks and lua interpreter to 64bit instead of 32 bit)
  • Migrate to WSL and Linux based Mudlet instances (as the luarocks work here)
  • Try to build Mudlet with the particular rock included? (probably beyond my skillset)
  • Try to build Mudlet with the particular rock included? (probably beyond my skillset)
Trying to require cjson

Code: Select all

        <error loading module 'cjson' from file 'C:\Program Files (x86)\LuaRocks\systree\lib\lua\5.
1\cjson.dll':
	The specified module could not be found.
>
Trying to require mqtt (i get the same message for "socket")

Code: Select all

        <[string "-------------------------------------------..."]:282: loop or previous error 
loading module 'mqtt'>
Paths for reference:
Mudlet:

Code: Select all

lua print(package.path)
C:\Users\espen\.config\mudlet\profiles\Greylock\?.lua;C:\Users\espen\.
config\mudlet\profiles\Greylock\?\init.lua;C:\Program Files (x86)\LuaRocks\lua\?.lua;C:\Program 
Files (x86)\LuaRocks\lua\?\init.lua;C:\Users\espen\AppData\Roaming\luarocks\share\lua\5.1\?.
lua;C:\Users\espen\AppData\Roaming\luarocks\share\lua\5.1\?\init.lua;C:\Program Files 
(x86)\LuaRocks\systree\share\lua\5.1\?.lua;C:\Program Files (x86)\LuaRocks\systree\share\lua\5.
1\?\init.lua;    
lua print(package.cpath)
C:\Users\espen\.config\mudlet\profiles\Greylock\?.dll;C:\Qt\Tools\mingw730_32\lib\lua\5.1\?.dll;.\?.
dll;C:\Program Files (x86)\LuaRocks\?.dll;C:\Program Files (x86)\LuaRocks\loadall.dll;C:\Program 
Files (x86)\LuaRocks\clibs\?.dll;C:\Program Files (x86)\LuaRocks\clibs\loadall.dll;.\?51.
dll;C:\Program Files (x86)\LuaRocks\?51.dll;C:\Program Files (x86)\LuaRocks\clibs\?51.
dll;C:\Users\espen\AppData\Roaming\luarocks\lib\lua\5.1\?.dll;C:\Program Files 
(x86)\LuaRocks\systree\lib\lua\5.1\?.dll;  
Interpreter:

Code: Select all

C:\Program Files (x86)\LuaRocks>lua5.1.exe
Lua 5.1.5  Copyright (C) 1994-2012 Lua.org, PUC-Rio
> print(package.path)
C:\Program Files (x86)\LuaRocks\lua\?.lua;C:\Program Files (x86)\LuaRocks\lua\?\init.lua;C:\Users\espen\AppData\Roaming\luarocks\share\lua\5.1\?.lua;C:\Users\espen\AppData\Roaming\luarocks\share\lua\5.1\?\init.lua;C:\Program Files (x86)\LuaRocks\systree\share\lua\5.1\?.lua;C:\Program Files (x86)\LuaRocks\systree\share\lua\5.1\?\init.lua;
> print(package.cpath)
.\?.dll;C:\Program Files (x86)\LuaRocks\?.dll;C:\Program Files (x86)\LuaRocks\loadall.dll;C:\Program Files (x86)\LuaRocks\clibs\?.dll;C:\Program Files (x86)\LuaRocks\clibs\loadall.dll;.\?51.dll;C:\Program Files (x86)\LuaRocks\?51.dll;C:\Program Files (x86)\LuaRocks\clibs\?51.dll;C:\Users\espen\AppData\Roaming\luarocks\lib\lua\5.1\?.dll;C:\Program Files (x86)\LuaRocks\systree\lib\lua\5.1\?.dll;