[Solved] MQTT gateway problem



  • Hi all!
    I am not native english speaker, sorry for my text.
    I have:

    • arduino mega
    • ethernet shield
    • mosquitto on linux (192.168.1.75:1883)
    • mysensors 2.0
    • arduino ide 1.6.12
    • MQTT gateway

    Code of MQTT Gateway:

    /**
     * The MySensors Arduino library handles the wireless radio link and protocol
     * between your home built sensors/actuators and HA controller of choice.
     * The sensors forms a self healing radio network with optional repeaters. Each
     * repeater and gateway builds a routing tables in EEPROM which keeps track of the
     * network topology allowing messages to be routed to nodes.
     *
     * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
     * Copyright (C) 2013-2015 Sensnology AB
     * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
     *
     * Documentation: http://www.mysensors.org
     * Support Forum: http://forum.mysensors.org
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * version 2 as published by the Free Software Foundation.
     *
     *******************************
     *
     * REVISION HISTORY
     * Version 1.0 - Henrik Ekblad
     * 
     * DESCRIPTION
     * The W5100 MQTT gateway sends radio network (or locally attached sensors) data to your MQTT broker.
     * The node also listens to MY_MQTT_TOPIC_PREFIX and sends out those messages to the radio network
     *
     * LED purposes:
     * - To use the feature, uncomment WITH_LEDS_BLINKING in MyConfig.h
     * - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved
     * - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
     * - ERR (red) - fast blink on error during transmission error or recieve crc error  
     * 
     * See http://www.mysensors.org/build/esp8266_gateway for wiring instructions.
     * nRF24L01+  ESP8266
     * VCC        VCC
     * CE         GPIO4          
     * CSN/CS     GPIO15
     * SCK        GPIO14
     * MISO       GPIO12
     * MOSI       GPIO13
     *            
     * Not all ESP8266 modules have all pins available on their external interface.
     * This code has been tested on an ESP-12 module.
     * The ESP8266 requires a certain pin configuration to download code, and another one to run code:
     * - Connect REST (reset) via 10K pullup resistor to VCC, and via switch to GND ('reset switch')
     * - Connect GPIO15 via 10K pulldown resistor to GND
     * - Connect CH_PD via 10K resistor to VCC
     * - Connect GPIO2 via 10K resistor to VCC
     * - Connect GPIO0 via 10K resistor to VCC, and via switch to GND ('bootload switch')
     * 
      * Inclusion mode button:
     * - Connect GPIO5 via switch to GND ('inclusion switch')
     * 
     * Hardware SHA204 signing is currently not supported!
     *
     * Make sure to fill in your ssid and WiFi password below for ssid & pass.
     */
    
    #include <SPI.h>
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG 
    
    // Enables and select radio type (if attached)
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    #define MY_GATEWAY_MQTT_CLIENT
    
    // Set this nodes subscripe and publish topic prefix
    #define MY_MQTT_PUBLISH_TOPIC_PREFIX "ms_mqtt_gw-out"
    #define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "ms_mqtt_gw-in"
    
    // Set MQTT client id
    #define MY_MQTT_CLIENT_ID "mqtt_gw_1"
    
    // Security Signing
    #define MY_SIGNING_SOFT //!< Software signing
    //#define MY_SIGNING_ATSHA204 //!< Hardware signing using ATSHA204A
    // Enable node whitelisting
    //#define MY_SIGNING_NODE_WHITELISTING {{.nodeId = GATEWAY_ADDRESS,.serial = {0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x02,0x01}}}
    // Enable this if you want destination node to sign all messages sent to this node.
    //#define MY_SIGNING_REQUEST_SIGNATURES
    
    // W5100 Ethernet module SPI enable (optional if using a shield/module that manages SPI_EN signal)
    //#define MY_W5100_SPI_EN 4  
    
    // Enable Soft SPI for NRF radio (note different radio wiring is required)
    // The W5100 ethernet module seems to have a hard time co-operate with 
    // radio on the same spi bus.
    #if !defined(MY_W5100_SPI_EN) && !defined(ARDUINO_ARCH_SAMD)
      #define MY_SOFTSPI
      #define MY_SOFT_SPI_SCK_PIN 54
      #define MY_SOFT_SPI_MISO_PIN 56
      #define MY_SOFT_SPI_MOSI_PIN 55
    #endif  
    
    // When W5100 is connected we have to move CE/CSN pins for NRF radio
    #ifndef MY_RF24_CE_PIN 
      #define MY_RF24_CE_PIN 5
    #endif
    #ifndef MY_RF24_CS_PIN 
      #define MY_RF24_CS_PIN 6
    #endif
    
    // Enable these if your MQTT broker requires usenrame/password
    //#define MY_MQTT_USER "username"
    //#define MY_MQTT_PASSWORD "password"
    
    // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
    #define MY_IP_ADDRESS 192,168,1,76
    
    // If using static ip you need to define Gateway and Subnet address as well
    #define MY_IP_GATEWAY_ADDRESS 192,168,1,1
    #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 "m20.cloudmqtt.com"
    #define MY_CONTROLLER_IP_ADDRESS 192, 168, 1, 75
    
    // The MQTT broker port to to open 
    #define MY_PORT 1883     
    
     /*
    // Flash leds on rx/tx/err
    #define MY_LEDS_BLINKING_FEATURE
    // Set blinking period
    #define MY_DEFAULT_LED_BLINK_PERIOD 300
    
    // Enable inclusion mode
    #define MY_INCLUSION_MODE_FEATURE
    // Enable Inclusion mode button on gateway
    #define MY_INCLUSION_BUTTON_FEATURE
    // Set inclusion mode duration (in seconds)
    #define MY_INCLUSION_MODE_DURATION 60 
    // Digital pin used for inclusion mode button
    #define MY_INCLUSION_MODE_BUTTON_PIN  3 
    
    // Uncomment to override default HW configurations
    //#define MY_DEFAULT_ERR_LED_PIN 16  // Error led pin
    //#define MY_DEFAULT_RX_LED_PIN  16  // Receive led pin
    //#define MY_DEFAULT_TX_LED_PIN  16  // the PCB, on board LED
    */
    
    #include <Ethernet.h>
    #include <MySensors.h>
    
    void setup() { 
    }
    
    void presentation() {
      // Present locally attached sensors here    
    }
    
    
    void loop() {
      // Send locally attech sensors data here
    }
    
    

    And i have this trouble:

    0;255;3;0;9;Starting gateway (RNNGAS, 2.0.0)
    0;255;3;0;9;TSM:INIT
    0;255;3;0;9;TSM:RADIO:OK
    0;255;3;0;9;TSM:GW MODE
    0;255;3;0;9;TSM:READY
    IP: 192.168.1.76
    0;255;3;0;9;No registration required
    0;255;3;0;9;Init complete, id=0, parent=0, distance=0, registration=1
    IP: 192.168.1.76
    0;255;3;0;9;Attempting MQTT connection...
    IP: 192.168.1.76
    0;255;3;0;9;Attempting MQTT connection...
    IP: 192.168.1.76
    0;255;3;0;9;Attempting MQTT connection...
    0;255;3;0;9;TSP:SANCHK:OK
    IP: 192.168.1.76
    0;255;3;0;9;Attempting MQTT connection...
    IP: 192.168.1.76
    0;255;3;0;9;Attempting MQTT connection...
    IP: 192.168.1.76
    0;255;3;0;9;Attempting MQTT connection...
    IP: 192.168.1.76
    0;255;3;0;9;Attempting MQTT connection...
    

    I try to use mosquitto_sub and pub + mqtt-spy, and mqtt broker is work.
    I replase mega -> uno, one ethernet shield to another, nothing change.
    ping between client and brocker is ok.

    I don't know what else to do, can anybody help me?



  • Can you connect to the MQTT server using MQTT-SPY?



  • @Martin-Tellblom Yes, it work normally, how it seems to me.


  • Mod

    @pinkkoff what version of mosquitto are you running?



  • @Yveaux
    mosquitto is an MQTT v3.1 broker.
    Version: 0.15-2ubuntu1

    Run on Odroid C1+ with ubuntu 14.04


  • Mod

    @pinkkoff iirr the mqtt implementation in mysensors is 3.1.1
    Try upgrading your mosquitto version



  • @Yveaux Thank you!!! It working!
    Problem is in version of mosquitto in ubuntu repository. If someone want to use mqtt, better way is follow step-by-step guide


  • Admin

    @pinkkoff

    FYI, I've had better luck using the mosquitto ppa. Tested on RPI2 and RPI3 running Ubuntu.



  • I'm also trying mqtt. somehow I can't see the messages:

    MySensors $ ./configure --my-gateway=mqtt --my-controller-ip-address=192,168,1,32 --my-port=1883 --my-mqtt-client-id=22 --my-mqtt-publish-topic-prefix=mysensors-from --my-mqtt-subscribe-topic-prefix=mysensors-to --my-rf24-pa-level=RF24_PA_LOW 
    MySensors $ sudo make install
    ...
    MySensors $ sudo mysGateway -d
    ...
    mysGateway: Attempting MQTT connection...
    mysGateway: connected to 192.168.1.32
    mysGateway: TSF:MSG:READ,8-8-0,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
    mysGateway: !TSF:MSG:SEND,0-0-8-8,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=NACK:0100
    mysGateway: TSF:MSG:READ,8-8-0,s=255,c=0,t=17,pt=0,l=10,sg=0:2.0.1-beta
    mysGateway: TSF:MSG:READ,8-8-0,s=255,c=3,t=6,pt=1,l=1,sg=0:0
    mysGateway: Attempting MQTT connection...
    mysGateway: connected to 192.168.1.32
    ...
    

    So GW attempts to send some stuff to mqtt server elsewhere, like that version string. But this on the server prints nothing:

    $ mosquitto_sub -t mysensors-from/*

    I also tried with # instead of *

    I've verified mqtt works, if I pub that from mqtt client, it works.



  • so this works:

    MySensors $ mosquitto_pub -h 192.168.1.32 -t mysensors-from/0/1 -m "MySensors MQTT hello world from raspi to odroid"

    mqtt-host $ mosquitto_sub -t mysensors-from/#
    MySensors MQTT hello world from raspi to odroid



  • My mosquitto is mosquitto 3.1 - 0.15-2ubuntu1 (from ppa) and mysensors is up to date devel branch from github.



  • after upgrading to above mentioned 3.1.1 version from wheezy, the mysensors start to print out it sends stuff. can't see it on subs yet though.



  • nevermind. now after all upgrades AND BATTERY CHANGE to sensebender it's all fine 🙂



Suggested Topics

  • 49
  • 6
  • 9
  • 5
  • 5
  • 24
  • 8
  • 6

0
Online

11.2k
Users

11.1k
Topics

112.5k
Posts