more G-Labs products

Author Topic: MySensors v2.0 Serial/Ethernet Gateway  (Read 2895 times)

November 07, 2016, 10:13:21 AM
Reply #15

raptorjr

  • ***
  • Information
  • Full Member
  • Posts: 78
You point me in the good direction  :) Thanks a lot !

I succeed switch on/off my several color, by doing this modifications :

--> Add my type :

Code: [Select]
       
case 4: // V_DIMMER, V_PERCENTAGE
        hgSubType = "Status.Level"; // status.percentage?
        break;

--> Update severals value by * 100 :

Code: [Select]
setValue = "100"; /////
Code: [Select]
{setValue = "100";}
Code: [Select]
setValue = (100 * Convert.ToInt32(reqs[3])).ToString();
--> Changing the send of the command to use serial instead network :

Code: [Select]
TcpClient.SendMessage(theCommand);Replace by
Code: [Select]
SerialPort.SendMessage(theCommand);
--> Changing the send of the command to use serial instead network :

Replace this :
Code: [Select]
subType = 2; //V_STATUS, V_LIGHTby this :
Code: [Select]
subType = 3; //V_DIMMER
########################################
The ToDo to this program :
  • Status update of the level in HG
  • Manage set command by serial or network gateway
  • Manage SubType more global

I don't know what the standard for dimmer values are, if all/most dimmers use 0-1 or 0-100? But otherwise maybe better to change your sketch to handle the conversion?
So that more users can use your updated program, and not everyone need to change the values for their usage.

November 07, 2016, 10:53:09 PM
Reply #16

nolio

  • *****
  • Information
  • Global Moderator
  • Posts: 544
raptorjr, my MySensors script do something like this :
Code: [Select]
255 * gw.loadState(RED) / 100But it's a generic sketch ...

I do the change in the following script but if in your case : "switch", it doesn't work. I can manage the 2 case.
Can you test with this new one please?

November 07, 2016, 11:25:04 PM
Reply #17

raptorjr

  • ***
  • Information
  • Full Member
  • Posts: 78
raptorjr, my MySensors script do something like this :
Code: [Select]
255 * gw.loadState(RED) / 100But it's a generic sketch ...

I do the change in the following script but if in your case : "switch", it doesn't work. I can manage the 2 case.
Can you test with this new one please?

I don't have a dimmer, sorry if I was unclear. Just thought that since you seem to know a little about programming, and mvdarend is leaving HG, it would be nice if your changes was generic so everyone could use the things you added.

But as I said, don't know what ranges that are most common, 0-1 or 0-99?

I will use the MySensors gateway a lot, but at the moment I'm about to move, so all fun electronic projects have been put on hold for a while. But I hope that when the time comes that I can help to debug and test the gateway, and maybe come up with suggestions and add code also.

November 08, 2016, 08:30:13 PM
Reply #18

raptorjr

  • ***
  • Information
  • Full Member
  • Posts: 78
@nolio

I'm no expert, but when you use f.ex. setValue = "100" for Control.On and Control.Toggle, it feels like your hardcoding things to work with your dimmer? And it wont work with normal light switches or relays? Maybe better to adjust your sketch? 0 and 1 seems more logical for On/Off than 0/100.

I don't know if you are interested in getting a working MySensors gateway or if you just are modifying things to work in your environment? Last option is fine. I'm just looking for someone with the right knowledge to take over after mvdarend =) I'm not at that level yet, but would like to be in the future. But in the meantime we need someone with other MySensor nodes and some developer skills that could help and improve the gateway.

I only have one node with temp, relay and waterflow sensor. So that is the only things I can test at the moment.

November 08, 2016, 11:11:26 PM
Reply #19

nolio

  • *****
  • Information
  • Global Moderator
  • Posts: 544
I'm no expert, but when you use f.ex. setValue = "100" for Control.On and Control.Toggle, it feels like your hardcoding things to work with your dimmer? And it wont work with normal light switches or relays? Maybe better to adjust your sketch? 0 and 1 seems more logical for On/Off than 0/100.
I think my method is the good way and no one seams test that ... But perhaps, i do a mistake. So if someone test and comeback with a problem, i can correct that.
I don't know if you are interested in getting a working MySensors gateway or if you just are modifying things to work in your environment? Last option is fine. I'm just looking for someone with the right knowledge to take over after mvdarend =) I'm not at that level yet, but would like to be in the future. But in the meantime we need someone with other MySensor nodes and some developer skills that could help and improve the gateway.
I am interest for the both ;) but i am ok with you : First (work for everybody). I already post some HG program on other point in this target :)
I only have one node with temp, relay and waterflow sensor. So that is the only things I can test at the moment.
Ok that's a good point to know. On my side
  • 2 working node : RGBW + TeleInfo
  • Node to implement : Motion / Gas / InfraRed (for now IR with LIRC on raspberry pi seams easier to manager)

November 08, 2016, 11:37:41 PM
Reply #20

raptorjr

  • ***
  • Information
  • Full Member
  • Posts: 78
I'm no expert, but when you use f.ex. setValue = "100" for Control.On and Control.Toggle, it feels like your hardcoding things to work with your dimmer? And it wont work with normal light switches or relays? Maybe better to adjust your sketch? 0 and 1 seems more logical for On/Off than 0/100.
I think my method is the good way and no one seams test that ... But perhaps, i do a mistake. So if someone test and comeback with a problem, i can correct that.

If you look at the MySensors protocol https://www.mysensors.org/download/serial_api_20 they use 0/1 for On/Off for V_STATUS, V_LIGHT. And if this should be some kind of official MySensor gateway for HG maybe it would be smart and try to follow the protocol? Maybe less problem in the future if more user would like to test MySensors and HG.

November 09, 2016, 09:39:21 PM
Reply #21

nolio

  • *****
  • Information
  • Global Moderator
  • Posts: 544
I add the compatibility to the 2 set command :
  • V_STATUS  / 2 / Binary status. 0=off 1=on    / S_LIGHT, S_DIMMER, S_SPRINKLER, S_HVAC, S_HEATER
  • V_PERCENTAGE / 3 / / Percentage value. 0-100 (%) / S_DIMMER
by this type of code :
Code: [Select]
         
if (module.IsOfDeviceType("Switch")) {setValue = "1";} //V_STATUS, V_LIGHT
if (module.IsOfDeviceType("Dimmer")) {setValue = "100";} //V_DIMMER
So it's more adaptable :)

Program pull request on github : https://github.com/genielabs/homegenie-packages

November 09, 2016, 11:02:45 PM
Reply #22

raptorjr

  • ***
  • Information
  • Full Member
  • Posts: 78
Yes, would be nice with this included as a package.

But there is another place where SendMessage is used (line 296) that only use TcpClient and not the SerialPort. Suggest that the switch for Tcp or Serial Send message is moved to it's own function so it is easier to use anywhere in the code and no need to do the switch statement every time.