What is it?
An easy webpage that shows the messages send and received by the Mysensor gateway connected to my Vera3 in a human readable way.
The gateway acts as the glue between your controller and radio network. It translates radio messages to a protocol which can be understood by a controller.
This protocol used by the Mysensors environment has the following structure:
As that is not quite understandable if you have a couple of dozen nodes laying around in your domotica environment, it gets tricky to get the right message for e.g. debug purposes.
The gateway has a port open you can listen to, in my case the default port 5003. With telnet the output can be made visible:
As depicted, the protocol is quite simple to read, but as I have no idea what node-id 19 is or subtype 2 if the messagetype is 1, this calls for the need of some webpage that does this for me.
This project uses SignalR and APS.NET Core 1.0 (it is called vNext and 5 as well, but the name is going to change according to the live.asp.net standups).
ASP.NET SignalR is a library for ASP.NET developers that makes it incredibly simple to add real-time web functionality to your applications. What is “real-time web” functionality? It’s the ability to have your server-side code push content to the connected clients as it happens, in real-time.
The SignalR 3 setup post from Jaka Konda was used.
The gateway in my Vera3 environment looks like (got to love the picture):
C# code
All the code can be found on my github: https://github.com/timdows/webpages/tree/master/MysensorListener
The Startup.cs got some configuration for SignalR and configures the GeneralSettings and VeraSettings.
The appsettings.json file should be modified to your needs with the IPAddress of your Vera and Gateway.
The VeraSettings.cs requests the user_data and processes it into rooms and devices to be used later.
The MysensorsController.cs get the SignalR ConnectionManager, GeneralSettings and VeraSettings injected by DI.
The only view is at the Index method. This also starts the SignalR MysensorsHub’s StartTelnetClient method in the background.
The MysensorsHub.cs holds the StartTelnetClient method, it creates a TCP connection to the Gateway and processes the data. If a MysensorsMessageStructure has been formed, it is send out via the SignalR environment.
The Index.cshtml and _Layout.cshtml make sure that the data is presentable on the webpage. The javascript functions broadcastMessage and broadcastObject insert the received data into the table or list.
End result
TODO
- Save the messages in a database and create an option to search through them.
What could be better
- It is possible that a message is received in two read cycles from the TCP stream (although the buffer is 1024 bytes), the hub than sends out the unprocessed message, but it appears under the table on the webpage hence it will go unnoticed.