more G-Labs products

Author Topic: MySensors via MQTT  (Read 14609 times)

July 07, 2015, 08:08:52 PM
Reply #15

gs001

  • *
  • Information
  • Newbie
  • Posts: 21
Thanks for all the work you've put into this.  It really opens up HomeGenie for inexpensive monitoring of lots of different sensor types.

Just one small issue I can't sort out. See below.

I'm running the MQTT MySensors program on my Rasp Pi HG setup, talking to an Arduino Uno MQTT Gateway via ethernet, and it consistently works well monitoring lightlux and Humidity/temp sensors using Pro Minis. I even put the humidity/temp sensor inside the freezer, and it's signal is relayed to the gateway via a Nano repeater (the metal walls of the freezer drastically attenuate the signal, so a repeater was necessary). One more freezer and refrigerator to go.

The issue I've run into is this - as long as I start the MySensors Gateway, _Then_ the MQTT MySensors program everything will start and continue to run with no issues.

However, If the Gateway goes offline, (for example if I yank the power to the gateway  to enroll a new sensor) the MQTT program silently fails, and no longer receives any information from the MySensors network. If I restart the program, everything again works normally.

I believe the problem is the program initially connects to the Gateway, and after that it doesn't subsequently check for connectivity. (I say I believe because my C# skills are non-existent. Based on my meager understanding of other programming languages I can sort of understand the flow of the program, but the syntax of C# might as well be Greek to me.) So, on disconnect the program hangs.

I've looked at the MQTT Network program in Interconnections, and I see some tests for connectivity, but again, the syntax escapes me.

Is there a way to have the MQTT MySensors program also test for connectivity?

Thanks,

Gary Sanders

July 08, 2015, 01:53:56 PM
Reply #16

mvdarend

  • *****
  • Information
  • Hero Member
  • Posts: 431
I'd noticed that too, but I haven't set up MySensors permanently yet so I haven't really looked into it.

I'm not sure as to go about it actually, maybe do a Ping every x minutes, and there is no reply reconnect?

July 09, 2015, 01:22:07 AM
Reply #17

gs001

  • *
  • Information
  • Newbie
  • Posts: 21
I don't believe a ping would do it, because even though the gateway would be disconnected from the HG computer, if it's powered up and connected to the LAN it could still reply to ping requests.

As I said earlier, there is code in the original MQTT program that appears to test for connectivity. However, with my limited understanding of C# I don't see (or understand) the mechanism to actually cause a reconnect.

July 09, 2015, 06:53:27 AM
Reply #18

mvdarend

  • *****
  • Information
  • Hero Member
  • Posts: 431
