Closed rayterrill closed 7 years ago
maybe like following.
// client.publish("rayterrill/feeds/moisture",(uint8_t)sensorValue,4);
client.publish("rayterrill/feeds/moisture",(uint8_t *)&sensorValue, sizeof(sensorValue));
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.
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));
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.
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.
Hi @rayterrill , can you work on Photon with MQTT? I will close this issue.
Sure. Go ahead and close. Thanks for the help!
On Sun, Aug 28, 2016 at 9:41 PM -0700, "Hirotaka" notifications@github.com 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.
Having a heck of a time trying to use the MQTT library in Particle with integer values coming off of a moisture sensor.
Veryfing code using this library in Particle Build fails with this error: