Using ESP8266 to publish serial input to MQTT [Solved]

Hi ,
I have a whispernode (RFradio) receiving a message from another whisper node and sending it to the serial port on an ESP8266. The radio is connected to TX, RX on ESP. I then want the incoming message on the ESP to be published to an MQTT topic. The message is similar to "63:0:2900".
The first part works ok, i.e. I can serial.print the message to the console, and initiate an MQTT topic, but there is nothing displayed as the payload when I subscribe to the topic using MQTT.fx or similar.
I suspect the message is not in the correct format/array for the publish command.
Here is the complete code. Any help would be awesome,

thanks

//#include <ESP8266wifi.h>

//#include <OneWire.h>
//#include <DallasTemperature.h>
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <SPI.h>
#include <stdlib.h>


const char* ssid = "xxx";
const char* password = "xxx";

IPAddress server(192, 168, 1, 117);     //Site Specific  ...........................................
WiFiClient WifiClient;

PubSubClient client(server, 1883, WifiClient);
unsigned long keepalivetime = 0;
unsigned long MQTT_reconnect = 0;
#define MQTT_CLIENT_ID ""
#define MQTT_RETRY 500

void reconnect() {
  // Loop until we're reconnected
  while (!client.connected()) {
    Serial.print("Attempting MQTT connection...");
    // Attempt to connect
    if (client.connect(MQTT_CLIENT_ID)) {
      Serial.println("connected");
      // Once connected, publish an announcement...
      client.publish("talk/heart", "beat");
      // ... and resubscribe
      client.subscribe("talk/reset");
      //Can subscribe to Out relay Aux Here
    } else {
      Serial.print("failed, rc=");
      Serial.print(client.state());
      Serial.println(" try again in 5 seconds");
      // Wait 5 seconds before retrying
      delay(5000);
    }
  }
}

unsigned long beat_time;

int i, messageLength;
void setup() {
  // Start serial
  Serial.begin(115200);


  WiFi.begin(ssid, password);
  while (WiFi.waitForConnectResult() != WL_CONNECTED) {
    Serial.println("Connection Failed! Rebooting...");
    delay(5000);
    ESP.restart();
  }
  
}

void loop() {
  // String stringVal = "";
  client.loop();
  reconnect();
  //heart beat
  unsigned long time_passed = 0;
  time_passed = millis() - beat_time;
  if (time_passed < 0)
  {
    beat_time = millis();
  }
  //360000
  if (time_passed > 30000)
  {
    time_passed = 0;
    Serial.println("heart beat");
    client.publish("talk/heart", "1");
    delay(500);
    client.publish("talk/heart", "0");
    beat_time = millis();

  }
  //Listen for begin of message
  if (Serial.read() == '

)
  {

char Message[100];

for (i = 1; i < 100; i++)
    {
      delay(1);
      Message[i] = Serial.read();
      if (Message[i] == '#')
      {
        break;
      }

}

//length of the message
    messageLength = i;

Serial.println("The incoming message is:");

for (i = 1; i < messageLength; i++)
    {
      Serial.print((Message[i]));

}

Serial.println();

//Publish mesaage to MQTT

client.publish("Talk", Message);

}

}

I tried
reading your code,
but I got too
dizzy with the piss-poor
indenting.

Use Tools + Auto Format and post the code again, if you want any to try to read it.

You're too polite mate.
When you've pick yourself up off the floor from your dizzy spell... any ideas on the code problem...

The PubSubClient class has several publish() methods. The one that you are using is:

boolean publish(const char* topic, const char* payload);

That means that the function takes two strings.

    client.publish("Talk", Message);

"Talk" is a string. Message is NOT.

A string is a NULL terminated array of chars. Your array of chars is NOT NULL terminated, so it is NOT a string.

Thanks mate, that did the trick!