HomeGenie Forum

Automation Program Plugins and Wizard Scripting => APP Contributions => Topic started by: mvdarend on October 12, 2016, 08:10:29 PM

Title: MySensors Serial Gateway (v2.0)
Post by: mvdarend on October 12, 2016, 08:10:29 PM
The MySensor Serial Gateway has been replaced with a combined Serial/Ethernat gateway.

I've created a new thread for this:
http://www.homegenie.it/forum/index.php?topic=1725.0 (http://www.homegenie.it/forum/index.php?topic=1725.0)
Title: Re: MySensors Serial Gateway (v2.0)
Post by: mvdarend on October 12, 2016, 10:29:48 PM
Oops... I just realised that the Controller is not handing out NodeIds... :-[ I was using old MySensor Nodes that already had Id's assigned by the previous version I created.

I'll have to fix that, as a workaround you can set the NodeId manually with the following code:

Code: [Select]
#define MY_NODE_ID 1
Title: Re: MySensors Serial Gateway (v2.0)
Post by: mvdarend on October 14, 2016, 12:59:06 PM
ID_REQUEST is now implemented.

For 'grouped' modules, I've added meta data to the ChildrenNodes to better differentiate between data types.
Title: Re: MySensors Serial Gateway (v2.0)
Post by: raptorjr on October 14, 2016, 06:17:59 PM
Either this is very easy and I'm complicating things, or I'm really stupid =) I can't figure out how to use it.
I think I have added it as a Interconnection(although I thought first that I should add it as a Interface in some way), but I get a blue light, and that don't feel right. I have tested to add the Serial Gateway in Domoticz, and it works, so I guess it's all about configuring HG the right way.

Any chance of a small walkthrough on how to set up this?
Title: Re: MySensors Serial Gateway (v2.0)
Post by: mvdarend on October 14, 2016, 06:43:38 PM
Blue light is good, it means that the APP is running correctly (in the background)

If the COM port and baud rate are correct you can try modifying the code slightly to see if messages are being received correctly, you can do this as follows:

- Go to: Configure -> Programs -> Interconnections -> MySensors APP and click on it
- Click on Edit
- Go to tab 'Program code'

At line 27 uncomment the the line Program.Notify (also comment the Pause line if you want:
Code: [Select]
  // this will be called every time a message is received from serial port
  //Program.Notify("SerialPort String", incoming);
  //Pause(5);

You should now see if messages are arriving in Homegenie, Power cycle (or reset) the gateway or one of the sensors to force it to Present itself again and see if you are getting popups in HomeGenie (see image example)

Edit: Forgot to add, once all is OK, you'll need to add the actual module (or widgets) to the interface, you can do this as follows:

- Go to Configure -> Groups
- Create a new group and open it (or open an existing one)
- Go to Actions -> Add Module
- You should see a group 'HomeAutomation.MySensors' with the modules
Title: Re: MySensors Serial Gateway (v2.0)
Post by: raptorjr on October 14, 2016, 07:00:06 PM
Thank you for your help. But it doesn't seem to be anything coming in to HG.

If I do  cat /dev/ttyUSB20 and restart my MySensor node. I get this:

1;255;0;0;17;2.0.1-beta
1;255;3;0;6;0
1;255;3;0;11;FishTank
1;255;3;0;12;1.0
1;1;0;0;6;Water temperature
1;2;0;0;3;Water valve
1;3;0;0;21;Water flow
1;3;1;0;34;0.0
1;3;1;0;35;0.00
1;1;1;0;0;24.7
1;3;1;0;34;0.0
1;3;1;0;35;0.00
1;1;1;0;0;24.7

First presenting name and sensors attached, and then starting to report temperature and water flow/volume.
But I don't get any message in HG.

This is my configuration of MySensor Serial gateway in HG:
    BaudRate = "115200"
    Fri Oct 14 2016 17:54:10 GMT+0200 (W. Europe Standard Time)
    COMPort = "/dev/ttyUSB20"
    Fri Oct 14 2016 17:54:45 GMT+0200 (W. Europe Standard Time)
    GroupSubDevices = "True"
    Fri Oct 14 2016 17:54:10 GMT+0200 (W. Europe Standard Time)
    InclusionMode = "True"
    Fri Oct 14 2016 17:54:10 GMT+0200 (W. Europe Standard Time)
    Module Parameters
    Program.Status = "Background"
    Fri Oct 14 2016 18:55:29 GMT+0200 (W. Europe Standard Time)
Title: Re: MySensors Serial Gateway (v2.0)
Post by: mvdarend on October 14, 2016, 07:09:49 PM
When you restart the MySensor APP do you see a 'MySensors COM Port Status CONNECTED!' popup?
Title: Re: MySensors Serial Gateway (v2.0)
Post by: raptorjr on October 14, 2016, 07:14:24 PM
No, no message.
Title: Re: MySensors Serial Gateway (v2.0)
Post by: mvdarend on October 14, 2016, 07:20:34 PM
Have you ever clicked on the Stop/Hand icon when you got one of those popus? That could be the reason you're no longer getting them.

If you have you can remove it from the Blocked popup list as follows:

- Configure -> Maintenance
- Open User Interface
- Click on Blocked Popups -> Edit button
- Remove the blocked popup from the list

There's a good chance that modules have already been created, but that there was no notification because of the blocked popups, have you tried adding a new module to a group yet, can you see the mysensors modules in the list?
Title: Re: MySensors Serial Gateway (v2.0)
Post by: raptorjr on October 14, 2016, 07:28:28 PM
No blocked popups. Haven't done much with HG other than trying the demo things. I only have MySensors nodes, so before you made this I hadn't anything to test with.

I have no module that has anything to do with MySensors. I guess the sensors should appear below a bold/italic text that says something about MySensors.FishTank or something like that? (Since that is the name of my node)

Can I add some more log printing in the Program to see how far we get in the code? Or is there some HG log that can tell us anything?
Title: Re: MySensors Serial Gateway (v2.0)
Post by: mvdarend on October 14, 2016, 07:38:05 PM
I have no idea what could be wrong, not getting a 'Serial connected' (or even a connection error) popup seems strange, especially seeing as the App has a blue icon which means it is running.

Could you try going to COnfigure -> Maintenance -> Configuration and Data -> Modules cleanup -> Select Modules?

Do you see any MySensor nodes in the list?
Title: Re: MySensors Serial Gateway (v2.0)
Post by: raptorjr on October 14, 2016, 07:47:03 PM
Yes, it says 1000 MySensors Serial Gateway.

Could it be som kind of permission issue on my Raspberry Pi3?
Title: Re: MySensors Serial Gateway (v2.0)
Post by: mvdarend on October 14, 2016, 07:54:22 PM
Not sure if it could be a permissions issue, I'm running HomeGenie on a Windows machine and I don;t know very much about Linux.

Is Domoticz still running on your RPi? Could it be blocking the COM port? (or some other program?)

I forgot to answer your last question, the code you uncommented earlier is the first line of code after a message has been received on the COM port, if that isn;t showing anything then there is no message being received.
Title: Re: MySensors Serial Gateway (v2.0)
Post by: raptorjr on October 14, 2016, 07:55:57 PM
Domoticz is running. But I can stop it. Thought it shouldn't be a problem since I got output from /dev/ttyUSB20. But I'll try.


No, didn't make a change. Stopped Domoticz and restarted the APP. No message.

You say that the first thing received. But what if the port can't be opened? Is it possible to add some debug output on the call to open the port? To see if that fails? Or that should always generate Connected or Disconnected?
Title: Re: MySensors Serial Gateway (v2.0)
Post by: mvdarend on October 14, 2016, 08:16:45 PM
I'm not sure how to get more feedback from the Serial connection, I only get a true or false back.

In Maintenance -> System options you can enable to log file. If it's already been enabled open it and search for the COM port address.

If it has not been enabled you can do it now and then restart the APP, hopefully you'll find some info in there.

I tested it with a non-existant port number on my machine and got the following in the logs:

Code: [Select]
2016-10-14 20:11:01.4140 Error System.IO.IOException: The port 'COM55' does not exist.
   at System.IO.Ports.InternalResources.WinIOError(Int32 errorCode String str)
   at System.IO.Ports.SerialStream..ctor(String portName Int32 baudRate Parity parity Int32 dataBits
   at System.IO.Ports.SerialPort.Open()
   at SerialPortLib.SerialPortInput.Open()

Edit: By using a non existant COM port I could reproduce the problem you seem to be getting. Maybe I'm parsing the COM port string incorrectly (I've only tested it on a Windows machine)
Title: Re: MySensors Serial Gateway (v2.0)
Post by: raptorjr on October 14, 2016, 08:20:25 PM
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?
Title: Re: MySensors Serial Gateway (v2.0)
Post by: mvdarend on October 14, 2016, 08:27:53 PM
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?
Title: Re: MySensors Serial Gateway (v2.0)
Post by: raptorjr on October 14, 2016, 08:34:15 PM
Yes, it is virtual. I'm using this https://www.mysensors.org/build/raspberry (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.
Title: Re: MySensors Serial Gateway (v2.0)
Post by: mvdarend on October 14, 2016, 08:39:08 PM
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.



Title: Re: MySensors Serial Gateway (v2.0)
Post by: raptorjr on October 14, 2016, 08:44:48 PM
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.
Title: Re: MySensors Serial Gateway (v2.0)
Post by: mvdarend on October 14, 2016, 08:56:50 PM
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.
Title: Re: MySensors Serial Gateway (v2.0)
Post by: raptorjr on October 14, 2016, 09:54:22 PM
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.
Title: Re: MySensors Serial Gateway (v2.0)
Post by: mvdarend on October 14, 2016, 10:13:59 PM
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.

Title: Re: MySensors Serial Gateway (v2.0)
Post by: raptorjr on October 14, 2016, 10:25:03 PM
Here are the file with my changes.
Title: Re: MySensors Serial Gateway (v2.0)
Post by: mvdarend on October 15, 2016, 07:26:06 AM
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"
Title: Re: MySensors Serial Gateway (v2.0)
Post by: mvdarend on October 15, 2016, 08:53:17 AM
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 (http://www.homegenie.it/forum/index.php?topic=1719.0)
Title: Re: MySensors Serial Gateway (v2.0)
Post by: raptorjr on October 15, 2016, 10:54:24 AM
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.
Title: Re: MySensors Serial Gateway (v2.0)
Post by: mvdarend on October 15, 2016, 11:28:02 AM
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
Title: Re: MySensors Serial Gateway (v2.0)
Post by: raptorjr on October 15, 2016, 12:10:11 PM
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.
Title: Re: MySensors Serial Gateway (v2.0)
Post by: mvdarend on October 15, 2016, 12:26:24 PM
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.


Title: Re: MySensors Serial Gateway (v2.0)
Post by: Orkspalter on October 15, 2016, 08:34:37 PM
Hi Marcel,

thank you for offering me your help with my problem setting up MySensors MQTT which i am still making no progress, i will pm you about that, thanks !!
The gateway i have built is the ESP8266 Mqtt gateway so i will not be able to use your new 2.0 sensors app but will you adapt it to the MQTT aswell ?

I am thinking of setting up a arduino nano and building a serial gateway just to try out your 2.0 app on my raspberry pi but mqtt is the way to go for me because all the options you have. Do you think it will work if having running a PI with both homegenie and node red on it, that both apps can use one serial gateway at the same time, using the same usb which it is connected ? As in node red, i can turn a serial gateway into mqtt and vice versa, so i could have a serial gateway in homegenie with your app and still having at the same time a mqtt gateway for using with node red?
Title: Re: MySensors Serial Gateway (v2.0)
Post by: mvdarend on October 15, 2016, 09:08:48 PM
Hi,

I'm not sure if you can create two connections to a single COM port, raptorjr managed to read the port with Cat while Domoticz was still connected to the port, so I imagine it shouldn't be a problem.

raptorjr also adapted my code to work with the MySensor Ethernet gateway, is that an option for you? MQTT messages are a lot different to the standard MySensor messages, I'm not sure if I can find the time to create/maintain another version.
Title: Re: MySensors Serial Gateway (v2.0)
Post by: raptorjr on October 16, 2016, 12:33:58 AM
I'm trying to experiment a little and make some changes to try and learn how HG and programs work. But doing this it seems that even though a program is not enabled, it still produces Popups?

If I restart my Arduino so it starts with presentation. Both the original gateway, by mvdarend, and my modified shows popups of added sensors, even though none of those two programs is enabled and running.

That can't be right?
Title: Re: MySensors Serial Gateway (v2.0)
Post by: mvdarend on October 16, 2016, 07:29:02 AM
No, that doesn't sound right. When I stop the Serial version, I get a 'Serial disconnected' popup (are you seeing that?), but I haven't noticed a 'Disconnected' with the Ethernet version, not sure why.

Is it possible that when you imported the program that you might have imported it more than once? Could you try checking all of the program groups to make sure that you don;t have a second instance hidden away and running?
Title: Re: MySensors Serial Gateway (v2.0)
Post by: mvdarend on October 16, 2016, 08:39:38 AM
OK, I think I've found the problem, I'm not sure, but I think that in your code the Instance of TcpHelper is not shutting down properly and an instance of the program keeps running in the background.

For me the following worked:

Remove line 31:
Code: [Select]
TcpClientHelper tcpConnection = new TcpClientHelper();
And then change all instances of tcpConnection, rename to TcpClient.

After that restart the HomeGenie service and the problem should be resolved.
Title: Re: MySensors Serial Gateway (v2.0)
Post by: mvdarend on October 16, 2016, 09:58:21 AM
I've combined the Serial en Ethernet connections into one app. You can now swtich between the two.

I've also created a few custom Sensor types for HomeGenie, to get these to display properly you'll have to edit the homegenie.generic.sensor widget (until I've found a proper solution) you can do this as follows:

- Configure -> Widgets
- open the homegenie.generic.sensor widget
- Click on the Javascript tab
- Scroll down to line 154 and change it to the following:
From this:
Code: [Select]
if (!ctx.isUnknown) {to this:
Code: [Select]
if (!ctx.isUnknown || parameter.Name.indexOf("Sensor.") >= 0 ) {- Actions -> Save

You can test it by clicking the Run/Preview button and binding to an existing module.
Title: Re: MySensors Serial Gateway (v2.0)
Post by: raptorjr on October 16, 2016, 11:26:14 AM
The gateway seems to work fine. (Although I think it looks better with default ip to be 127.0.0.1)

I changed the javascript code, but don't really know what change to look for?

But when talking about widgets. The water flow widget needs some changing, and I don't know if I need to create a completely new widget? As it is now it is always Off, and when I blow in my flow sensor to emulate a flow, the widget turns On when the total volume is > 0. Goes back to Off when I reset the total volume.

Eventually I need to find out how to make widgets and make a real water flow widget with both total volume and current water flow, but until then. Is there another widget that can be used to at least show the value from total volume?
Title: Re: MySensors Serial Gateway (v2.0)
Post by: mvdarend on October 16, 2016, 11:44:57 AM
I've changed the above example for changing the javascript code in the widget, it should be clearer now. Once you've modified it it should show the actual Flow value (if your using the latest version of the script)

Good catch on the default IP address, I'll change it.

One more thing, Widgets will often 'hold on' to old values, even if theyre no longer being used. By going to the parameters of the widget you can delete the old values. (Configure -> Groups -> Select group -> Select hamburger menu for widget) Delete any old values. (in your case Sensor.Generic, or Status.value i'm not sure which)

Title: Re: MySensors Serial Gateway (v2.0)
Post by: raptorjr on October 16, 2016, 12:20:49 PM
I'm using the version from your previous post. I removed all the modules (don't know if that is needed or if I can change a module manually, or if they get updated if I restart my MySensors node?)

When I added all again this is how my Water flow widget look now:

Title: Re: MySensors Serial Gateway (v2.0)
Post by: mvdarend on October 16, 2016, 03:16:58 PM
Have you also modified the widget in the widget editor?
Title: Re: MySensors Serial Gateway (v2.0)
Post by: raptorjr on October 16, 2016, 03:19:26 PM
Yes I have. Line 153-155 looks like this. Changed Line 154.

Code: [Select]
        var ctx = $$.ui.GetParameterContext($$.module, parameter.Name, parameter.Value);
        if (!ctx.isUnknown || parameter.Name.indexOf("Sensor.") >= 0) {
          var paramBox = $(paramTemplate);
Title: Re: MySensors Serial Gateway (v2.0)
Post by: mvdarend on October 16, 2016, 03:31:13 PM
Not sure what it could be, when editing and chaning a prgram (with widgets) in HG sometimes the widgets will start acting in strange ways, here's a few things you can check:

- In the parameters menu (Hamburger menu) of the widget do you see 'Sensor.Flow' in the list?
- Is the value of 'VirtualModule.ParentId' the same as the MySensors prgram Id?

If all else fails I usually remove all traces of the widget/module by doing the following:

- Stop the MySensor APP
- Remove all the MySensor widgets
- Remove all MySensor modules via 'Modules Cleanup'. (Only the actual widget modules, not the prpgram itself.)

Restart HOmeGenie and check to see no traces of the MySensor widgets are lef. Then try starting everything back up and add the widgets again.
Title: Re: MySensors Serial Gateway (v2.0)
Post by: raptorjr on October 17, 2016, 04:37:48 PM
Is it the gateway or HG that should take care of ACK from the node/sensor? Noticed yesterday that my relay didn't engage, and HG didn't care. Thought that it was on.
Feels like a important thing for on/off modules. But maybe no support for this in HG?
Title: Re: MySensors Serial Gateway (v2.0)
Post by: mvdarend on October 17, 2016, 04:42:44 PM
I haven't looked into ACK properly yet, after a quick read of the docs yesterday I think it works as follows:

ACK request from node: Handled by Gateway, if I have understood it correctly.

ACK request from HG: ACK response handled by HG, not yet implemented.
Title: Re: MySensors Serial Gateway (v2.0)
Post by: imedia on October 17, 2016, 10:39:34 PM
Hi.

I managed to install your mysensors code and I can see the notifications showing up with the serial data but I cannot add the module to the group it is not listed in the module list. There is no HomeAutomation.MySensors in the list.
Title: Re: MySensors Serial Gateway (v2.0)
Post by: raptorjr on October 17, 2016, 10:52:05 PM
Hi.

I managed to install your mysensors code and I can see the notifications showing up with the serial data but I cannot add the module to the group it is not listed in the module list. There is no HomeAutomation.MySensors in the list.


Just to make sure. You have restarted your MySensor node after the gateway is started? It is when it is started that it does the presentation to HG.

But I don't think you should see notifications with serial data, unless you have removed that comment from the code? You are using the version from post #35?

@mvdarend If possible to edit maybe the newest version and info should be in the first post?
Title: Re: MySensors Serial Gateway (v2.0)
Post by: mvdarend on October 18, 2016, 06:17:36 AM
Hi.

I managed to install your mysensors code and I can see the notifications showing up with the serial data but I cannot add the module to the group it is not listed in the module list. There is no HomeAutomation.MySensors in the list.
Hi imedia,

Besides the above, here are a few more thing you can check for:

- Is 'Inclusion Mode always on (True/False)' set to True?
- Is the device you're adding in the supported devices list?
- Does the info you're seeing in the Serial Data popups look like MySensor messages? If not, the Baud rate might be incorrect.

If that doesn;t help, could you post your sketch here so I can try it on my system?



Title: Re: MySensors Serial Gateway (v2.0)
Post by: mvdarend on October 18, 2016, 06:19:30 AM
@mvdarend If possible to edit maybe the newest version and info should be in the first post?

I'm thinking of starting a new thread for the combined Serial/Ethernet version to make it more clear for others. I just need to write it all up, I'll see if I can do that this evening.
Title: Re: MySensors Serial Gateway (v2.0)
Post by: mvdarend on October 18, 2016, 07:35:48 PM
Continues here: http://www.homegenie.it/forum/index.php?topic=1725.0 (http://www.homegenie.it/forum/index.php?topic=1725.0)
Title: Re: MySensors Serial Gateway (v2.0)
Post by: ealltech on November 25, 2016, 08:55:02 AM
Not sure if it could be a system on module (https://www.graperain.com/ARM-Embedded-System-On-Module/) kind of permissions issue, I'm running HomeGenie on a Windows machine and I don;t know very much about Linux. Is Domoticz still running on your RPi? Could it be blocking the COM port? (or some other program?)
I forgot to answer your last question, the code you uncommented earlier is the first line of code after a message has been received on the COM port, if that isn;t showing anything then there is no message being received.