MQTT updating 2 items

I have an ESP8266 reading temperature and voltage and trying to publish both to OpenHAB2.2 items.

These are the ESP relevant defines:

#define temperature_topic "sensor/temperature"
#define voltage_topic "sensor/voltage"

and the 2 publish commands:

client.publish(temperature_topic, String(temp).c_str(), true);
client.publish(voltage_topic, String(vdd).c_str(), true);

I defined 2 items:

Number WiFiTemperatureSensor "Temperature [%.2f °C]" {mqtt="<[mosquitto:sensor/temperature:state:default]"}
Number WiFiVoltage "Voltage [%.2f V]" {mqtt="<[mosquitto:sensor/voltage:state:default]"}

now I am struggling to figure why only the Temperature item is being updated.
If I comment out the first publish for temperature, i get the voltage published successfully.
I am new to this so I may be missing some obvious system misunderstanding.
What am I doing wrong?

This could be a long shot, but have you tried to have a short pause between publishing values from 8266?

I already have some pause. Here is the complete loop function:

  float temp = sensors.getTempCByIndex(0);
  Serial.println(temp); 
  if (!client.connected()) {
    reconnect();
  }
  delay(50);
  client.publish(temperature_topic, String(temp).c_str(), true);
  
  float vdd = ESP.getVcc() / 1000.0;
  Serial.print("Vdd: ");
  Serial.println(vdd);
  if (!client.connected()) {
    reconnect();
  }
  delay(50);
  client.publish(voltage_topic, String(vdd).c_str(), true);

  Serial.println("Goint to Sleep!");
  ESP.deepSleep(deepSleep);

hmmmm, have you set the log level of the MQTT binding to TRACE in Karaf to see if you get any more information?

Is this the correct command?

log:set TRACE org.openhab.binding.mqtt

It seems right, and then log:tail to see “real” time what is happening when publishing messages

The log shows nothing about mqtt and the voltage being updated.
Only the temperature.

12:51:15.873 [INFO ] [smarthome.event.ItemStateChangedEvent] - WiFiTemperatureSensor changed from 21.00 to 21.50

Bummer !! … I would think the problem is somewhere between the 8266 and the broker, but this is a tricky one. This is yet another shot in the dark, but what happens if you publish more than two messages in a short time span (50 ms). Still only get the first message “through” or something else? What happens if you have really long pauses between messages (like 1000 ms or more)? Have you checked your messaging in a tool like mqtt-spy or similar?

Thanks for the suggestion to use mqtt-spy.
I use it to publish both topics and see the items getting updated in the karaf log. However, and I think it is intentional, when publishing the same value more than once, the openhab item does not show it is getting updated in the log.
I modified the ESP code and put the voltage topic to publish first and now only this topic is updating the matching item.
It is frustrating. I don’t understand why only the first topic is being updated in openhab.

void loop() {
  Serial.print("Temperature: ");
  sensors.requestTemperatures(); // Send the command to get temperatures
  // After we got the temperatures, we can print them here.
  float temp = sensors.getTempCByIndex(0);
  Serial.println(temp);  
  Serial.print("Vdd: ");
  float vdd = ESP.getVcc() / 1000.0;
  Serial.println(vdd);
  
  if (!client.connected()) {
    reconnect();
  }
  client.loop();
  delay(10);
  client.publish(voltage_topic, String(vdd).c_str());
  delay(10);
  client.publish(temperature_topic, String(temp).c_str());
  Serial.println("Goint to Sleep!");
  delay(10);
  client.disconnect();
  ESP.deepSleep(deepSleep);
}

I discovered that if I set a delay of 1 second between the first publish to the second one then both items are updated.
Very strange!
Where is it documented or explained that 2 consecutive publish events cannot be done in short time?
How can I change and configure it?
The reason is the ESP is running on battery and keeping it connected and running just doing nothing will shorten the battery time.

There is no limitation on the MQTT broker or OH side. I routinely publishs dozens of messages from a single device as fast as my python script can run.

I would guess the limitation is either on the ESP side or the network is spotty or something like that is going on.

not a solution to your problem, but I would use JSON for simultaneous sending both temperature and voltage.