... if it's powered up and connected to the LAN it could still reply to ping requests.
Haha, how stupid of me... I should have put some more thought into that :-[

I'll have a look at the original code this weekend. I should have the gateway box printed up by then, it will be on permanently after that.

July 09, 2015, 10:04:10 PM
Reply #19

Qu3uk

  • *
  • Information
  • Newbie
  • Posts: 5
Is there any interest in having home genie support my sensors similar to how it supports zwave.. Built in? I'm waiting for my parts and thought I might try and give it a go. Although new to both hg and mys.

July 10, 2015, 11:15:21 AM
Reply #20

mvdarend

  • *****
  • Information
  • Hero Member
  • Posts: 431
Is there any interest in having home genie support my sensors similar to how it supports zwave.. Built in?
I would be very interested, I'd do it myself if I knew how to get started with something like that :)

The MySensors project is pretty cool, with a little DIY you can create all the sensors you need for a fraction of the price of store bought stuff.

July 10, 2015, 08:49:29 PM
Reply #21

gs001

  • *
  • Information
  • Newbie
  • Posts: 21
I'd definitely be interested. I have a couple of sensors running now, and I see an immediate need for a handful of others. Having built-in support would be ideal.

A quick tip on MySensors - When building the MQTT gateway, note that some of the I/O pins used to connect the NRF24L01+ radio are *ANALOG* pins, because the W5100 Ethernet board uses up so many Digital I/O pins. Also, there's a change to a config file needed to support the analog pin use.

It's all documented in the build instructions, and very straightforward, but really easy to overlook. It can cost several hours of frustration.  (Don't ask me how I know all this. It was a hard lesson on reading the instructions FIRST which, of course I normally don't do, being male and all).

Gary Sanders

July 11, 2015, 02:37:23 AM
Reply #22

Qu3uk

  • *
  • Information
  • Newbie
  • Posts: 5
Well I'm up for having a go and I'll see where I get to. As I said new to both projects and just got my MQTT Gateway working but not got as far as any sensors.. waiting for a few more parts to get off the breadboards.

I backed the ninjasphere and ever since that went bust I've been looking for a replacement. I think Home Genie is ace but I've not got any zwave or any other compatible things to really have a play with it and understand via trial and error.

 

July 31, 2015, 10:52:28 AM
Reply #23

swaner

  • *
  • Information
  • Newbie
  • Posts: 21
MySensors and homegenie sounds promising :). I noticed that there is an existing MQTT-broker addon built by Genie (https://github.com/genielabs/MIG-MqttBroker).

I don't know a thing about MQTT but if it is some sort of communication standard then maybe it should work straight out of the box? Or atleast be a good starting point to build an addon for homegenie?

August 03, 2015, 05:36:15 PM
Reply #24

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
I used Mosquitto MQTT as my broker since I found guides to help during setup.  I didn't know about the one Gene provided as an add-on.  If I hadn't gotten Mosquitto working, I'd just use his since it should work fine out of the box.

August 15, 2015, 09:58:27 PM
Reply #25

mvdarend

  • *****
  • Information
  • Hero Member
  • Posts: 431
I'm trying to extend the functionality of your APP to be able to send commands, but I'm having trouble getting it to work. 

With the following code I'm trying to send a command:
Code: [Select]
// - http://<hg_address>/api/MQTT:/MyMQTT/21/2/V LIGHT/1
When.WebServiceCallReceived("MQTT:", ( args ) => {
  try
  {
    // Hard coded command for testing
    MqttClient.Publish("MyMQTT/21/1/V_LIGHT", "1");         
    return "{ 'ResponseValue' : 'OK' }";   
  } catch (Exception e) {
    Program.Notify("MQTT ERROR!", e.Message);
  }
  return "{ 'ResponseValue' : 'ERROR' }";
});

The Message is arriving, so the "MyMQTT/21/1/V_LIGHT" is working fine, only the command itself "1" is not visible to the arduino.

Sending the same command with MQTTlens works fine, see screenshot.

I've tried all sorts of variations:
MqttClient.Publish("MyMQTT/21/1/V_LIGHT/", "1");
MqttClient.Publish("MyMQTT/21/1/V_LIGHT/1", "");
MqttClient.Publish("MyMQTT/21/1/V_LIGHT", "'1'");
MqttClient.Publish("MyMQTT/21/1/V_LIGHT", "\"1\"");

Can anyone help me in the right direction?

EDIT: Extra info: I'm running the RelayActuator example. Also uploaded correct screenshot.
« Last Edit: August 16, 2015, 10:00:50 AM by mvdarend »

August 18, 2015, 07:19:00 PM
Reply #26

mvdarend

  • *****
  • Information
  • Hero Member
  • Posts: 431
With WireShark I see a subtle difference in the message sen from MQTTLens and my above code from HomeGenie:
MQTTLens
Code: [Select]
0000   02 de ad 00 00 42 c8 f7 33 a4 79 87 08 00 45 00  .....B..3.y...E.
0010   00 40 24 48 40 00 80 06 54 33 c0 a8 00 02 c0 a8  .@[email protected]......
0020   00 ea 54 f6 07 5b 53 74 eb 49 27 43 ef 8c 50 18  ..T..[St.I'C..P.
0030   40 79 4c 24 00 00 30 16 00 13 4d 79 4d 51 54 54  @yL$..0...MyMQTT
0040   2f 32 31 2f 31 2f 56 5f 4c 49 47 48 54 31        /21/1/V_LIGHT1

As you can see, the HomeGenie version adds a '00 01' between the Topic and Message. Anyone know how to work around this?

HomeGenie
Code: [Select]
0000   02 de ad 00 00 42 c8 f7 33 a4 79 87 08 00 45 00  .....B..3.y...E.
0010   00 42 23 c8 40 00 80 06 54 b1 c0 a8 00 02 c0 a8  .B#[email protected].......
0020   00 ea 5c 8e 07 5b b7 16 40 1f 2a f4 dd 49 50 18  ..\..[..@.*..IP.
0030   40 df 97 3c 00 00 32 18 00 13 4d 79 4d 51 54 54  @..<..2...MyMQTT
0040   2f 32 31 2f 31 2f 56 5f 4c 49 47 48 54 00 01 31  /21/1/V_LIGHT..1

March 05, 2016, 06:06:39 AM
Reply #27

atideath

  • *
  • Information
  • Newbie
  • Posts: 2
Can you share your widget code? Thanks!

March 06, 2016, 08:01:11 AM
Reply #28

mvdarend

  • *****
  • Information
  • Hero Member
  • Posts: 431
Can you share your widget code? Thanks!
Do you mean the washing machine widget? (or something else)

If you want the washing machine widget I no longer have it. Using the homegenie/generic/status widget is a better option as it also works well with the Mobile Apps.

August 31, 2016, 08:46:21 PM
Reply #29

reza

  • *
  • Information
  • Newbie
  • Posts: 10
I'm interested in the widget you posted on the first message of this thread where it shows multiple parameters at the same time.  I've got a sensor zwave node and it cycles through the values.  I would rather them all show up at the same time like in your widget.