Giter VIP home page Giter VIP logo

Comments (7)

hirotakaster avatar hirotakaster commented on September 18, 2024

maybe like following.

// client.publish("rayterrill/feeds/moisture",(uint8_t)sensorValue,4);
client.publish("rayterrill/feeds/moisture",(uint8_t *)&sensorValue, sizeof(sensorValue));

from mqtt.

rayterrill avatar rayterrill commented on September 18, 2024

I'm still getting garbage even with that code.

I looked at the Adafruit MQTT library, and they've got a publish declaration that allow for an int value, as in this:
bool Adafruit_MQTT_Publish::publish(int32_t i) { char payload[12]; ltoa(i, payload, 10); return mqtt->publish(topic, payload, qos); }

I incorporated some similar char coercing logic into my publish, and I'm indeed now able to publish data using this libraries char publish declaration. I just can't get it to work at all with the unit8_t declaration.

from mqtt.

hirotakaster avatar hirotakaster commented on September 18, 2024

Do you want to use char or int type in publish? If you want to use char, you can do like this.

char publishData[120];
sprintf(publishData, "%d", 10);
client.publish("rayterrill/feeds/moisture", publishData, strlen(publishData));

or If you want to use int type. of course you should get published data with int type.

  client.publish("rayterrill/feeds/moisture",(uint8_t *)&sensorValue, sizeof(sensorValue));

from mqtt.

rayterrill avatar rayterrill commented on September 18, 2024

I tried it with:
client.publish("rayterrill/feeds/moisture",(uint8_t *)&sensorValue, sizeof(sensorValue));

Still getting garbage data into Arduino IO. It might just be Arduino IO, not sure.

I wanted to post as int, but char is also working.

from mqtt.

hirotakaster avatar hirotakaster commented on September 18, 2024

here is my test code.

// photon side
int sensorValue = 65; // character 'A'
void loop() {
    if (client.isConnected())
        client.loop();
    delay(1000);
    client.publish("sensor/val/", (uint8_t *)&sensorValue, sizeof(sensorValue));
    sensorValue++;
}
// mosquitto side
mosquitto_sub  -h [mosquitt_server_ipaddr] -t "sensor/val/"
A
B
C
D
E
F
...

I check works well on my Photon/mosquitto command. Check your Arduino IO side source code.

from mqtt.

hirotakaster avatar hirotakaster commented on September 18, 2024

Hi @rayterrill , can you work on Photon with MQTT? I will close this issue.

from mqtt.

rayterrill avatar rayterrill commented on September 18, 2024

Sure. Go ahead and close. Thanks for the help!

On Sun, Aug 28, 2016 at 9:41 PM -0700, "Hirotaka" [email protected] wrote:

Hi @rayterrill , can you work on Photon with MQTT? I will close this issue.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

from mqtt.

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.