Temp-Monitoring using OpenHab, MQTT, Pi 3 & Uno



  • Hello guys,

    I am trying to build a temperature monitoring system for a fridge, which tracks data and in-case it goes above a certain temperature, it would send an email alert. Would be nice if I am able to display data logs on a touch screen.

    I have the following setup:
    Raspberri Pi 3 with OpenHabian installed
    Arduino Uno hooked up to 2 DS18B20 (One Wire temp sensors)
    2x nRFl01+ (one for the Pi & one on the Uno)

    Things I have done previously:
    I tested the nRF24 connections and was able to send/receive simple "hello world" from Arduino to Rp3
    I have been able to read temperature data on the Arduino via serial monitor

    I have followed This Guide, however I am stuck in STEP 3, to be more specific, I don't know how to transfer data from Uno to Rp and check if it is working or not via MQTT,

    additionally, OpenHab is brand new to me, and I wasn't able to find any examples on how to configure it, I would really appreciate it if someone can link a few videos/tutorials that can get me going, as the amount of information my brain has consumed over the few days is vast, and I am about to lose my mind!

    Also I tried following the instructions on MySensors.org trying to just use serial communication, but that didn't really work and I was stuck around the same stage.

    Need clarification:

    1. Can I transmit and receive data using the MySensors libraries without installing MySensors in OpenHab? (because I don't have it, according to the tutorial it wasn't installed)

    2. Where the hell do I define my Node IDs ? (Do I simply place "#define MY_NODE_ID 1" ontop of my Uno Code?)?

    3. For the MQTT Broker on PaperUI, I was only able to get it online by using "LocalHost" is that right?

    I have a lot of questions, but will start with these, I will keep reading/watching videos in the meantime 🤔


  • Mod

    Hi @nizoo91, welcome to the MySensors community 🙂

    I only know the answer to one of your questions, so I'll just answer that.

    1. Where the ^^^^ do I define my Node IDs ? (Do I simply place "#define MY_NODE_ID 1" ontop of my Uno Code?)?

    Yes. Before including MySensors.h



  • @nizoo91 Hi!
    I'll try to shed some light on your questions 1 and 3.

    Question 3. Right. If the Broker is hosted on the same RPi as OpenHab (OH), then localhost is correct.

    Question 1. The question is not correct. The sequence of transmission from sensor to OH is the following:

    a.) The Arduino sensor sends its data to the MySensors MQTT GW, which in your case is hosted on the RPi.
    b.) The MySensors MQTT GW publishes the data to the MQTT Broker, which in your case also is hosted on the RPi. The MQTT broker acts like a hub for the MQTT messages.
    c.) OH uses the MQTT-binding to subscribe to the messages that come into the MQTT Broker and does its magic.

    This is a very efficient set-up especially if you have, as I have, several places with sensors, each reporting via their own MySensors MQTT GW to one MQTT Broker which then OH can subscribe to.
    But for learning both MySensors and OH at the same time, it will be a bit complicated.

    Some good sources of knowledge is www.openhab.org where you will learn everything about OH. The OH community is also very much alive. I recommend that you use that site for learning OH instead of other sources.

    To learn MQTT and how this works, you can start using a tool called mqtt.fx which is available from the website with the same name. Then you can connect to your broker and watch incoming messages from the MySensors GW. You can also inject MQTT messages with that tool and make OH do things.

    For a simpler set-up just install the MySensors serial GW and have that talk directly to OH. There is an OH binding available for MySensors I think but I have no experience with that.

    Coming to grips with all of this is a bit of a steep learning curve but don't give up. Start piece by piece and get the different parts working and then connect them together. I have done it! Good luck!



  • @nizoo91 said in Temp-Monitoring using OpenHab, MQTT, Pi 3 & Uno:

    Can I transmit and receive data using the MySensors libraries without installing MySensors in OpenHab? (because I don't have it, according to the tutorial it wasn't installed)

    For the MQTT Broker on PaperUI, I was only able to get it online by using "LocalHost" is that right?

    You don't need the mysensors binding if all you're doing is taking in readings. you'd probably be better for it.

    localhost/127.0.0.1/the actual ip should all work. if localhost works, just use that. don't make it complicated.



  • @mfalkvidd, @bgunnarb & @waspie

    Thank you for the help guys, to be honest I felt fairly out dated because I wasn't able to get it working first try! as usually I am a tech guru, and I am able to just get things working the way I want fairly easily!

    Anyhow, I will keep digging and see what I can do! I definitely need to get my head around it, but also need to get this up and running for my school project, as this will be my project for end of the semester! and will be using it in our family Restaurant after 🙂 and yes, free food for everyone that helps me out haha 😉

    Will report back with any questions 🙂

    @waspie I would love to make it as simple as possible for the school project purposes, so I can get it done and take my time tinkering later on with MQTT and everything else, but I absolutely need a working device to present within 2 months 🙂

    Cheers



  • @nizoo91

    Sorry to be a pain, but where exactly are things failing right now?



  • Thank you @waspie, for the follow-up

    I have actually made a big mess of everything trying to use different tutorials, OH documentation, ect...

    I am a little more familiar with OpenHab now, especial thanks to @bgunnarb 's comment, it helped me understand the "sequence" and breakdown each step separately.

    I decided to start with a fresh OpenHabian install and go at it again.

    I am curious about MQTT Broker version to use, in the tutorial it says:
    "There are compatibility issues on the latest release of openHAB (2.4). I will review this i more depth but for the moment you can add the compatibility with legacy bindings and install MQTT1 instead of the new binding."

    is the above statement still valid? does MQTT1 actually still work? should I absolutely not use the new MQTT Broker? because I have read other posts that got the new broker working...

    Thank you



  • 2.4 works well enough. there were some big bugs squished with 2.5m1 hot on 2.4's heels.
    If you're planning to use this more and more (and you likely will once you start to see what you can do) stick with the 2.x implementation of MQTT. I don't know how openhabian handles things. If you can, disable whatever bundled MQTT broker openhabian has and use the built in broker (for the sake of simplicity).

    Enable/install the embedded (built in) broker by using PaperUI. Go to Add-ons->Misc and install the Embedded MQTT Broker.
    Once installed, you'll have a new item in the PaperUI Inbox. That item will be the broker - add it. If you don't get it in your inbox you may still have an external broker running which will keep the embedded one from starting (two processes are trying to use a single port).



  • Not sure if you are able to help me out here, but here is what I got so far,

    my MQTT1 Broker is running with following config:

    mosquitto.url=tcp://localhost:1883
    mosquitto.qos=1
    mosquitto.retain=true
    mosquitto.async=false
    mosquitto.user=openhabian
    mosquitto.pwd="" 
    
    • no pwd for mosquitto.

    I used the following commmand when installing the MySensors:

    ./configure --my-gateway=mqtt --my-controller-ip-address=127.0.0.1 --my-mqtt-publish-topic-prefix=mygateway1-out --my-mqtt-subscribe-topic-prefix=mygateway1-in --my-mqtt-client-id=mysensors-1 --my-mqtt-user=openhabian --my-mqtt-password=
    
    • Again no password
    • I am assuming 127.0.0.1 is localhost as usual, so I left it as 127.0.0.1
      Below is the result of : sudo ./bin/mysgw
      alt text

    .
    Arduino code to test connection:

    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    // Enables and select radio type (if attached)
    #define MY_RADIO_RF24
    //#define MY_RADIO_RFM69
    //#define MY_RADIO_RFM95
    
    #define MY_GATEWAY_MQTT_CLIENT
    #define MY_NODE_ID 1
    
    // Set this node's subscribe and publish topic prefix
    #define MY_MQTT_PUBLISH_TOPIC_PREFIX "mygateway1-out"
    #define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "mygateway1-in"
    
    // Set MQTT client id
    #define MY_MQTT_CLIENT_ID "mysensors-1"
    
    // Enable these if your MQTT broker requires username/password
    #define MY_MQTT_USER "openhabian"
    #define MY_MQTT_PASSWORD ""
    
    // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
    //#define MY_IP_ADDRESS 192, 168, 0, 19
    
    // If using static ip you can define Gateway and Subnet address as well
    //#define MY_IP_GATEWAY_ADDRESS 192, 168, 0, 19
    //#define MY_IP_SUBNET_ADDRESS 255,255,255,0
    
    // MQTT broker ip address or url. Define one or the other.
    //#define MY_CONTROLLER_URL_ADDRESS 192, 168, 0, 19
    #define MY_CONTROLLER_IP_ADDRESS 192, 168, 0, 19
    
    // The MQTT broker port to to open
    #define MY_PORT 1883
    
    #include <Ethernet.h>
    #include <MySensors.h>
    
    void setup()
    {
        // Setup locally attached sensors
    }
    
    void presentation()
    {
        // Present locally attached sensors here
    }
    
    void loop()
    {
        // Send locally attached sensors data here
    }
    

    • Result:
    0 MCO:BGN:INIT GW,CP=RNNGA---,REL=255,VER=2.3.1
    4 TSM:INIT
    5 TSF:WUR:MS=0
    11 TSM:INIT:TSP OK
    13 TSM:INIT:GW MODE
    15 TSM:READY:ID=0,PAR=0,DIS=0
    17 MCO:REG:NOT NEEDED
    641 !GWT:TPC:DHCP FAIL
    643 MCO:BGN:STP
    645 MCO:BGN:INIT OK,TSP=1
    1268 !GWT:TPC:DHCP FAIL
    1271 TSM:READY:NWD REQ
    1308 TSF:MSG:SEND,0-0-255-255,s=255,c=3,t=20,pt=0,l=0,sg=0,ft=0,st=OK:
    1937 !GWT:TPC:DHCP FAIL
    2561 !GWT:TPC:DHCP FAIL
    3184 !GWT:TPC:DHCP FAIL
    3809 !GWT:TPC:DHCP FAIL
    4432 !GWT:TPC:DHCP FAIL    
    

    Please let me know what stupid thing I have done now 😞



  • I think all the MQTT/OH stuff looks right but I'm not sure what's going on with the arduino part.
    You're using an UNO with an ethernet shield?



  • @waspie

    No I am not, I think I spent too much time yesterday on it, and made a mess again 😕

    I am going to give it an another shot now and see what I can do 🙂



  • @nizoo91 right, well then there's no need to be setting IPs and such in the arduino...



  • @waspie said in Temp-Monitoring using OpenHab, MQTT, Pi 3 & Uno:

    @nizoo91 right, well then there's no need to be setting IPs and such in the arduino...

    Okay I am going to start from the beginning again then, because I just found another post that confused me even more!
    @gohan said in Sending data from Arduino to Raspberry Pi via NRF24L01+:

    "he serial gateway is supposed to be connected via USB and it is sending data over the usb serial port, so for your project you would need an extra Arduino as a sensor node where you will connect the 2 sensors (look at the MySensors library examples) with a NRF24 module that will be sending data to the other Arduino with the other NRF24 configured as serial gateway and connected to the RPI3 via USB. MySensors library allows you to setup your gateway also as Ethernet (with a W5100 shield) or Ethernet with MQTT client (also need the W5100 shield)."

    Attached is a picture of what I want to achieve, preferably without an Ethernet shield. alt text

    Any advice would be appropriated 😕



  • No Ethernet, just mqtt


  • Mod

    That's fine, just look on instruction on how to build a raspberry gateway



  • Wohoo got it to finally work 🙂

    not using MQTT but via serial gateway which is good enough for now 🙂


Log in to reply
 

Suggested Topics

  • 3
  • 6
  • 6
  • 1
  • 2

53
Online

11.4k
Users

11.1k
Topics

112.7k
Posts