MQTT Broker gateway



  • @celonunes actually, i figured a way around it using mosquitto bridge
    that way its much more robust too, so I am good 🙂
    can post my conf if anyone interested.


  • Code Contributor

    Those are the most recent changes to MQTT gateway:

    • Fixed node id distribution by the gateway (reported by @viking)
    • Fixed the problem with openhab and multiple MQTT clients
    • Fixed the appearance of garbage in messages sent from MQTT to a node


  • I can't change on-off manually for button with relay sketch, if i try, connection is lost, switching from screen never works again until restart everything.

    2015-03-05 15:51:29.200 [INFO ] [runtime.busevents ] - node2_sw2 received command OFF
    2015-03-05 15:51:32.624 [INFO ] [runtime.busevents ] - node2_sw2 received command ON

    Openhab 1.6.2 or 1.7.0 same result.

    **My main problem is losing connections with nodes. I also tried serial binding and same result.
    **
    Mysensors+Openhab useless with mqtt and also serial binding


  • Code Contributor

    @C.r.a.z.y. Could you send the serial output from the gateway? And a more complete log from openhab showing errors?


  • Admin

    @C.r.a.z.y. said:

    I can't change on-off manually for button with relay sketch, if i try, connection is lost, switching from screen never works again until restart everything.

    Are you sure it isn't a powering issue of the "button-node" where radio shuts down when you press the button? Are you controlling a physical relay?



  • @celonunes You can find MQTT and serial logs in the zip files openhab 1.6.2 and 1.7.0 logs-1.7.0.zip logs-1.6.2.zip

    @hek My nodes are working perfect when i only plug serial usb to any usb socket of a computer-printer-usb hub even a mobile phone charger 🙂 they are good without server/controller



  • @hek My relay powered from nano icp headers maybe this makes trouble for wifi , i will change this and give update.

    My button is not normal button , its an ir distance sensor which trigers the relay.



  • I can't seem to get openhab to communicate with my MQTT gateway. I can connect to the gateway with the MyMQTT Android app and I receive messages from my light sensor node including the sketch name and light level. I can ping my gateway without issue as well.

    However, OpenHab never seems like it notices the gateway. No data in the sketch name or node result. I've used the sitemap, items, and config files as described above and I've also customized them to match my sensor node more specifically. Both without success. The only change I've made is my sensor node is defined as node ID 20 within it's sketch.

    When using start_Debug.bat what should I see in the command line window to indicate OpenHab even sees or connects to the gateway. I see no indication that it attempts to connect to the IP address of my gateway.

    Thanks



  • Maybe if you can share your items, sitemap, and rules if any.





  • can you also please paste a sample of what you see in myMQTT or screenshot maybe? or it can be easier to copy and paste from a terminal window? are you using raspberry pi or something else?



  • @hooraysimpsons unplug the power and restart your modem, check your dhcp menu if it has ip for Ardiuno.

    Check your mqtt from serial monitor, you must see "gateway started..."



  • mosquitto_sub -h localhost -v -t '#'
    This is what i use to see what is happening on mqtt broker, i am using a raspberry pi and mosquitto installed on the same pi. you can also swap localhost for ip address ie 192.168.0.5 etc



  • @C.r.a.z.y. it sounds like he is getting as far as the mqtt broker, so the gateway must be working. ?



  • Crazy- I was thinking my network connection as a source of the problem. On my router homepage the gateway does not show up as being given an IP. However, the MyMQTT Android App sees the gateway without issue so the routing across my network from phone to gateway is successful. I have attached a screenshot of the MyMQTT andoird app output.

    2015-03-08 14.55.12.png

    I am trying to run OpenHab on a windows PC. I don't have mosquitto running at all. My understanding is that it is not required.



  • Group all
    Group node1 (all)
    Group node2 (all)
    Group sketch (all)

     Number node1_light  "Light Level"     (node1,all)  {mqtt="<[mysensor:MyMQTT/20/0/V_LIGHT_LEVEL:state:default]"}
    

    Try changing the first line of items like this above.. and in sitemap change node1_temp to node1_light

    Also see if activating any of the switches in openhab publishes to myMQTT ?



  • Restarting the modem and checking wires of arduino solved my problem before.
    I am sure mqtt have to be in dhcp list.



  • I have restarted my router with no effect. The gateway still does not show up as an active client (using DDWRT) but I still have a connection from phone to gateway.

    Added the above line. I've used one before like it but went back to what was given at the beggining of this thread to start anew. I also tried with the following edits
    "Light Level"
    "Light Level [%s]"
    "Light Level [%.1f]"

    None of which make a difference. The reason I think OpenHab doesn't even see the gateway is because nothing shows up in sketch name either which should work even if the above line was incorrect.

    I have done the testing with the Android App turned off as well since I know OpenHab had some issues earlier if other clients were accessing the gateway.

    I still see no reference to my gateway's IP in any of the OpenHab output/logs. So I'm not sure it is even trying.

    The only error message in my openhab log is:
    11:23:46.951 [ERROR] [sphere.cpr.AtmosphereFramework:2215 ] -

    I tried clearing the EEPROM in the gateway. I changed it's Mac address and removed the DHCP lease for it from my router. Still no evidence of the gateway on my router status page but also still able to connect to it with my phone.

    Another update:
    I installed Mosquitto and I see the light sensor level using mosquitto_sub -h 192.168.1.134 -t MyMQTT


  • Code Contributor

    @hooraysimpsons Your gateway seems to be working fine. Do you see something like this on your openhab logs?

    2015-02-27 17:48:06.349 [INFO ] [.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
    2015-02-27 17:48:06.350 [INFO ] [o.i.t.m.i.MqttBrokerConnection] - Starting MQTT broker connection 'mysensor'
    


  • @celonunes Nope. I figured it out. In my openhab config file there was space prior to my MQTT related lines

    " mqtt:mysensor.url=tcp://192.168.1.134:1883"
    " mqtt:mysensor.clientId=OpenhabMQTT"
    Instead of
    "mqtt:mysensor.url=tcp://192.168.1.134:1883"
    "mqtt:mysensor.clientId=OpenhabMQTT"

    Removed the space and now I get my light sensor output value. I still don't get the sketch name coming through but I'll look into that later.



  • @celonunes @hek
    I installed this https://github.com/lurch/rpi-serial-console
    pi@raspberrypi ~ $ rpi-serial-console status
    Serial console on /dev/ttyAMA0 is disabled

    Now my nodes are working perfect when i use manual button or ui but my logs are not correct

    My config:

    add on : org.openhab.binding.serial_1.6.0.201411271703.jar
    String Arduino "Arduino" { serial="/dev/ttyUSB0" }

    As you see there are "fails" but nodes are working.

    015-03-09 12:37:51.725 [INFO ] [runtime.busevents ] - Arduino state updated to 0;0;3;0;9;send: 0-0-52-52 s=1,c=1,t=2,pt=0,l=1,st=fail:1

    2015-03-09 12:37:56.726 [INFO ] [runtime.busevents ] - Arduino state updated to 0;0;3;0;9;read: 52-52-0 s=255,c=0,t=18,pt=0,l=5:1.4.1
    52;255;0;0;18;1.4.1
    0;0;3;0;9;read: 52-52-0 s=255,c=3,t=6,pt=1,l=1:0
    52;255;3;0;6;0

    2015-03-09 12:37:58.768 [INFO ] [runtime.busevents ] - Arduino state updated to 0;0;3;0;9;read: 52-52-0 s=255,c=3,t=11,pt=0,l=14:Relay & Button
    52;255;3;0;11;Relay & Button
    0;0;3;0;9;read: 52-52-0 s=255,c=3,t=12,pt=0,l=3:1.0
    52;255;3;0;12;1.0
    0;0;3;0;9;read: 52-52-0 s=1,c=0,t=3,pt=0,l=5:1.4.1
    52;1;0;0;3;1.4.1
    0;0;3;0;9;read: 52-52-0 s=2,c=0,t=3,pt=0,l=5:1.4.1
    52;2;0;0;3;1.4.1

    2015-03-09 12:37:59.700 [INFO ] [runtime.busevents ] - S2 received command ON
    2015-03-09 12:37:59.822 [INFO ] [runtime.busevents ] - Arduino received command 52;1;1;0;2;0

    2015-03-09 12:38:00.106 [INFO ] [runtime.busevents ] - Arduino state updated to 0;0;3;0;9;send: 0-0-52-52 s=1,c=1,t=2,pt=0,l=1,st=fail:0

    2015-03-09 12:38:00.546 [INFO ] [runtime.busevents ] - S2 received command OFF
    2015-03-09 12:38:00.661 [INFO ] [runtime.busevents ] - Arduino received command 52;1;1;0;2;1

    2015-03-09 12:38:00.967 [INFO ] [runtime.busevents ] - Arduino state updated to 0;0;3;0;9;send: 0-0-52-52 s=1,c=1,t=2,pt=0,l=1,st=fail:1

    2015-03-09 12:38:01.161 [INFO ] [runtime.busevents ] - S2 received command ON
    2015-03-09 12:38:01.339 [INFO ] [runtime.busevents ] - Arduino received command 52;1;1;0;2;0

    2015-03-09 12:38:01.649 [INFO ] [runtime.busevents ] - Arduino state updated to 0;0;3;0;9;send: 0-0-52-52 s=1,c=1,t=2,pt=0,l=1,st=fail:0

    2015-03-09 12:38:01.782 [INFO ] [runtime.busevents ] - S2 received command OFF
    2015-03-09 12:38:01.894 [INFO ] [runtime.busevents ] - Arduino received command 52;1;1;0;2;1

    2015-03-09 12:38:02.076 [INFO ] [runtime.busevents ] - Arduino state updated to 0;0;3;0;9;send: 0-0-52-52 s=1,c=1,t=2,pt=0,l=1,st=fail:1



  • Just want to make sure I'm understanding this correctly since I feel the MQTT terminology is new to me.

    The MQTT Broker is the MQTT server so if I wanted to use this with openhab on a pi I would just need the MQTT plugin and then point it to the IP of the gateway?

    I have the ethernet module ordered so I can't test myself yet.


  • Code Contributor

    @C.r.a.z.y. You are using the raspberry serial port to connect the openhab with the arduino and the arduino is running the SerialGateway sketch, is that right?


  • Code Contributor

    @Chaotic said:

    The MQTT Broker is the MQTT server so if I wanted to use this with openhab on a pi I would just need the MQTT plugin and then point it to the IP of the gateway?

    That's right.



  • I have ENC28J60-I/SO connected by ethernetcable to my Asus RT-n66u in LAN 4. But It will not show up in my router... On my ENC28J60 there is a red light on D1 and the ethernet port has a green light and a yellow flashing light.

    Serial monitor says "
    Started!
    0;0;3;0;9;read: 20-20-0 s=255,c=0,t=17,pt=0,l=5:1.4.1
    0;0;3;0;9;read: 20-20-0 s=255,c=3,t=6,pt=1,l=1:0
    0;0;3;0;9;send: 0-0-20-20 s=255,c=3,t=6,pt=0,l=1,st=ok:M
    0;0;3;0;9;read: 20-20-0 s=255,c=3,t=11,pt=0,l=18:Temperature Sensor
    0;0;3;0;9;read: 20-20-0 s=255,c=3,t=12,pt=0,l=3:1.0

    . But nothing more. I have followed the MQTT gateway guide and set an static ip in the sketch.. DHCP is on in my router.

    The only thing I see in my router is : That the cable is connected to something and that its 10 Half duplex.

    I have also tried to connect it to other LAN ports but no difference

    What could be wrong?


  • Code Contributor

    @msebbe Did you try to ping the gateway static IP?



  • @celonunes

    Yes, both from windows cmd and from the router ui with this result:

    PING 192.168.1.197 (192.168.1.197): 56 data bytes

    --- 192.168.1.197 ping statistics ---
    5 packets transmitted, 0 packets received, 100% packet loss

    Could be that I have not changed the MAC adress cause I tried to figure out how to do it but I dont understand this part from the MQTT gateway sketch:

    *1 -> NOTE: Keep first byte at x2, x6, xA or xE (replace x with any hex value) for using Local Ranges.

     #define TCP_PORT 1883						// Set your MQTT Broker Listening port.
     IPAddress TCP_IP ( 192, 168, 1, 197 );				// Configure your static ip-address here
     uint8_t TCP_MAC[] = { 0x02, 0xDE, 0xAD, 0x00, 0x00, 0x42 };	// Mac-address - You should change this! see note *2 above!

  • Code Contributor

    @msebbe Which library your are using for the ENC28J60? The UIPEthernet has some examples you could try to test if your module is working.



  • @celonunes
    Just wanted to say I was able to get this working.

    Also found a nice little MQTT utility that makes it easy to see the messages being sent from the broker/openhab.

    I'm sure I'll have more questions but most of my hardware is still on a boat from china so will be a little while till I discover them.



  • @celonunes In the Mqtt broker sketch, Ethernet.h was included. I suppose it should be UIPEthernet.h for me? So I tried that but nothing.

    I had better luck with the UIPEthernet examples, there my arduino shows up with an ip and mac adress.. Hmmm.

    edit:

    So after using UIPEthernet "Advanced chat server" sketch, the MAC and IP showed up in my router. When I then tried with the MQTT sketch with UIPEthernet.h it would not work. So then I tried to copy the MAC and IP I used in the chat server sketch into the Mqtt sketch and bom! I can now ping it, so I guess it works now?

    edit2: Should it say anything more then "Started!" on serial monitor? Like "on ip 192.168.1.197" or something like that? Since Im now trying the MQTT in pidome as I know how to use pidome better. Pidome states;
    Connected: Yes, with 192.168.1.197:1883 at topic: MyMQTT/# (without subscribe promise)
    Last receive time: 00-00-0000 00:00
    Last send time: 00-00-0000 00:00

    This is what Serial monitor says http://i61.tinypic.com/i252kn.png

    But when I use device discovery it cannot find the temperature sensor that could be found using the serial gateway 😕



  • Hi everyone,

    Finally got this working but had a couple of quetions

    Does the MQTT Broker gateway not handle requests for time? I currently have a node that I'm using as an alarm clock which has a RTC module. I had hoped to be able to update the time via the gateway and polling the time from one of my computers which are connected to NTP servers but the message never seems to get put on a MQTT message so I can't have a computer respond to it.


  • Code Contributor

    @msebbe It doesn't print your ip, those numbers after "Started!" is related to mqtt packages showing that PiDome is connected.
    For the device discovery, there are probably a lot of other people who can help you with that because I don't know much about PiDome.


  • Code Contributor

    @Chaotic MQTT Broker gateway doesn't handle time requests.



  • @celonunes Ok, thanks! I got the discovery working by just rebuilding the same sensor from scratch!

    Sorry for so many questions.. But I have now changed to Openhab and got it working with my MQTT gateway. Now Another problem appear:

    http://i60.tinypic.com/2d2eqzk.png[/IMG

    I would like to display the temperature in °C like in your guide sketch (wich I am using) but instead it looks like in the picture. Same thing about humidity, why is it like this?

    Edit: For anyone wondering, I solved the issue with the degree symbol not showing up properly by replacing "°C" with "& deg;C" without space between & deg



  • Hi Folks,

    New to mysensors and am impressed. I've been playing with OpenHAB and MQTT so this sounds like an interesting project. My question though, which might have been answered but I'm finding it hard to find the answer, is - is this bidirectional? As in if I had a 'sensor' on the Arduino network and that went over the radio network, hit the gateway and then got picked up by OpenHAB, could I then, if I had a 'actuator' or a 'do-er' node on the network, send a message to MQTT from OpenHAB to change the status of that actuator device? So for instance to start a motor controlling blinds for instance? Or is it a read only system?

    Thanks



  • @Brett-Jenkins

    It works both ways.



  • Thanks 🙂



  • How can I implement MQTT for MQ-2 Gas sensor the correct way? In the mysensor sketch there is only one child ID and one V_VAR1 but 3 different outputs: LPG, CO and Smoke? I'm only receiving CO value and not all 3 in openhab.



  • @kunall There is V_VAR1-5 actually

    V_VAR1	24	Custom value
    V_VAR2	25	Custom value
    V_VAR3	26	Custom value
    V_VAR4	27	Custom value
    V_VAR5	28	Custom value
    

    Personally I would set up each value you want as a S_CUSTOM if you can't figure out another sensor type that fits.

    For smoke you can use S_SMOKE
    For Air Quality S_AIR_QUALITY
    Not sure what you'd want to use for CO2 through

    http://www.mysensors.org/download/serial_api_14



  • @Chaotic Thanks! I will try this and get back with result.



  • @Damme
    how to run MySensors ( MQTT gateway) on the arduino due + Wiznet5100 + NRf24l01?
    Get the error:

    Arduino: 1.5.8 (Windows 8), Board: "Arduino Due (Programming Port)"
    
    In file included from Z:\arduino-1.5.8-new\libraries\DigitalIO/DigitalIO.h:31:0,
                     from EthernetGateway.ino:41:
    Z:\arduino-1.5.8-new\libraries\DigitalIO/DigitalPin.h:30:20: fatal error: avr/io.h: No such file or directory
     #include <avr/io.h>
                        ^
    compilation terminated.
    Ошибка компиляции.
    
      This report would have more information with
      "Show verbose output during compilation"
      enabled in File > Preferences.
    
    
    


  • @hooraysimpsons this solved my problem too! Everything else in my setup was a quick job but problem solving this issue took half a day. It should be more widely circulated..



  • Hi guys,

    I dind´t read all comments so I hope this wasn´t answered before: I would like to know how to setup an arduino + NRF24L01 Node:

    • how to initialize the node
    • what should the Arduino sketch look like to start MQTT

    Thanks for your help!!



  • Ok,forget my last post, I have a new problem:

    When I uplaod the EthernetGW Sketch to my arduino nano I can see MQTT messages coming in from one node int the arduino serial monitor. So now I uploaded the MQTTGW sketch to my nano because I would like to use openhab. But after uploading the sketch all info I get from serial monitor is "Started!", nothing else is showing up.
    I can still ping the MQTT gateway but it seems like it´s not receiving any mqtt message, at least no the state of my node. Could you please help and support me here? Thanks in advance!



  • nobody experiencing this problem? Any idea how I could start fixing this? Pls help!



  • Hello,

    I have made this gateway with W5100.
    Everything looks OK, except random connection failures.
    Clients - MyMQTT (android), Openhab are loosing contact with the broker time after time.
    The issue can occur every 5 - 60 mins.

    Any ideas what could be the problem?

    Thank you in advance.



  • Hi,

    Was hoping someone could help a MQTT and openHab newb here. i have Openhab configured and running with Phillips Hue and Wemo, and trying to integrate MySensors. I build the 1.5 version MQTT gateway using the W5100 module, and all is working (can ping the gateway noproblem, and receiving data from a sensor). The problem is, i'm not sure how to add the line into the items and sitemap file....

    Here is the output that I am getting from the MQTT serial monitor. The sensor I have connected is a 3-in-1 with motion PIR, and DHT22 temp/humid and a hard configured Node_ID of 3 (or, should be).

    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=1,c=1,t=0,pt=7,l=5,sg=0:23.3
    0;0;3;0;9;read: 1-1-0 s=0,c=1,t=1,pt=7,l=5,sg=0:44.1
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=1,c=1,t=0,pt=7,l=5,sg=0:23.2
    0;0;3;0;9;read: 1-1-0 s=0,c=1,t=1,pt=7,l=5,sg=0:44.0
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=0,c=1,t=1,pt=7,l=5,sg=0:43.9
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=0,c=1,t=1,pt=7,l=5,sg=0:44.0
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=1,c=1,t=0,pt=7,l=5,sg=0:23.3
    0;0;3;0;9;read: 1-1-0 s=0,c=1,t=1,pt=7,l=5,sg=0:44.1
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=1,c=1,t=0,pt=7,l=5,sg=0:23.2
    0;0;3;0;9;read: 1-1-0 s=0,c=1,t=1,pt=7,l=5,sg=0:43.9
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=1,c=1,t=0,pt=7,l=5,sg=0:23.3
    0;0;3;0;9;read: 1-1-0 s=0,c=1,t=1,pt=7,l=5,sg=0:44.0
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=0,c=1,t=1,pt=7,l=5,sg=0:44.1
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=0,c=1,t=1,pt=7,l=5,sg=0:44.0
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=0,c=1,t=1,pt=7,l=5,sg=0:44.1
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=0,c=1,t=1,pt=7,l=5,sg=0:44.0
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=0,c=1,t=1,pt=7,l=5,sg=0:44.1
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=0,c=1,t=1,pt=7,l=5,sg=0:44.0
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=0,c=1,t=1,pt=7,l=5,sg=0:44.1
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=0,c=1,t=1,pt=7,l=5,sg=0:44.0
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=0,c=1,t=1,pt=7,l=5,sg=0:44.1
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=0,c=1,t=1,pt=7,l=5,sg=0:44.0
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=1,c=1,t=0,pt=7,l=5,sg=0:23.4
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
    

    Can someone help me get the information to display in OpenHab? Please.



  • Contact contact_99        "Contact node 99 sensor 3: [MAP(de.map):%s]"        { mqtt="<[mysensors:sensor-gw1-out/99/3/1/0/16:state:MAP(mqttToCloseOpen.map)]" }
    

    this is an item which
    reads a message from mqtt broker:

    • < input, reads message
    • mysensors => mqtt connection as decribes in opnehab.cfg
    • sensor-gw1-out => topics as configured in your mqtt gateway sketch
    • 99/3/1/0/16 have a look at serial api: node 99, child 3 etc

    I found it very helpful to subscribe myself to the mqtt broker and read the incoming messages there



  • Hi @dakky

    Thanks for the help. So far, I can get my temperature and humidity to update, but I cannot get my motion sensor on the same node to update at all.

    Here are the lines I have in default.items

    /* MySensors MQTT */
    Number		node1_temp					"Temp [%.1f °C]"     						(node1)		{mqtt="<[mysensor:MyMQTT/1/1/V_TEMP:state:default]"}
    Number		node1_humid					"Humid [%.1f %%Rh]" 						(node1)		{mqtt="<[mysensor:MyMQTT/1/0/V_HUM:state:default]"}
    Contact 	node1_motion        		"Motion Sensor 3: [MAP(1on0off.map):%s]"     (node1)	{ mqtt="<[mysensors:MyMQTT/1/2/V_TRIPPED:state:MAP(1on0off.map)]" }
    

    And here is my default.sitemap file

    Frame label="Sensor Data" {
            Text label="Sensors" icon="mysensors" {
    		Group item=node1 label="Man Cave Climate" icon="temperature" 
    		Chart item=node1_humid period=W refresh=10000
    		}
    

    And finally, this is what I am reading from screen when the message appear on the MQTT broker sketch. The node_id is 1, not 3 like I originally though.

    >>30 17 00 14 4D 79 4D 51 54 54 2F 31 2F 32 2F 56 5F 54 52 49 50 50 45 44 30
    0;0;3;0;9;read: 1-1-0 s=0,c=1,t=1,pt=7,l=5,sg=0:47.1
                                                        MyMQTT/1/0/V_HUM
    >>30 16 00 10 4D 79 4D 51 54 54 2F 31 2F 30 2F 56 5F 48 55 4D 34 37 2E 31
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
                                                      MyMQTT/1/2/V_TRIPPED
    >>30 17 00 14 4D 79 4D 51 54 54 2F 31 2F 32 2F 56 5F 54 52 49 50 50 45 44 30
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
                                                      MyMQTT/1/2/V_TRIPPED
    >>30 17 00 14 4D 79 4D 51 54 54 2F 31 2F 32 2F 56 5F 54 52 49 50 50 45 44 30
    0;0;3;0;9;read: 1-1-0 s=1,c=1,t=0,pt=7,l=5,sg=0:21.8
                                                        MyMQTT/1/1/V_TEMP
    >>30 17 00 11 4D 79 4D 51 54 54 2F 31 2F 31 2F 56 5F 54 45 4D 50 32 31 2E 38
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
                                                      MyMQTT/1/2/V_TRIPPED
    >>30 17 00 14 4D 79 4D 51 54 54 2F 31 2F 32 2F 56 5F 54 52 49 50 50 45 44 30
    0;0;3;0;9;read: 1-1-0 s=2,c=1,t=16,pt=0,l=1,sg=0:0
                                                      MyMQTT/1/2/V_TRIPPED
    >>30 17 00 14 4D 79 4D 51 54 54 2F 31 2F 32 2F 56 5F 54 52 49 50 50 45 44 30
    

    Any ideas on what I am missing? Also, when trying to implement persistence, I went with MySQL as per directions here but the data doesn't actually go into the chart. Other than adding mysql to the openhab.cfg file, what else is there? The log isn't showing any errors from what I can see.

    Thanks!



  • Typing from tablet => short Version

    Contact items needs Open or Closed not On vor Off. Make a new map translating 0 to closed etc and it should work. or use the correct item: switch seems a better choice
    https://github.com/openhab/openhab/wiki/Explanation-of-items#itemtype



  • Hi @dakky

    well, some luck. I made a new map contact.map with
    0=Closed
    1=Open
    -=unknown

    so far the swtich now shows "Unknown" all the time; but no status updates from the sensor (even though it is showing in serial console as 1, and 0 when it is off).

    Not sure why it isn't updating like it should now. Might have to reboot the server.



  • Ok, got it. Had to do the following to my items and sitemap to get a PIR to work right:

    entry in default.items

    Switchnode6_motion	 "LR Motion Test [MAP(motion.map):%s]"  (FF_Living,All) {mqtt=">[mysensor:MyMQTT/6/1/V_TRIPPED:command:ON:1],>[mysensor:MyMQTT/6/1/V_TRIPPED:command:OFF:0],<[mysensor:MyMQTT/6/1/V_TRIPPED:command:MAP(motion.map)]"}
    

    and default.sitemap

    Text item=node6_motion label="PIR Test LR [%s]" icon="pir"
    

    And last, the transform file (named motion.map)

    1=ON
    0=OFF
    

    At least now it registers the data in text as On or Off. Thanks again @dakky



  • Is there a way to redirect all the messages from the serial console of the wifi gateway to some tcp port so they can be read via putty?


  • Hardware Contributor

    Hello, sorry to reopen this post, but maybe someone can help me! I'm still waiting the arrival of my arduinos to make my nodes and gateways, but I already installed openhab to start configuring the layout and MQTT. All is working, I can post to MTQQ from openhab and used the tutorial on this post to make the same button send and recieve.

    The problem is that when I click the button with the code "sw2 send + recieve example" openhab enters in loop mode, it seems that keeps sending and reviving the same MTQQ request. I use MQTT.fx to test the MTQQ posts, and when I click the button, the program also crashes and takes my CPU to max.

    Can any one help me?
    Best Regards
    Soloam


  • Hardware Contributor

    Hello, the problem persists, the map function keeps sending the same request over and over again, If I make a click in a few seconds my mqtt client is full of requests, over 500 with the same message. Wasn't it supposed to send only one message for click?



  • I don't believe you can put both inbound and outbound mqtt messages in the switch definition. This is what creates the infinite loop since you are both sending and receiving on the same message topic. Every time the broker receives the message, it publishes it out to all subscribers. Since your switch item is also a subscriber it picks it up again and the loop continues.

    Use only inbound in the definition then either a rule and/or proxy item to handle the outbound command. Set your rule definition "when item received command". That way it will only fire when you click on the switch item in openHAB. If you use any other option, ie. received update or changed, it will also continue the infinite loop.

    Hope this makes sense.


  • Hardware Contributor

    That makes perfect seance, I was only mirroring the solution presented on the 1st post of this topic. I will try your approach!

    Thank You


  • Hardware Contributor

    It didn't worked, the rule also changes when I receive the MQTT in openhab:

    rule "Send Requst"
    when
        Item node2_sw2 received command
    then
    	if(node2_sw2.state == ON){
    		sendCommand(node2_sw1,ON)
    	}
    	else{
    		sendCommand(node2_sw1,OFF)
    	}
     end
    

    I don't believe this is a new problem to the forum, didn't any one made, a switch on the openhab with inptut and output.


  • Hardware Contributor

    Found the solution tanks to watou user in OpenHab Forum.

    Switch node2_sw2  "sw2 send + recieve example"  (node2,all)	  {mqtt=">[mysensor:MyMQTT/21/2/V_LIGHT:command:OFF:0],>[mysensor:MyMQTT/21/2/V_LIGHT:command:ON:1],<[mysensor:MyMQTT/21/2/V_LIGHT:state:MAP(1on0off.map)]"}
    

    The secret is in the :state: declaration on the MAP!

    Thank you all


Log in to reply
 

Suggested Topics

  • 2
  • 5
  • 17
  • 2
  • 6
  • 10

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts