Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Troubleshooting
  3. Problem with Mosquitto Topic

Problem with Mosquitto Topic

Scheduled Pinned Locked Moved Troubleshooting
6 Posts 3 Posters 665 Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    exblematique
    wrote on last edited by
    #1

    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

    mfalkviddM 1 Reply Last reply
    0
    • E exblematique

      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

      mfalkviddM Offline
      mfalkviddM Offline
      mfalkvidd
      Mod
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • E Offline
        E Offline
        exblematique
        wrote on last edited by
        #3

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

        mfalkviddM 1 Reply Last reply
        1
        • E exblematique

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

          mfalkviddM Offline
          mfalkviddM Offline
          mfalkvidd
          Mod
          wrote on last edited by
          #4

          @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.

          1 Reply Last reply
          0
          • bgunnarbB Offline
            bgunnarbB Offline
            bgunnarb
            wrote on last edited by
            #5

            @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!

            I have never been so busy since I retired!

            1 Reply Last reply
            1
            • E Offline
              E Offline
              exblematique
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              1
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              22

              Online

              11.7k

              Users

              11.2k

              Topics

              113.1k

              Posts


              Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • MySensors
              • OpenHardware.io
              • Categories
              • Recent
              • Tags
              • Popular