GithubHelp home page GithubHelp logo

Comments (4)

LiamBindle avatar LiamBindle commented on May 27, 2024

@wyx087 Thanks for raising the issue. The examples are just meant to be simple demos of how to get started, but I wasn't aware the subscriber gives extra characters some times—do you know why? To me it looks like the null-character should be included in the payload:

mqtt_publish(&client, topic, application_message, strlen(application_message) + 1, MQTT_PUBLISH_QOS_0);

from mqtt-c.

learn-more avatar learn-more commented on May 27, 2024

The problem is most likely that not all publishers do this.
The default samples continue sessions from others, so he might be looking at that

from mqtt-c.

LiamBindle avatar LiamBindle commented on May 27, 2024

That's a good point. @wyx087 did you modify simple_publisher.c? If you're using simple_subscriber.c out-of-the-box on a common testing broker like https://test.mosquitto.org, the topic name is "datetime" so it's possible other peoples' publishes to "datetime" are coming back to you.

Regardless, I don't think this is a bug, but @wyx087 your approach using application_message_size is what you should be doing.

I'm going to close this issue but feel free to reopen

from mqtt-c.

wyx087 avatar wyx087 commented on May 27, 2024

I agree, it's not a bug for the core program. The purpose of this post is just to make you aware that the examples could use some form of length limiter. Hopefully will save other novices like me from some head-scratching.

Quite possibly the problem lies with my publisher. But monitoring with Home Assistant MQTT doesn't reproduce this. Equally, HA could have implemented length limiter.

Here is debug output from my program, which is adopted from your reconnect_subscriber example.
Publisher is https://github.com/emoncms/emoncms
First print shows message as shown by your example. Second print uses the sprintf I posted earlier.

Received publish('power/export'): 06.74power/usage226.74power/usage227.22
Received publish('power/export'): '0'
Received publish('power/solar'): -00
Received publish('power/solar'): '-0'
Received publish('power/usage'): 228.86power/usage228.86power/usage227.22
Received publish('power/usage'): '228.86'

Received publish('power/export'): 06.86power/usage206.86power/usage206.86
Received publish('power/export'): '0'
Received publish('power/solar'): -00
Received publish('power/solar'): '-0'
Received publish('power/usage'): 207.8
                                      power/usage207.86power/usage206.86
Received publish('power/usage'): '207.8'

This was recorded at nearly 9pm, export value should be solid 0. The 06.74 value throws off some calculations I do later.

from mqtt-c.

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.