more G-Labs products

Author Topic: MySensors Serial Gateway (v2.0)  (Read 4181 times)

October 14, 2016, 08:20:25 PM
Reply #15

raptorjr

  • ***
  • Information
  • Full Member
  • Posts: 78
Yes, I get a error in the log:

2016-10-14 20:17:48.8054 Error System.IO.IOException: Invalid argument
  at System.IO.Ports.SerialPortStream.ThrowIOException () [0x00000] in <filename unknown>:0
  at System.IO.Ports.SerialPortStream.SetSignal (SerialSignal signal, Boolean value) [0x00000] in <filename unknown>:0
  at (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPortStream:SetSignal (System.IO.Ports.SerialSignal,bool)
  at System.IO.Ports.SerialPortStream..ctor (System.String portName, Int32 baudRate, Int32 dataBits, Parity parity, StopBits stopBits, Boolean dtrEnable, Boolean rtsEnable, Handshake handshake, Int32 readTimeout, Int32 writeTimeout, Int32 readBufferSize, Int32 writeBufferSize) [0x00000] in <filename unknown>:0
  at (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPortStream:.ctor (string,int,int,System.IO.Ports.Parity,System.IO.Ports.StopBits,bool,bool,System.IO.Ports.Handshake,int,int,int,int)
  at System.IO.Ports.SerialPort.Open () [0x00000] in <filename unknown>:0
  at (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPort:Open ()
  at SerialPortLib.SerialPortInput.Open () [0x00000] in <filename unknown>:0

Maybe this isn't compatible in a Linux environment?

October 14, 2016, 08:27:53 PM
Reply #16

mvdarend

  • *****
  • Information
  • Hero Member
  • Posts: 431
I found this when searching the error string:

Quote
It turns out this is a problem using socat to create virtual serial ports and using the System.IO.Ports implementation in mono, the two just won't work together. This is not a bug with messagingtoolkit. It does however limit implementation on Linux when using virtual serial ports.

/dev/ttyUSB20: 20 seems like a high number, is it a virtual serial port?

October 14, 2016, 08:34:15 PM
Reply #17

raptorjr

  • ***
  • Information
  • Full Member
  • Posts: 78
Yes, it is virtual. I'm using this https://www.mysensors.org/build/raspberry so I can have my RPi3 act as a gateway. Without having to create a specific Arduino MySensor gateway that I then connect to my RPi. This way the RPi is the gateway.

So it is not possible to use the RPi as a gateway with a virtual serial port?

Would it be hard to implement a Ethernet gateway for HG? The above solution could be used as serial, ethernet or mqtt.

October 14, 2016, 08:39:08 PM
Reply #18

mvdarend

  • *****
  • Information
  • Hero Member
  • Posts: 431
Quote
So it is not possible to use the RPi as a gateway with a virtual serial port?

By the looks of it unfortunately no in the case of HomeGenie. HG runs on Mono and apparently Mono has a problem with virtual ports.

I'm not sure if it would be difficult to adapt the code I have already created to make an Ethernet/MQTT gateway. I don't suppose it would be too difficult.




October 14, 2016, 08:44:48 PM
Reply #19

raptorjr

  • ***
  • Information
  • Full Member
  • Posts: 78
Well, I can only appreciate the work you have done so far. I really love MySensors, and HG seems like a good controller. Even if I cant use it I hope more people begin to use MySensors and HG.

If you ever get the time to make a Ethernet gateway send me a message and I will try it.

October 14, 2016, 08:56:50 PM
Reply #20

mvdarend

  • *****
  • Information
  • Hero Member
  • Posts: 431
Too bad we couldn't get it to work. Maybe someone else will come along with a workaround.

If I or someone else creates a MQTT or Ethernet version I'll let you know. If you decide to make a standalone Serial Gateway I'll be happy to help again if you need it.

October 14, 2016, 09:54:22 PM
Reply #21

raptorjr

  • ***
  • Information
  • Full Member
  • Posts: 78
So, I made some changes to your code to make it to a Ethernet gateway. I think I succeeded, at least I get messages from my node.
But I have a few problem.

1. Only the temperature sensor is added. My waterflow and water valve is not added.
2. I was hoping that the module would appear as HomeAutomation.MySensors.FishTank (the name of my sketch). Since I can have many different Arduinos and sketches, it would be hard to find what sensors is connected to witch node. It would be easier than having to name each sensor like TempBedroom, TempOut, TempFridge and so on. Instead having a module HomeAutomation.MySensors.Bedroom, HomeAutomation.MySensors.Outdoor, and after that have Temperature for each. Would this be possible? And many nodes can be connected to one gateway.
3. I do get a popup every time my node updates the temperature, but I don't actually get the temperature value, it is always 0.00.
4. I didn't understand what <Address>1015</Address> was so I left it. Maybe need to change so it wont interfere with your serial version?

5. One more thing. Didn't know how I could get the right order of the Options, so now they are in a little mess. Would like to have IP address and Port as the two first fields.

Is there any way I can save my changes and send them back to you? Maybe you can figure out what is wrong.
« Last Edit: October 14, 2016, 09:56:50 PM by raptorjr »

October 14, 2016, 10:13:59 PM
Reply #22

mvdarend

  • *****
  • Information
  • Hero Member
  • Posts: 431
Wow, great work. Maybe we can get a Serial and Ethernet gateway solution for HomeGenie!

I'm not sure what the problems could be caused by, you can export the program in Edit mode via Actions -> Export. Post the .hgx file here and I'll take a look at it. (I'm about to go to bed though, so it will be some time tomorrow.)

I've got an old MQTT client gateway (v1.42) here which I'll convert to a v2.0 Ethernet gateway to test your code.


October 14, 2016, 10:25:03 PM
Reply #23

raptorjr

  • ***
  • Information
  • Full Member
  • Posts: 78
Here are the file with my changes.

October 15, 2016, 07:26:06 AM
Reply #24

mvdarend

  • *****
  • Information
  • Hero Member
  • Posts: 431
Actually your code works perfectly, well done. I didn't realise that creating a TCP connection to the MySensor Gateway was so easy, to be honest I hadn't put any time into it...

It actually shouldn't be hard to combine your and my scripts into a single MySensor APP, that should make maintenance easier than two seperate APPs.

But getting back to your questions:

1: That's probably because you left 'Group Subdevices...'* on, if you watch the widget for a few seconds you'll notice that it cycles through all the parameters. If you want separate widgets/modules per sensor you'll need to set Group SubDevices to False.

You can also check to see exactly which parameters are in the module via Configure -> Groups -> Open the Group -> Hamburger Icon (three lines)

2: You can Rename modules by clicking on the 'Gear' icon in the widget. (The gateway doesn't receive the sketch name AFAIK. When grouping SubDevices the first sensor name is given.)

Edit The name of the sketch is given... I never realised...

3: I'm guessing that you're actually seeing the Valve or Flow value, but as the widget is called 'Water temperature' it seems confusing.

4: You can ignore that, it shouldn't affect any other APP.

If you want to delete old modules to re-add them you can do the following:
- Remove the module/widget from the group (Configure -> Groups)
- Remove the module from homegenie (Configure -> Maintenance -> Configuration and Data -> Modules Cleanup)
- Restart HomeGenie (Configure -> Maintenance) if you want to be sure that the modules are completely gone. (When handing out new Id's it will 'remember' the old Id's if HG hasn't been restarted)


* There was a small error in the parameter description, it says "Group Subdevices with ID > 10 (True/False)", but it should be "... with ID < 10"
« Last Edit: October 15, 2016, 07:38:30 AM by mvdarend »

October 15, 2016, 08:53:17 AM
Reply #25

mvdarend

  • *****
  • Information
  • Hero Member
  • Posts: 431
Some things seem to have changed in the widgets since I last made a plugin for HG. It looks like 'unknown' data types are not displayed anymore in the standard sensor widget.

You should be able to see all the values via Configure -> Groups -> Open the Group -> Hamburger Icon (three lines) but they are not shown in the widget properly. I'll see if I can find a workaround. Otherwise we might have to create a Generic MySensor widget.

Edit: More info and a workaround here: Adding Sensor types
« Last Edit: October 15, 2016, 09:59:13 AM by mvdarend »

October 15, 2016, 10:54:24 AM
Reply #26

raptorjr

  • ***
  • Information
  • Full Member
  • Posts: 78
Besides the problem with the Sensor types that you describe. Which for now is a a little bit over my head =)
What I'm thinking about is the sketch name, and when you add modules to your group.

When grouping I think it should look like this:
HomeAutomation.MySensors
SketchName

With separate sensors:
HomeAutomation.MySensors.SketchName
Sensor1
Sensor2
...

Would that be possible? And then, in the first case, still have the name of the sensors shown when rotating?

And another problem, since a gateway can have many nodes. You have to choose a global option for all nodes, group or not? Would it be possible to choose this on a node per node basis?

I'm just throwing out ideas and thoughts, don't know if I over complicate things. But I think that MySensors nodes is different compared to other implementations and protocols. Where you can have many nodes on one gateway, and a node can have multiple sensors.

October 15, 2016, 11:28:02 AM
Reply #27

mvdarend

  • *****
  • Information
  • Hero Member
  • Posts: 431
I'm not sure if we're talking about the same things here, so I'll try to sum up how HomeGenie stores modules:

Basically HomeAutomation.MySensors is like a namespace, it's just a name used in the background for grouping devices based on their type. (in this case my sensors.)

When adding a module to a Group (Configure -> Groups) the available modules are grouped by this 'namespace'. (see HomeAutomation.MySensors.png)

In the MySensors HomeGenie APP you can choose to group sensors with 'Group Subdevices with ID < 10' if you set this to True, all subdevices with a ChildNodeId of less than 10 will be grouped. You should not group actuators as HG will not know exactly where to send the command.

In your case I would do something like the following: (in your MySensors Arduino sketch)
Water Temp : ChildNodeId = 1
Water Flow  : ChildNodeId = 2
Water valve : ChildNodeId = 10

(or not group them at all)

This way you will end up with two modules created:
- Module with Id 1 containing sensor info for Temp and Flow
- Module with Id 1.10 containg the binary switch

You can then add these two modules to whichever group (Configure -> Groups) you want, You can also add them to multiple groups, for example:

Group Fish Tank
- Both Module Id 1 and 1.10

Group Temperature
- Module Id 1 and any other temperature modules you might have

Group Switches
- Module 1.10 and any other switches you may have

You don't have to do this of course, just showing that  the 'GUI' groups are different (and more flexible) than the 'Namespace' groups.

Edit: Clarifications here and there
« Last Edit: October 15, 2016, 11:35:30 AM by mvdarend »

October 15, 2016, 12:10:11 PM
Reply #28

raptorjr

  • ***
  • Information
  • Full Member
  • Posts: 78
Thank you for explaining. All this is new to me, not only HG, but the whole MySensors thing also.

I think I understand what you are saying, and it works fine when you only have one node connected to your gateway. But what happens when you have more than one?

Suppose I have my Fish tank setup as you suggest:
Sketch name = FishTank
Water Temp : ChildNodeId = 1
Water Flow  : ChildNodeId = 2
Water valve : ChildNodeId = 10

And then I have two water irrigation nodes for some group of plants: (I don't have this, just an example)
Sketch name = Irrigation fontside
Soil humidity : ChildNodeId = 1
Outdoor temp  : ChildNodeId = 2
Irrigation valve : ChildNodeId = 10

Sketch name = Irrigation backside
Soil humidity : ChildNodeId = 1
Outdoor temp  : ChildNodeId = 2
Irrigation valve : ChildNodeId = 10

It feels that if you only have a (id.childid) it gets messy pretty fast. You'd have to figure out what node get which Id, and then remember which Id for which sensor/switch/valve. Is there any way to add the sketch name somewhere to make it easier to keep things apart? Because having to give all sensors/actuators unique names is pretty ugly.

I understand the thing about not grouping actuators, but would it be possible to keep them out of the group independent of the Id they have?
I'm thinking about your example, setting the valve to Id 10. And then at a later time I have a node with more than 10 sensors. Then sensors above 10 would not be grouped, and I would have to increase the number and change all my sketches too.
Sure, I can always set the actuators to Id 50 or something, but I think a better solution would be to automatically filter out all the things that can not be grouped.

I'm sorry about all the questions. I have tried to search for information on how everything works, but it is not easy to find. I really think HG looks good, and I want a powerful and flexible controller that looks good. And if I should take the time to really learn HG I must know that in the end it will be worth it. So I don't spend months just to realize it can't do something I need =)

Although it seems that development has stalled a bit. Not much have happened since the last beta release.

October 15, 2016, 12:26:24 PM
Reply #29

mvdarend

  • *****
  • Information
  • Hero Member
  • Posts: 431
Quote
Is there any way to add the sketch name somewhere to make it easier to keep things apart?
Yes, it is not (yet) added automatically, but once you've added the widget to a GUI Group you can rename it, see image in my last post. In the list you can see three nodes with Id's 1, 2 and three. (Node 2 is besically one node with 6 binary switches)

Node 3 'Front Door Multisensor' is a name I changed after adding to a group (it has four  grouped sensors, Lumens, Temp, Humidity and Motion) just click on the 'Options cog' on the widget and change the name. In the list you can also see a number of devices just called 'switch', but one of them has been renamed to BugLight Switch.

Automatically giving actuators a seperate widget should also be possible, I'll see what I can do.

Edit See images for an example of a 'Grouped' widget, this is the Front door multisensor, second image is the four values it rotates through.


« Last Edit: October 15, 2016, 12:54:10 PM by mvdarend »