Help getting started with MQTT gateway


  • Hardware Contributor

    @hek Ahh okay, i was only wondering :). I'm setting up a ArduinoMega as we speak as a MQTTClient, im struggling to get my broker (mosquitto) on my raspberrypi controller to get the startup message from the gateway. Day long of debugging ahead of me 😉


  • Hardware Contributor

    @hek I've changed the port number and MY_IP_GATEWAY_ADDRESS to the address of the RaspberryPi running Mosquitto. I've set my static IP, router gateway and subnet as follows in the sketch, uploaded it to the arduino and its not showing up in the subscribed topic of mosquitto_sub -v -t '#' when i restart the gateway.

    // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
    #define MY_IP_ADDRESS 192,168,0,85
    
    // If using static ip you need to define Gateway and Subnet address as well
    #define MY_IP_GATEWAY_ADDRESS 192,168,0,1
    #define MY_IP_SUBNET_ADDRESS 255,255,255,0
    
    
    // MQTT broker ip address.  
    #define MY_CONTROLLER_IP_ADDRESS 192, 168, 0, 21
    
    // The MQTT broker port to to open 
    #define MY_PORT 1883      
    

    I am able to ping the address of the arduino, so i know the connection of the arduino is, somewhat, correct.

    Is there anything silly that i'm doing wrong here? I've tried changing:

    // W5100 Ethernet module SPI enable (optional if using a shield/module that manages SPI_EN signal)
    //#define MY_W5100_SPI_EN 4
    

    but that didn't work either. I'm struggling to see anything else that would be needed apart from the address for the broker itself.

    Edit: Would it just be better for me to run the Gateway as a Broker itself rather than as a client connecting to the broker on the raspberryPi?


  • Hardware Contributor

    I have my controller running openHAB and mosquitto perfect now, my MQTTGateway is working too. I've made a humidity sensor node with the sketch in the library folder, its passing (null) on the specified topic.

    I'm guessing that the (null) means that there is no message in the communication. Am i correct in assuming this?


  • Admin

    @samuel235 said:

    I'm guessing that the (null) means that there is no message in the communication. Am i correct in assuming this?

    Some messages has no payload. But humidity/set should have one.


  • Hardware Contributor

    send: 255-255-0-0 s=255,c=3,t=3,pt=0,l=0,sg=0,st=ok:
    H: 41.90
    req id
    send: 255-255-0-0 s=255,c=3,t=3,pt=0,l=0,sg=0,st=ok:
    T: 24.70
    req id
    send: 255-255-0-0 s=255,c=3,t=3,pt=0,l=0,sg=0,st=ok:
    H: 42.00
    req id
    send: 255-255-0-0 s=255,c=3,t=3,pt=0,l=0,sg=0,st=ok:
    H: 41.80
    req id
    send: 255-255-0-0 s=255,c=3,t=3,pt=0,l=0,sg=0,st=ok:
    T: 24.80
    req id
    

    This is just a snippet from my Humidity sensor, and there is nothing sitting at the end of the send line, so i'm guessing the sensor node is not releasing a value for humidity.


  • Admin

    The node is requesting an id from the controller. "req id"...

    So you either have to answer this request (through mqtt) or set a static id on the node.

    #define MY_NODE_ID 42


  • Hardware Contributor

    @hek I wondered why i was getting 255-255 everywhere. Does this have anything to do with that?

    By the way, i assumed that all the configs were setup to handout random ID's, i'm sure i kept reading "automatic ID assign" when i was editing configs for the radios....


  • Admin

    The node uses id 255 temporarily while asking for an id.

    It's automatic if you're controller supports it. But as this mqtt topic layout is quite new, I doubt many controllers support it.

    The previous (1.5) MQTT gateway did some handouting on its own which wasn't optimal (stored last used id in EEPROM resulting in no control/reuse of ids).


  • Hardware Contributor

    Ahhh right okay, well this is what i kept reading in 'MyConfig.h':

    // Node id defaults to AUTO (tries to fetch id from controller)
    #ifndef MY_NODE_ID
    #define MY_NODE_ID AUTO
    #endif
    

    However, i shall manually set the ID on my nodes now.

    I have put '#define MY_NODE_ID 42' into the humidity sketch, that isn't working, is there a specific place it needs to be? I'm just looking through the config files to see where about in the sendMessage code it calls for it and how it calls for it. I've tried to comment those lines out so it doesn't even attempt to get a ID from the controller, that isn't working at the moment.


  • Admin

    @samuel235 said:

    is there a specific place it needs to be?

    Add it before the inclusion of MySensor.h


  • Hardware Contributor

    I tried what you advised but it wasn't asigning a ID to the node still. So after a little looking around i found that you can specify the node id within gw.begin().

    So i have got it as gw.begin(NULL, 4, false).

    While i understand that the second piece of data is the node id, and the third is whether or not it goes into sleep mode. What is the first? Also, with me calling false for the sleep mode and then at the end of the sketch it tells the node to sleep for 30 seconds, am i over riding that sleep mode that i call at the end?


  • Admin

    Ah.. you're running mixed library versions on node/gateway.. Yes, then you'd need to call gw.begin() on the node.


  • Hardware Contributor

    But will this overwrite any config/settings like sleep or anything? What does the NULL mean at the start of gw.begin?


  • Admin

    I'm splitting this discussion to a new topic.


  • Admin

    The 1.5 API/begin() is documented here:
    http://www.mysensors.org/download/sensor_api_15#the-full-api

    First argument is callback-function used if you're interested in incoming data. NULL won't overwrite any configuration.


  • Hardware Contributor

    I'm sorry, i got confused about which version i was running. I thought it was the development humidity sketch and therefor i didn't look for the API of it. Makes sense now. Thank you.


  • Hardware Contributor

    I now have my controller, broker and gateway setup working fine. I then created a temp and humidity sensor, works fine. I then made a motion node, works fine. Then a light switch node that all work perfectly fine together. Now, i come to configure my relay module (which im struggling with getting it to receive the messages) so i open my serial monitor for the gateway and see that even though its got a solid connection, it keeps trying to make another MQTT connection. Over and over again....

    0;0;3;0;9;Attempting MQTT connection...
    0;0;3;0;9;MQTT connected
    0;0;3;0;9;Attempting MQTT connection...
    0;0;3;0;9;MQTT connected
    0;0;3;0;9;Attempting MQTT connection...
    0;0;3;0;9;MQTT connected
    0;0;3;0;9;Attempting MQTT connection...
    0;0;3;0;9;MQTT connected
    0;0;3;0;9;Attempting MQTT connection...
    0;0;3;0;9;MQTT connected
    

    There is nothing in the loop section of the sketch, so all i can assume is that it keeps dropping its connection to mosquitto broker thats wired over ethernet?


  • Admin

    Strange.. And the log on the relay node?


  • Hardware Contributor

    This post is deleted!

  • Hardware Contributor

    send: 4-4-0-0 s=255,c=0,t=18,pt=0,l=5,sg=0,st=fail:1.5.1
    send: 4-4-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=fail:0
    repeater started, id=4, parent=0, distance=1
    send: 4-4-0-0 s=255,c=3,t=11,pt=0,l=5,sg=0,st=fail:Relay
    send: 4-4-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,st=fail:1.0
    send: 4-4-0-0 s=1,c=0,t=3,pt=0,l=0,sg=0,st=fail:
    

  • Hardware Contributor

    Just to let you know (Not sure if it tells you that i have edited a post), i have removed what i said about the gateway not working, that is back online now, however its back to doing exactly what it was doing earlier and keep trying to connect. But literally its spamming at a rate of like 10/20 per second...

    0;0;3;0;9;Attempting MQTT connection...
    0;0;3;0;9;MQTT connected
    0;0;3;0;9;Attempting MQTT connection...
    0;0;3;0;9;MQTT connected
    

    I have a weird feeling that there may be a power issue or a connection issue somewhere on this gateway. (Its in a cupboard since i got it working this morning so its a little hard for me to believe it).

    I have tried a restart on the MQTT broker btw, still nothing.


  • Hardware Contributor

    I now feel like a very big silly idiot. Let this be a lesson to anyone thats developing any sort of project. Document everything in some way, pen and paper or in a file.

    I had refreshed the sketch and used the same clientID as the raspberrypi was using when i had my old automation server running there.


Log in to reply
 

Suggested Topics

  • 1
  • 5
  • 3
  • 2
  • 1
  • 2

5
Online

11.4k
Users

11.1k
Topics

112.7k
Posts