MQTT Publish/Subscriber plugin

Plugins skapade av Switch Kings användare | Plugins created by Switch King users
cyberde
3 stars
3 stars
Posts: 61
Joined: Thu 11 Apr 2013, 08:00
Location: The Netherlands
Contact:

MQTT Publish/Subscriber plugin

Post by cyberde » Thu 07 May 2015, 12:54

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

krambriw
4 stars
4 stars
Posts: 336
Joined: Thu 19 Jul 2012, 19:41

Re: MQTT Publish/Subscriber plugin

Post by krambriw » Thu 07 May 2015, 15:56

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

krambriw
4 stars
4 stars
Posts: 336
Joined: Thu 19 Jul 2012, 19:41

Re: MQTT Publish/Subscriber plugin

Post by krambriw » Fri 08 May 2015, 18:19

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()

cyberde
3 stars
3 stars
Posts: 61
Joined: Thu 11 Apr 2013, 08:00
Location: The Netherlands
Contact:

Re: MQTT Publish/Subscriber plugin

Post by cyberde » Fri 08 May 2015, 18:35

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 :)

krambriw
4 stars
4 stars
Posts: 336
Joined: Thu 19 Jul 2012, 19:41

Re: MQTT Publish/Subscriber plugin

Post by krambriw » Sat 09 May 2015, 06:36

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
You do not have the required permissions to view the files attached to this post.

cyberde
3 stars
3 stars
Posts: 61
Joined: Thu 11 Apr 2013, 08:00
Location: The Netherlands
Contact:

Re: MQTT Publish/Subscriber plugin

Post by cyberde » Sat 09 May 2015, 09:12

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.

cyberde
3 stars
3 stars
Posts: 61
Joined: Thu 11 Apr 2013, 08:00
Location: The Netherlands
Contact:

Re: MQTT Publish/Subscriber plugin

Post by cyberde » Sat 09 May 2015, 11:51

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

krambriw
4 stars
4 stars
Posts: 336
Joined: Thu 19 Jul 2012, 19:41

Re: MQTT Publish/Subscriber plugin

Post by krambriw » Tue 12 May 2015, 16:00


cyberde
3 stars
3 stars
Posts: 61
Joined: Thu 11 Apr 2013, 08:00
Location: The Netherlands
Contact:

Re: MQTT Publish/Subscriber plugin

Post by cyberde » Sun 31 May 2015, 12:37

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)

fiskafan
1 star
1 star
Posts: 11
Joined: Fri 21 Jan 2011, 09:18

Re: MQTT Publish/Subscriber plugin

Post by fiskafan » Wed 23 Dec 2015, 15:33

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!

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests