Giter VIP home page Giter VIP logo

Comments (7)

martin-ger avatar martin-ger commented on June 19, 2024

I am not aware of such a bug. Is there anything special in the code of the broker? Just the basic sample or local subscriptions/publications? What are the subscriptions of the Tasmota? Maybe two matching topics?

from umqttbroker.

HoerMirAuf avatar HoerMirAuf commented on June 19, 2024

I take the uMQTTBrokerSampleOOFull.

The only changes i have done in the Sample Code is a static IP, and deleted the counter publishing:

/*
 * uMQTTBroker demo for Arduino (C++-style)
 * 
 * The program defines a custom broker class with callbacks, 
 * starts it, subscribes locally to anything, and publishs a topic every second.
 * Try to connect from a remote client and publish something - the console will show this as well.
 */

#include <ESP8266WiFi.h>
#include "uMQTTBroker.h"

/*
 * Your WiFi config here
 */
char host[] = "ESP-MQTT";           // Hostname & SSID in AP-Mode
char ssid[] = "DEG-TEST-WLAN";      // your network SSID (name)
char pass[] = "12345678";           // your network password
bool WiFiAP = false;      // Do yo want the ESP as AP?
bool STATIC = true;                 // Static IP for STA Mode?
IPAddress ip(192,168,1,200);        // Static IP
IPAddress gw(192,168,1,1);          // Static Gateway/DNS
IPAddress su(255,255,255,0);        // Static Subnet Mask

/*
 * Custom broker class with overwritten callback functions
 */
class myMQTTBroker: public uMQTTBroker
{
public:
    virtual bool onConnect(IPAddress addr, uint16_t client_count) {
      Serial.println(addr.toString()+" connected");
      return true;
    }
    
    virtual bool onAuth(String username, String password) {
      Serial.println("Username/Password: "+username+"/"+password);
      return true;
    }
    
    virtual void onData(String topic, const char *data, uint32_t length) {
      char data_str[length+1];
      os_memcpy(data_str, data, length);
      data_str[length] = '\0';
      
      Serial.println("received topic '"+topic+"' with data '"+(String)data_str+"'");
    }
};

myMQTTBroker myBroker;

/*
 * WiFi init stuff
 */
void startWiFiClient()
{
  if (STATIC) {
	WiFi.config(ip, gw, gw, su);
  }
  WiFi.softAPdisconnect(true);
  WiFi.hostname(host);
  Serial.println("Connecting to "+(String)ssid);
  WiFi.begin(ssid, pass);
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println(""); 
  Serial.println("WiFi connected");
  Serial.println("IP address: " + WiFi.localIP().toString());
  Serial.println(""); 
}

void startWiFiAP()
{
  WiFi.softAP(ssid, pass);
  Serial.println("AP started");
  Serial.println("IP address: " + WiFi.softAPIP().toString());
}

void setup()
{
  Serial.begin(115200);
  Serial.println();
  Serial.println();

  // Start WiFi
  if (WiFiAP)
    startWiFiAP();
  else
    startWiFiClient();

  // Start the broker
  Serial.println("Starting MQTT broker");
  myBroker.init();

/*
 * Subscribe to anything
 */
  myBroker.subscribe("#");
}

//int counter = 0;

void loop()
{
/*
 * Publish the counter value as String
 */
  //myBroker.publish("broker/counter", (String)counter++);
   
  // wait a second
  delay(1000);
}

The mosquitto_pub Topic is (the MQTT Device Name is "TEST", the Group Topic is the default "sonoff" but not used here):
**

mosquitto_pub -i LapTop -h 192.168.1.200 -t cmnd/TEST/POWER -m off

**
This command is only send once !!!

The debug webconsole log from tasmota show:

00:00:16 SRC: MQTT
00:00:16 RSL: Gruppe 0, Index 1, Befehl POWER, Daten off
00:00:16 MQT: stat/TEST/RESULT = {"POWER":"OFF"}
00:00:16 MQT: stat/TEST/POWER = OFF
00:00:16 SRC: MQTT
00:00:16 RSL: Gruppe 0, Index 1, Befehl POWER, Daten off
00:00:17 MQT: stat/TEST/RESULT = {"POWER":"OFF"}
00:00:17 MQT: stat/TEST/POWER = OFF

Every Command seems to result in a double publishing ??

from umqttbroker.

martin-ger avatar martin-ger commented on June 19, 2024

Could you try to flash my https://github.com/martin-ger/esp_mqtt ?

It is the same core as the uMQTTBroker and you have much more debugging features. Especially you can see all subscriptions with "show mqtt" on the serial console. My guess is still, that the client has two subscriptions that match the topic.

from umqttbroker.

HoerMirAuf avatar HoerMirAuf commented on June 19, 2024

Hmmm ... i would, but i'm not familiar with NONOS_SDK or the esp-open-sdk.
I'm just a novice with a basic knowledge in Arduino IDE.

My Goal was to get a MQTT Broker/Repeater working on a cheap Sonoff Basic Device.
I got it running for up to 10 tcp/mqtt connectionsc/clients. The only Problem is the douple publishing.

This will not happen with a mosquitto broker ... it also could be the mosquitto Broker subpress this douple publishing ... look's like QOS thing ....

from umqttbroker.

martin-ger avatar martin-ger commented on June 19, 2024

The esp_mqtt includes binaries - no need to compile it - just flashing required.

QoS might be an issue - uMQTTBroker just suports QoS 0. QoS 1 or 2 might be undefined.

from umqttbroker.

HoerMirAuf avatar HoerMirAuf commented on June 19, 2024

Hi martin-ger.

Thank you very much for your patience and your help !!!

I was playing around with the Tasmota MQTT settings and found the Problem.... and .. your are right !!

In Tasmota it's possible die give a MQTT Topic Name and there are also a MQTT "Full-Topic" Name.
If the "Full-Topic" keep empty it will generated from a prefix AND the Topic.
So, there is a subscribtion with the same content parts twice !

Changing the "Full-Topic" Part to the right content and not the "Topic" your uMQTTBroker works fantastic.

The courios ... with other Brokers like IOBroker or Mosquitto this settings wasn't neccessary.

just flashing required.

... hmm will give them a try, but it is possible on a 1MB flash Memory??

from umqttbroker.

martin-ger avatar martin-ger commented on June 19, 2024

Maybe we are interpreting the MQTT spec differently - maybe I am wrong and it should be delivered just once in such a case - have to dig a bit.

The esp_mqtt will work on 1 MB - I usually ran it on a Sonoff. However, if the Arduino version is fine for you and you don't need the additional features there, there is nothing wrong with it. The MQTT lib is the same.

from umqttbroker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.