Announcement

Collapse
No announcement yet.

HSPI_MoskusSample - An easier plugin sample [VB.NET]

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #46
    Davros,

    this look cool, did you post you TCP sample somewhere?

    Comment


      #47
      Hi mate.

      Sorry, never did get to clean it up and include in demo code. On the plus side, it has been running fine for the last few months

      Happy to post warts and all version - my plugin for my DAB1 audio amp which is based off of the sample.

      In this example, the TCP Port is set up as a server that sits and listens to a specified port and is used to relay commands to the serial port. So anything you send to the TCP port will be sent to the serial device (DAB1) in this case.
      Nothing is sent out the TCP port to the attached clients...it could be, but in this example it is not. The code I posted over in the other thread (https://forums.homeseer.com/showpost... &postcount=12) gives an example od sending data to attached clients, as well as an example of setting up the plugin as a client rather than a server.

      Hope that helps.
      Last edited by davros; May 22, 2017, 10:33 PM.

      Comment


        #48
        Updated the TCP code to address issue with high cpu when a client disconnects.
        Attached Files

        Comment


          #49
          Here is some client code I hacked up that I'll be using/adapting to maintain a connection to a remote server. It tries a reconnect every x seconds (10 seconds in this case. Seems to work ok.

          Hope it is of use to others and as always, feel free to improve/adapt and post your code....not that anyone ever does

          Code:
          Imports System.Net
          Imports System.Net.Sockets
          Imports System.Text
          Imports System.Timers
          
          Module MainModule
          
              Dim clientSocket As TcpClient
              Dim ns As NetworkStream
              Dim ns1 As NetworkStream
              Dim TCPServerMonitorTimer As New Timer(10000) ' 2000 = 2sec   ' 10000 = 10 sec
          
          
              Sub Main()
                  AddHandler TCPServerMonitorTimer.Elapsed, AddressOf MonitorTCPServer
                  TCPServerMonitorTimer.Enabled = True
                  ConnectToServer()
                  While True
          
                  End While
          
              End Sub
          
              Private Function ConnectToServer() As Boolean
                  Try
          
                      Dim ip As String = "192.168.0.226"
                      Dim port As Integer = 20108
          
                      clientSocket = New TcpClient(ip, port)
                      Dim ctThread As Threading.Thread = New Threading.Thread(AddressOf getMessage)
                      ctThread.Start()
                      Return True
                  Catch ex As Exception
                      Try
                          clientSocket.Close()
                      Catch
                      End Try
                      Console.WriteLine(ex)
                      Return False
                  End Try
          
              End Function
          
              Private Sub getMessage()
                  Try
                      Dim ns As NetworkStream = clientSocket.GetStream()
          
                      While True
                          Dim toReceive(100000) As Byte
                          Dim length As Integer = ns.Read(toReceive, 0, toReceive.Length)
                          Dim text As String = Encoding.ASCII.GetString(toReceive, 0, length)
                          Console.WriteLine(text)
                          Dim toSend() As Byte = Encoding.ASCII.GetBytes("Send me")
                          ns.Write(toSend, 0, toSend.Length)
                      End While
          
                  Catch ex As Exception
                      Console.WriteLine(ex)
                  End Try
          
              End Sub
          
              Private Sub SendData(textToSendToServer As String)
                  Try
                      Dim ns1 As NetworkStream = clientSocket.GetStream()
                      Dim toSend() As Byte = Encoding.ASCII.GetBytes(textToSendToServer)
                      ns1.Write(toSend, 0, toSend.Length)
          
          
                  Catch ex As Exception
                      Console.WriteLine(ex)
                      Try
                          clientSocket.Close()
                      Catch
                      End Try
                      ConnectToServer()
                  End Try
              End Sub
          
          
              Private Sub MonitorTCPServer(source As Object, e As ElapsedEventArgs)
                  SendData("")
              End Sub
          
          End Module
          Last edited by davros; May 31, 2017, 09:57 PM.

          Comment


            #50
            Originally posted by davros View Post
            Yep. And on the back of this I have just completed by first plugin for my Arduino Mega Based IO Controller.

            16 Relays contacts, 8 interupt driven opto-isolated Digital inputs (dry and active), 8 Analog opto isolated inputs. Very happy.
            Relays can be set to timed events and it saves state. It's run via simple command like "11,2;" to set relay 2 to on, and returns state as "R2=1".

            I even used PlugExtraData to store device info. which turns out to be very useful - and like many things HS, unecessarily complex and poorly documented.

            Hey, does anyone have a TCPIP server Visual Studio VB.Net Solution/project they can share

            Happy to reshape and publish as a TCP demo interface as per serial.

            Sharing is caring
            Enigmatheatre has written a plugin for Arduino - I hope you are aware.

            Comment


              #51
              HSPI_MoskusSample - An easier plugin sample [VB.NET]

              Originally posted by ecuboss View Post
              Enigmatheatre has written a plugin for Arduino - I hope you are aware.


              Thanks for posting mate. Yes, I am. I use a bunch of arduinos for various tasks and they are rather custom

              Ie one is Ethernet and serial controlled, 16 relays, 8 (opto-isolated) interrupt driven digital inputs, analogue inputs and remote devices over RFM12B (same radio as used by jeelabs).

              I also like open source so I can debug and adapt as needed. It's working great for multiple roles and hopefully will help others to interface to their projects over serial or tcp.



              Sent from my iPad using Tapatalk
              Last edited by davros; June 20, 2017, 06:10 PM.

              Comment


                #52
                HSPI_MoskusSample - An easier plugin sample [VB.NET]

                Sent from my iPad using Tapatalk

                Comment


                  #53
                  Windows Forms App?

                  What would it take to "convert" this sample plugin to a Windows Forms App?

                  I've written vb.net applications that are based on the Windows Forms App template, but I don't know how to adapt this sample plugin accordingly. With Forms capability, menus could be developed to do practically everything with HS3.

                  My compiled forms-based vb.net apps are executed from HS3, but none of them can communicate directly with HS3 like this plugin does.

                  This "easier plugin sample" works well and is a great resource and learning tool! Thanks!

                  Frank

                  Comment


                    #54
                    Originally posted by frankc View Post
                    What would it take to "convert" this sample plugin to a Windows Forms App?

                    I've written vb.net applications that are based on the Windows Forms App template, but I don't know how to adapt this sample plugin accordingly. With Forms capability, menus could be developed to do practically everything with HS3.

                    My compiled forms-based vb.net apps are executed from HS3, but none of them can communicate directly with HS3 like this plugin does.

                    This "easier plugin sample" works well and is a great resource and learning tool! Thanks!

                    Frank
                    Just create a new Windows Forms project and include all the code from MoskusSample?

                    If you want to communicate directly with HS3 there's an easier way than include all plugin functions, I just need to remember how...


                    What exactly are you trying to achieve?
                    HSPro 3.0.0.458, Z-NET with Z-wave plugin 3.0.1.190, RFXCOM + 2x RFXtrx433E, HSTouch, Squeezebox plugin, iTach IP/WF2IR & GC-100-6 with UltraGCIR, BLDenon, NetcamStudio, Jon00s Webpage builder, Harmony Hub plugin, SCSIP (with FreePBX), Arduino plugin, IFTTT, Pushalot plugin, Device History plugin.
                    Running on Windows 10 (64) virtualized
                    on ESXi (Fujitsu Primergy TX150 S8).
                    WinSeer (for Win10) - TextSeer - FitbitSeer - HSPI_MoskusSample

                    Are you Norwegian (or Scandinavian) and getting started with HomeSeer? Read the "HomeSeer School"!

                    Comment


                      #55
                      Originally posted by Moskus View Post
                      What exactly are you trying to achieve?
                      Hi Magnus,

                      I was thinking that it would be nice to have a GUI to work with your plugin, that would allow a user to experiment with the different options by pressing buttons and using labels. (maybe?)

                      Since I posted that message, I've come up with a windows forms application that uses an HS3 connector routine that works well. It has a button to speak, writes to the HS3 log, and buttons to turn a device on and off for example. Making that stuff work was a real breakthrough for me.

                      I have never found an HS3 application that used a connector and a Windows Form. Custom menus can be made and graphic displays can be shown. Maybe others just don't have a need for such an arrangement. I'm not real sure how such an arrangement could be added to your plugin.

                      Thanks for your time Magnus,

                      Frank

                      Comment


                        #56
                        Originally posted by frankc View Post
                        I was thinking that it would be nice to have a GUI to work with your plugin, that would allow a user to experiment with the different options by pressing buttons and using labels. (maybe?)

                        Since I posted that message, I've come up with a windows forms application that uses an HS3 connector routine that works well. It has a button to speak, writes to the HS3 log, and buttons to turn a device on and off for example. Making that stuff work was a real breakthrough for me.

                        I have never found an HS3 application that used a connector and a Windows Form. Custom menus can be made and graphic displays can be shown. Maybe others just don't have a need for such an arrangement. I'm not real sure how such an arrangement could be added to your plugin.

                        Thanks for your time Magnus,

                        Frank
                        Well, here's my two cents.

                        GUI is nice, but only as a web GUI. Why? Because I never actually sit in front of my HomeSeer server, and I guess that goes for most users. My server is headless (without a monitor), and I just use Remote Desktop to run Windows Update when I have to.

                        Linux users (and that includes Zee2 users) don't even have (or need) a GUI.


                        But if you need some sort of connection to HomeSeer on your desktop, then I think Jon00 has some nice scripts/plugins that already does this.
                        HSPro 3.0.0.458, Z-NET with Z-wave plugin 3.0.1.190, RFXCOM + 2x RFXtrx433E, HSTouch, Squeezebox plugin, iTach IP/WF2IR & GC-100-6 with UltraGCIR, BLDenon, NetcamStudio, Jon00s Webpage builder, Harmony Hub plugin, SCSIP (with FreePBX), Arduino plugin, IFTTT, Pushalot plugin, Device History plugin.
                        Running on Windows 10 (64) virtualized
                        on ESXi (Fujitsu Primergy TX150 S8).
                        WinSeer (for Win10) - TextSeer - FitbitSeer - HSPI_MoskusSample

                        Are you Norwegian (or Scandinavian) and getting started with HomeSeer? Read the "HomeSeer School"!

                        Comment


                          #57
                          Originally posted by Moskus View Post
                          Well, here's my two cents.
                          Makes sense. In my case, my Homeseer server and its access are on the same desktop computer along with Netcam Studio. So that stuff is accessed directly.

                          What I want to do is to use an app, maybe a vb.net app, with an HS3 connection to display HS3 controls and camera video on some sort of network connected ~10* tablet display in other rooms in the house.

                          Maybe that would be an HSTouch app, but I'm not sure.

                          Comment


                            #58
                            Originally posted by Moskus View Post
                            Here's the download.

                            Changelog:
                            1.0.0: Initial release.
                            Have there been any updates in the last ohhh 3 years? I'm just starting out with trying to learn the plugin system and looking for a good place to start.

                            Comment


                              #59
                              Actually, not really. The changes to the plugin API are so small that this sample still works without problems.
                              HSPro 3.0.0.458, Z-NET with Z-wave plugin 3.0.1.190, RFXCOM + 2x RFXtrx433E, HSTouch, Squeezebox plugin, iTach IP/WF2IR & GC-100-6 with UltraGCIR, BLDenon, NetcamStudio, Jon00s Webpage builder, Harmony Hub plugin, SCSIP (with FreePBX), Arduino plugin, IFTTT, Pushalot plugin, Device History plugin.
                              Running on Windows 10 (64) virtualized
                              on ESXi (Fujitsu Primergy TX150 S8).
                              WinSeer (for Win10) - TextSeer - FitbitSeer - HSPI_MoskusSample

                              Are you Norwegian (or Scandinavian) and getting started with HomeSeer? Read the "HomeSeer School"!

                              Comment


                                #60
                                Originally posted by Moskus View Post
                                Actually, not really. The changes to the plugin API are so small that this sample still works without problems.
                                I have a C# tool that I would like to turn into a plugin. Do you have a sample framework for C#? Or would I be better off trying to re-write into VB.Net?

                                The current code is not huge in size so a re-write shouldn't be huge, but I don't know VB.Net or C# for that matter. I'm just learning and I whipped up the C# version over the last several days.

                                Comment

                                Working...
                                X