Problem with Mosquitto Topic



  • Hi everyone,

    I need to change serial communication for a Mosquitto on an existing project. There is one PC and 3 ESP32 without radio-frequency To put be simply, there is a PC which controls ESP32 by the network. On the current project, the node ID is the number of ESP between 1 and 3.
    0_1556451961142_ESP.png

    However, when a try to set up the MQTT gateway, the first topic is always 0. If I'm used message.setDestination(1), this message is not sending (return 0).

    I'm using this following code to my ESP32:

    #define MY_DEBUG
    #define MY_NODE_ID 2
    /**********************************************
    *     Ethernet Gateway Transport Defaults    */
    #define MY_GATEWAY_MQTT_CLIENT
    #define MY_GATEWAY_ESP32
    
    /** Configuration of WiFi */
    #define MY_WIFI_SSID "Test"
    #define MY_WIFI_PASSWORD "qwerty1234"
    #define MY_HOSTNAME "Boss2"
    
    /** MQTT Configuration **/
    #define MY_MQTT_PUBLISH_TOPIC_PREFIX "sendToPc"
    #define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "getToPc"
    #define MY_MQTT_CLIENT_ID "Boss2"
    #define MY_CONTROLLER_IP_ADDRESS 192, 168, 56, 101
    #define MY_PORT 1883
    /**********************************************/
    
    #include <MySensors.h>
    
    #define MY_BAUD_RATE 115200
    #define OPEN 1
    #define CLOSE 0
    #define CHILD_ID 1
    
    MyMessage msg;
    
    uint8_t value = OPEN;
    
    void presentation() {
      present(CHILD_ID, S_DOOR);
    }
    
    void setup(){
      Serial.begin(115200);
      msg.setType(V_TRIPPED);
      msg.setSensor(CHILD_ID);
    }
    
    void loop() {
      value = value == OPEN ? CLOSE : OPEN;
      send(msg.set(value));
      delay(1000);
    }
    
    

    And on serial terminal I have :

    20182 GWT:TPC:CONNECTING...
    20684 GWT:TPC:CONNECTING...
    20686 GWT:TPC:IP=192.168.137.160
    20691 MCO:BGN:STP(20693 MCO:REG:NOT NEEDED
    20695 MCO:BGN:INIT OK,TSP=NA
    20697 GWT:TPC:IP=192.168.137.160
    20700 GWT:RMQ:MQTT RECONNECT
    20723 GWT:RMQ:MQTT CONNECTED
    20725 GWT:TPS:TOPIC=sendToPc/0/255/0/0/17,MSG SENT
    20733 GWT:TPS:TOPIC=sendToPc/0/1/0/0/0,MSG SENT
    20740 GWT:TPS:TOPIC=sendToPc/0/1/1/0/16,MSG SENT
    21745 GWT:TPS:TOPIC=sendToPc/0/1/1/0/16,MSG SENT
    22751 GWT:TPS:TOPIC=sendToPc/0/1/1/0/16,MSG SENT
    

    Rather than

    20740 GWT:TPS:TOPIC=sendToPc/2/1/1/0/16,MSG SENT
    

    Do you have a solution?

    Thank you


  • Mod

    Welcome to the forum @exblematique
    A MySensors gateway (which is what each of your esp32 are technically) always has node id 0 by design.
    SetDestination is used to send to another node in the MySensors network, so it can't be used to achieve what you want.

    There are two ways to differentiate different gateways: MY_MQTT_CLIENT_ID and MY_MQTT_PUBLISH_TOPIC_PREFIX.



  • Thank you for your quick answers.
    I will try with this new information


  • Mod

    @exblematique https://github.com/mysensors/MySensors/issues/1212 might be of interest to you as well. There hasn't been any activity lately, but maybe you can join forces with other people that are interested.



  • @mfalkvidd said in Problem with Mosquitto Topic:

    MY_MQTT_PUBLISH_TOPIC_PREFIX

    @exblematique
    I am using three different MQTT gateways in three different geographical locations and have done so for years. Each having their own MY_MQTT_PUBLISH_TOPIC_PREFIX. It works perfectly!



  • Thank you for your all answers.
    I have made some tests and even if I don't have results for the moment, the best solution for me seems using (in accordance with @bgunnarb):

    MY_MQTT_PUBLISH_TOPIC_PREFIX ESP-topic/ESP-number
    

    Yes, it's can be a good idea @mfalkvidd


 

276
Online

8.4k
Users

9.3k
Topics

97.9k
Posts