I’m trying to use MQTT in it’s most crude form, just for compatibility between platforms.
I’m trying Cayenne, because I really like the iOS app integration.
ESP8266 just using…
include PubSubClient.h
include ESP8266WiFi.h
If I’d like to send a value to the dashboard, what would be the correct format?
In the DOCs section, found that we need to send it like this…
v1/username/things/clientID/data/channel
I guess it’s…
v1/MQTT username/things/clientID/data/channel
This would be the correct way of sending data to Channel 10?
I don’t know if anyone has had it compile on an ESP yet. I tried a while ago and couldn’t make it work with Cayenne. Maybe I’ll revisit it and help this cause.
Looks like you are on the right track.
One idea might be to have a local NodeRed mqtt server to aggregate all your date, and then publish it all to Cayenne through there. @adam has been successful doing this.
I’m really trying to avoid the Node, just esp8266 directly to Cayenne.
In the meantime I decided to check if the message format I was sending to Cayenne was ok, using MQTT.fx. I can authenticate correctly (mqtt.mydevices.com), but I can’t seem to be able to publish data to the dashboard.
Maybe my mqtt messages are incorrectly formatted.
The BYOT Docs say…
Send Sensor data
v1/username/things/clientID/data/channel
But then… Examples
Send Sensor Data to Channel 2⇒ PUB v1/A1234B5678C/things/0123-4567-89AB-CDEF/data/2temp,c=20.7
So I believe at this point I’m a bit confused here.
What would be the correct way? If testing from MQTT.fx, should it be quoted ,“”?
I guess I need to sort out this first step, and then move on to code the esp8266.
Thanks guys,
Cheers!
Marc
I was just showing how to send some test data through MQTT.fx, where you’d split the temp,c=20.7 part off to a different field.
I’m not familiar with the PubSub library, is that from our repo? If so I can ask one of our devs if I can’t figure it it out. I can take a look regardless if you have a link.
client.luxWrite(2, 155.55) to send the value 155.55 lux to Cayenne on MQTT Channel 2
or
client.virtualWrite(6, 17.222, "analog_sensor", "null") to pass the generic value 17.222 to MQTT Channel 6
I’m working on a table of all the supported values for those 3rd and 4th parameters for virtualWrite() since the table we have in the docs is a bit out of date/incorrect in some places. I’ll post it today or tomorrow and link it here as well.
Awesome! Let me know if you run into any trouble building those statements for other data types, that’s what I’m looking to make easier with this table I’m working on.
As promised, here is v1.0 of my completed table. I’ll likely add a few more examples/notes in the future, but this should be useful to get started with the various data types, or if you have data in a format not enumerated by our data / unit types list:
Finally, I got the esp8266 to send and receive “raw” MQTT messages using the PubSubClient library. Thanks @kreggly@adam and @rsiegel for all your help!
I believe this might be useful for anyone looking to do something similar, so I’ll leave the arduino sketch code with comments.
BTW, if anyone is willing to help me optimze the “string” generation for the actual mqtt message, you’re welcome. Cheers!
What does it do?
This sketch will attempt to connect to Cayenne MQTT server via Wifi, subscribe to a “dashboard button” topic, to turn on/off the esp8266 built in led. Also it will publish temperature readings from a Dallas DS18b20 digital temperature sensor.
In a near future, the esp8266 (NodeMCU v2) should act as a smart thermostat, controlling my central heater/boiler. It should be possible to remotely check ambient temperature and boiler status using Cayenne Dashboard and turn the heater on/off (in case I left home in a hurry!, etc.)
Hi All… Im having a similar problem, Im able to publish a fix value on CAYENNE but cannot publish the sensor actual data, I can only publish virtual (fake) values… I know this must be a basic issue but I haven’t been able to solve it… can anyone give me a hand?
Im connecting the BH1750 o my RSPI 3+, dont know much about coding but I have downloaded a code from here that works locally and makes actual readings on screen.
I’m still relatively new to Arduino and Cayenne. I’m using the pubsubclient library and trying to connect to Cayenne. this is the bit of code to connect to the cayenne server:
// Attempt to connect to the server with the ID clientID
if (cayClient.connect(clientID, username, password))
{
Serial.println(“Cayenne Connection established”);
I use the same code to connect to a local Mosquitto broker, and it works. Is there something that needs to be done to connect to Cayenne’s broker?
@adam If I’m reading it correctly, the code sample connects to the Node-RED server using the PubSubclient library, and the Node-RED server connects to the Cayenne dashboard through the flows. is there an example of using the pubsubclient to connect directly to Cayenne? Thanks!
@shramik_salgaonkar Ultimately, I’m looking at connecting to 2 different MQTT brokers from the Arduino devices. It takes input from 1 broker and updates the Cayenne dashboard thru the Cayenne MQTT broker. The cayenne mqtt client abstracts a lot of the details, and I thought using the pubsubclient would give me better control of the connections. Hope this makes sense.