Good afternoon,

I am using the Arduino Library PubSubClient.

According to it is possible to send multiple sensor variables to multiple channels simultaneously using

Topic: v1/ username /things/ clientID /data/

and Payload:
“channel”: 1,
“value”: 16.4,
“type”: “temp”,
“unit”: “c”
“channel”: 2,
“value”: 75,
“type”: “rel_hum”,
“unit”: “p”
“channel”: 5,
“value”: 75,
“type”: “batt”,
“unit”: “v”

I can not get it to work. I did manage to send sigle sensor values, one at a time
Attach my code:

//WiFi global declarations
#include <WiFi.h>
const char* ssid     = "xxxx";
const char* password = "xxxx";

#include <PubSubClient.h>

//(String batcap,String tempgyro,String temp,String tilt,String batvolt,String grav,String abv, float signalstrength, String mqtt_username, String mqtt_password, String mqtt_clientid)

void pubToCayenne(String batcap,String tempgyro,String temp,String tilt,String batvolt,String grav,String abv, String  signalstrength, String mqtt_username, String mqtt_password, String mqtt_client_id)
 WiFiClient wifiClient;  //MQTT things
 PubSubClient client("", 1883,wifiClient);

 if (client.connect(mqtt_client_id.c_str(), mqtt_username.c_str(), mqtt_password.c_str())) 
  Serial.println("Connected to Cayenne");
 String topic="v1/" +mqtt_username +"/things/" +mqtt_client_id+"/data/";        
 String payload;
 payload+="{\"channel\": 0,\"value\": "+String(000)+"}";  //iTilt id number
 payload+=",{\"channel\": 1,\"value\": "+batcap+"}";
 payload+=",{\"channel\": 2,\"value\": "+tempgyro+"}";
 payload+=",{\"channel\": 3,\"value\": "+String(1.08)+"}";  //Firmware Version
 payload+=",{\"channel\": 4,\"value\": "+temp+"}";
 payload+=",{\"channel\": 5,\"value\": "+tilt+"}";
 payload+=",{\"channel\": 6,\"value\": "+batvolt+"}";
 payload+=",{\"channel\": 7,\"value\": "+grav+"}";
 payload+=",{\"channel\": 8,\"value\": "+String(65)+"}"; //pub interval
 payload+=",{\"channel\": 9,\"value\": "+String(1.055)+"}"; //original gravity
 payload+=",{\"channel\": 10,\"value\": "+abv+"}";
 payload+=",{\"channel\": 11,\"value\": "+signalstrength+"}"; 


 Serial.println("Topic: "+topic);
 Serial.println("Payload: "+payload);

void setup() {
  WiFi.begin(ssid, password);
  Serial.println("Try to connect to WiFi");

  while (WiFi.status() != WL_CONNECTED) {
  Serial.println("WiFi Connected"); 

void loop() {

Please advice.

you can use the cayenne arduino library instead GitHub - myDevicesIoT/Cayenne-MQTT-Arduino: Cayenne MQTT Arduino Library

Your topic is wrong, should be: v1/username/things/clientID/data/json as per Cayenne Docs

Tnx, I am sorted for now. The Cayenne-MQTT-Arduino library is great, but takes to long for my battery powered device which is offline most of the time.

1 Like


You can also take a look at my project here Battery Powered ESP8266 Temperature/Humidity Monitor with DHT11