Page 1 of 2

MQTT Publish/Subscriber plugin

Posted: Thu 07 May 2015, 12:54
by cyberde
Hi all,

As the development of this plugin has been shut down I've decided to create my own plugin, which offers even more!
It allows SK to publish datasource updates and device events to a topic and update datasources by the subscribed topic. It also allows you to configure an MQTT topic subscription from the SK client, so no fiddling around with config files to add or remove a topic. You only need to edit the config once and that's it. The plugin will do the rest.

You can find the plugin here: https://bluewalk.net/products/switch-king-mqtt-plugin

This thread will be here for questions and support

Re: MQTT Publish/Subscriber plugin

Posted: Thu 07 May 2015, 15:56
by krambriw
Now is the time...for those that have integrated EventGhost with SK, migrate to use MQTT instead!

In EventGhost you will find a MQTT Client plugin (mine of course :P ) that also will allow you to subscribe and publish events to various topics.

Mission completed.

BTW If you are into it already, why not ,link in Node-RED to the same MQTT broker and suddenly, a lot of other stuff becomes available

Re: MQTT Publish/Subscriber plugin

Posted: Fri 08 May 2015, 18:19
by krambriw
When I add your plugin, SwitchKing server is not starting...removing them...SK server starts again

Is a reboot needed???

My config

Code: Select all

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="MQTTTopicPrefix" value="SwitchKing"/>
    <add key="MQTTBrokerAddress" value="192.168.10.253"/>
    <add key="MQTTQOSLevel" value="2"/>
    <add key="MQTTRetain" value="false"/>
    <add key="PublishDeviceEvents" value="true"/>
    <add key="PublishDatasourceUpdates" value="true"/>
  </appSettings>
</configuration>
From SK server log

Code: Select all

{Framework Service - Startup} --<Status> -- 2015-05-08 19:15:52 -- Running version 3.2.3.1 of server and version 2.5.5 of DB.
{Framework Service - Startup} --<Status> -- 2015-05-08 19:15:52 -- Build date and time for this version is 2013-07-23 12:22:17.
{Framework Service - Startup} --<Status> -- 2015-05-08 19:15:52 -- Telldus version is 2.1.2.
{Framework Service - Startup} --<Status> -- 2015-05-08 19:15:52 -- Validating database version and executing upgrade scripts.
{Framework Service - Startup} --<Status> -- 2015-05-08 19:15:52 -- No upgrade performed. Database version is already up to date.
{Framework Service - Startup} --<Status> -- 2015-05-08 19:15:53 -- Status of license is NotFound.
{Framework Service - Startup} --<Status> -- 2015-05-08 19:15:53 -- Opening service channel for Framework.
{Framework Service - Startup} --<Status> -- 2015-05-08 19:15:53 -- Service channel for Framework opened.
{REST Service - Startup} --<Status> -- 2015-05-08 19:15:53 -- Opening service channel for REST.
{Plugin Loading} --<Status> -- 2015-05-08 19:15:53 -- Creating plugin of type Net.Bluewalk.MQTT.SwitchKingPlugin.Plugin.
{REST Service - Startup} --<Status> -- 2015-05-08 19:15:53 -- Service channel for REST opened.
{Invocation Service - Shutdown} --<Fatal> -- 2015-05-08 19:15:53 -- Main Thread Error. Exception: 
System.Reflection.TargetInvocationException

Level 1) Ett undantagsfel har uppstått i målet för en aktivering. 
Level 2) Det går inte att läsa in filen eller sammansättningen M2Mqtt, Version=4.1.0.0, Culture=neutral, PublicKeyToken=null eller ett av dess beroenden. Det går inte att hitta filen.

StackTrace for Level 1:
   vid System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck)
   vid System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache)
   vid System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache)
   vid System.Activator.CreateInstance(Type type, Boolean nonPublic)
   vid SwitchKing.Server.Plugins.PluginLoader.<>c__DisplayClass1`1.<GetPlugIns>b__0(Type t)
   vid System.Collections.Generic.List`1.ConvertAll[TOutput](Converter`2 converter)
   vid SwitchKing.Server.Plugins.PluginLoader.GetPlugIns[TPluginType](List`1 assemblies, List`1 instantiatedPlugins)
   vid SwitchKing.Server.BusinessAccess.Plugins.PluginHost.set_PluginAssemblies(List`1 value)
   vid SwitchKing.Server.WinSvcServiceHost.InvocationService.LoadPlugins()
   vid SwitchKing.Server.WinSvcServiceHost.InvocationService.ProcessDeviceEvents()
{UnhandledExceptionController_Framework} --<Critical> -- 2015-05-08 19:15:53 -- Exception: 
System.Reflection.TargetInvocationException

Level 1) Ett undantagsfel har uppstått i målet för en aktivering. 
Level 2) Det går inte att läsa in filen eller sammansättningen M2Mqtt, Version=4.1.0.0, Culture=neutral, PublicKeyToken=null eller ett av dess beroenden. Det går inte att hitta filen.

StackTrace for Level 1:
   vid System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck)
   vid System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache)
   vid System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache)
   vid System.Activator.CreateInstance(Type type, Boolean nonPublic)
   vid SwitchKing.Server.Plugins.PluginLoader.<>c__DisplayClass1`1.<GetPlugIns>b__0(Type t)
   vid System.Collections.Generic.List`1.ConvertAll[TOutput](Converter`2 converter)
   vid SwitchKing.Server.Plugins.PluginLoader.GetPlugIns[TPluginType](List`1 assemblies, List`1 instantiatedPlugins)
   vid SwitchKing.Server.BusinessAccess.Plugins.PluginHost.set_PluginAssemblies(List`1 value)
   vid SwitchKing.Server.WinSvcServiceHost.InvocationService.LoadPlugins()
   vid SwitchKing.Server.WinSvcServiceHost.InvocationService.ProcessDeviceEvents()
   vid System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   vid System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   vid System.Threading.ThreadHelper.ThreadStart()
{UnhandledExceptionController_Framework} --<Critical> -- 2015-05-08 19:15:53 -- Exception: 
System.Reflection.TargetInvocationException

Level 1) Ett undantagsfel har uppstått i målet för en aktivering. 
Level 2) Det går inte att läsa in filen eller sammansättningen M2Mqtt, Version=4.1.0.0, Culture=neutral, PublicKeyToken=null eller ett av dess beroenden. Det går inte att hitta filen.

StackTrace for Level 1:
   vid System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck)
   vid System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache)
   vid System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache)
   vid System.Activator.CreateInstance(Type type, Boolean nonPublic)
   vid SwitchKing.Server.Plugins.PluginLoader.<>c__DisplayClass1`1.<GetPlugIns>b__0(Type t)
   vid System.Collections.Generic.List`1.ConvertAll[TOutput](Converter`2 converter)
   vid SwitchKing.Server.Plugins.PluginLoader.GetPlugIns[TPluginType](List`1 assemblies, List`1 instantiatedPlugins)
   vid SwitchKing.Server.BusinessAccess.Plugins.PluginHost.set_PluginAssemblies(List`1 value)
   vid SwitchKing.Server.WinSvcServiceHost.InvocationService.LoadPlugins()
   vid SwitchKing.Server.WinSvcServiceHost.InvocationService.ProcessDeviceEvents()
   vid System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   vid System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   vid System.Threading.ThreadHelper.ThreadStart()

Re: MQTT Publish/Subscriber plugin

Posted: Fri 08 May 2015, 18:35
by cyberde
krambriw wrote:When I add your plugin, SwitchKing server is not starting...removing them...SK server starts again

Is a reboot needed???

My config

Code: Select all

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="MQTTTopicPrefix" value="SwitchKing"/>
    <add key="MQTTBrokerAddress" value="192.168.10.253"/>
    <add key="MQTTQOSLevel" value="2"/>
    <add key="MQTTRetain" value="false"/>
    <add key="PublishDeviceEvents" value="true"/>
    <add key="PublishDatasourceUpdates" value="true"/>
  </appSettings>
</configuration>
My sincere apologies, I forgot to add the required M2Mqtt.dll to the archive. I have reuploaded the zipfile to my website and if you redownload that file and make sure the M2Mqtt.dll is also in the Plugins folder, it will work :)

Also, just as a sidenote, with your prefix, the topic will become SwitchKing/switchking/datasource/ for example. Unless you want that of course :)

Re: MQTT Publish/Subscriber plugin

Posted: Sat 09 May 2015, 06:36
by krambriw
Nice, works fine now

++Good to have would be support for system mode & scenario changes

Integrated with Node-RED just using drag & drop of some nodes, see below
Skärmklipp.PNG

Re: MQTT Publish/Subscriber plugin

Posted: Sat 09 May 2015, 09:12
by cyberde
krambriw wrote:Nice, works fine now

++Good to have would be support for system mode & scenario changes
Good to know it works. I'll add system mode and scenario mode later today.

Re: MQTT Publish/Subscriber plugin

Posted: Sat 09 May 2015, 11:51
by cyberde
I have updated the plugin which you can download here: https://bluewalk.net/products/switch-king-mqtt-plugin/

Change log
- Fixed error in Device Command JSON
- Added support for receiving scenario changes
- Added support for controlling scenario's
- Added support for receiving system mode changes
- Added support for controlling system modes

Re: MQTT Publish/Subscriber plugin

Posted: Tue 12 May 2015, 16:00
by krambriw

Re: MQTT Publish/Subscriber plugin

Posted: Sun 31 May 2015, 12:37
by cyberde
An update is available, changelog is as followed:
- Added ability to control devices through MQTT (same commands as used in the REST service are available)
- Added update check for future updates (updates will appear in the logfile and will be published to the switchking/mqttplugin topic)

Re: MQTT Publish/Subscriber plugin

Posted: Wed 23 Dec 2015, 15:33
by fiskafan
Hi,

I just started using this plugin and it looks great. A major step forward in my MQTT project.

Question. Is there a way to "rename" the datasource output topic? currently the "switchking/datasource/{ID}" is sent and i can't find a way to rename it.

Having a totaly customaziable topic per datasource when publishing from switchking would be really great. In that way i could reuse the Topic naming hierarchy - for example map the datasource/1 to the topic name "home/firstfloor/temp1" - as in in my other mqtt devices.

Thanks!