more G-Labs products

Author Topic: MQTT Broker  (Read 12192 times)

June 11, 2015, 10:51:19 PM
Reply #30

sintei

  • *
  • Information
  • Newbie
  • Posts: 8
OK, so I got HG to recognize the incoming messages and also make the switches in my lights based on what I published.
I know it is probably very simple for you guys, but I do not know programming language and really have to learn the hard way.
Anyways, here is a snippet of code on how I got it to work.
The module is named lounge (my zwave switch)
I publish "loungeON" or respective "loungeOFF" on the topic "MyMQTT/" (standard by importing CPTjacks scripts)

Net.Subscribe(topic, (mtopic, mpayload) => {
var zwave1 = Modules.WithName("lounge");
if (mpayload == "loungeON")
{
zwave1.On();
return;
}
if (mpayload == "loungeOFF")
{
zwave1.Off();
return;
}

Hope it helps any beginners like me.

June 11, 2015, 11:36:44 PM
Reply #31

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
Yup, that's pretty much all that you need.  Glad you got it working!

September 25, 2015, 09:04:11 PM
Reply #32

jjennings308

  • *
  • Information
  • Newbie
  • Posts: 9
I am new to MQTT.  Is it possible to send a message for a dimmer signal?  I have MQTT working between two HG units and Off and ON will work, but the dimmer signal from the remote unit has no effect on the local unit.

January 13, 2017, 10:36:57 PM
Reply #33

djatie

  • **
  • Information
  • Jr. Member
  • Posts: 34
sory this stupid question, im new mqtt user too.

is this mqtt broker on hg just for connecting 2 HG box? or i can do more? cos i just see on sytem setting just show mqtt port, no other setting.

i have one esp8266, i have flash with some scrip were it can control relay to on off.
i must log to esp8266 wifi then go to tiny web server on this esp8266, than manual on/off it from there.

i have plan to control it with HG,
if i want to do that, i must install mosquito mqtt broker on my raspi, then modificate some script on esp8266 to send receive payload with mqtt , over same wifi.

then make some script on hg were it will cek esp8266 status or send command to on off gpio.

its true like wat i think or i have another option to do that.
pls need guide, and sample. thanks before

:D


January 13, 2017, 10:43:52 PM
Reply #34

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
HG can be triggered by MQTT messages if you set up code to do it. I have a script that watches for weather and power info and adds the data to the statistics monitor so I can track those items from HG. It would be possible to trigger events based on MQTT packets if you want.

I use Mosquitto, but the one Gene built in will work just fine. You don't have to install an external broker.

January 14, 2017, 02:44:00 PM
Reply #35

djatie

  • **
  • Information
  • Jr. Member
  • Posts: 34
Nice share pls  ;D


January 19, 2017, 06:43:49 PM
Reply #37

djatie

  • **
  • Information
  • Jr. Member
  • Posts: 34
i activate original mqtt network from hg.
try to use demo model were it publish with mqtt

on android phone i use app mqtt iot to see what message publish.
its show like the attachement.

hem..
surrender for this cool facility :(
hahahaha dont understand how to use this

January 19, 2017, 07:43:04 PM
Reply #38

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
that format is used for HG to communicate with other HG boxes. If you want to use MQTT for tour own purposes, look at my code and see how I set it up. It's basically a modified version of the old built in HG example code but allows me to send data from sensors to my HG box. That data can be used for tracking of to perform actions.

If I had a light sensor in a room and a set of motorized shades, it would be really easy to make the shades open/close depending on sun light.

January 19, 2017, 09:59:14 PM
Reply #39

raptorjr

  • ***
  • Information
  • Full Member
  • Posts: 78
Excuse me for asking a stupid question. What are the benefits of using MQTT?

January 19, 2017, 11:07:34 PM
Reply #40

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
MQTT is just a transport protocol that allows you to transmit from one system without worrying about who's currently listening. On the other end, anot her system(s) can be listening without worrying if anyone is sending. The only real requirement is that the broker is alive. How/if you implement it into a specific design is up to you. It's a nice option if you can't trust a communications IMO because the sender and receiver don't rely on each other so if a message gets lost or one goes down it won't kill/hang the other.

You can do some reading for other uses, but I think it's really useful for sensor communication.

January 23, 2017, 10:09:01 PM
Reply #41

djatie

  • **
  • Information
  • Jr. Member
  • Posts: 34
DONE now i can on off my gpio use mqtt client.

Any one have sucsess integrating sonoff with homegenie?
« Last Edit: January 23, 2017, 10:21:47 PM by djatie »

January 23, 2017, 11:43:13 PM
Reply #42

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
sonoff is based on ESP8266 meaning WiFi. I'd imagine the that you'd need to call a URL from HG to turn on/off the module. I haven't looked into these, but there were a couple threads I was watching at the X10 forum about them.