user42496: I am trying to convert byte* value to int here is how I have it. 
void mqttCallback(char* topic, byte* payload, unsigned int length) {

  String topicStr = topic;
  int* payload_value;
  int updates_cal;

    payload_value = (int*)payload;
    //updates_cal = *payload_value;


    Serial.print((int)payload_value);


  delay(1);

  Serial.println();
  Serial.println("-----------------------");

}

I am getting MQTT payload as Integer value. Which I want to receive in my NodeMCU (ESP8266).
Is there any way to do this? 
Thank you! 

user60288: Don't know if you found an answer yet, but I had the exact same issue and eventually came up with this:
   payload[length] = '\0'; // Add a NULL to the end of the char* to make it a string.
   int aNumber = atoi((char *)payload);

Pretty simple in the end!

user55899: Judging by the comments, you are actually receiving your integer data as text, as a sequence of ASCII characters. This is what you send yourself using mosquitto_pub. The buffer is apparently not zero-terminated.
If these characters represent an integer value, then the way to retrieve it as an integer value would be 
char buffer[128];

// Make sure here that `length` is smaller than the above buffer size. 
// Otherwise, you'd need a bigger buffer

// Form a C-string from the payload
memcpy(buffer, payload, length);
buffer[length] = '\0';

// Convert it to integer
char *end = nullptr;
long value = strtol(buffer, &end, 10);

// Check for conversion errors
if (end == buffer || errno == ERANGE)
  ; // Conversion error occurred
else
  Sterial.println(value);


Another approach, which avoids using a separate large[ish] buffer just for the purposes of zero-termination, would be
// Build a `scanf` format string that will read no more than `length`
// characters without relying on zero-termination of the payload
char format[16];
snprintf(format, sizeof format, "%%%ud", length);

// Convert the payload
int payload_value = 0;
if (sscanf((const char *) payload, format, &payload_value) == 1)
  Serial.println(payload_value);
else
  ; // Conversion error occurred

However, this approach is less protected from integer overflow than the previous one.

Note that most of the above "jumping through the hoops" is dedicated to adding a zero-terminator to the input buffer. If instead you opt for ensuring zero-termination on the sender's side, then it would all reduce to a simple
// Convert C-string to integer
char *end = nullptr;
long value = strtol((const char *) payload, &end, 10);

// Check for conversion errors
if (end == buffer || errno == ERANGE)
  ; // Conversion error occurred
else
  Sterial.println(value);

No extra buffers required.

42496: <p>I am trying to convert <code>byte*</code> value to <code>int</code> here is how I have it. </p>

<pre><code>void mqttCallback(char* topic, byte* payload, unsigned int length) {

  String topicStr = topic;
  int* payload_value;
  int updates_cal;

    payload_value = (int*)payload;
    //updates_cal = *payload_value;


    Serial.print((int)payload_value);


  delay(1);

  Serial.println();
  Serial.println("-----------------------");

}
</code></pre>

<p>I am getting MQTT payload as Integer value. Which I want to receive in my NodeMCU (ESP8266).</p>

<p>Is there any way to do this? </p>

<p>Thank you! </p>
 60288: <p>Don't know if you found an answer yet, but I had the exact same issue and eventually came up with this:</p>

<pre><code>   payload[length] = '\0'; // Add a NULL to the end of the char* to make it a string.
   int aNumber = atoi((char *)payload);
</code></pre>

<p>Pretty simple in the end!</p>
 55899: <p>Judging by the comments, you are actually receiving your integer data as text, as a sequence of ASCII characters. This is what you send yourself using <code>mosquitto_pub</code>. The buffer is apparently not zero-terminated.</p>

<p>If these characters represent an integer value, then the way to retrieve it as an integer value would be </p>

<pre><code>char buffer[128];

// Make sure here that `length` is smaller than the above buffer size. 
// Otherwise, you'd need a bigger buffer

// Form a C-string from the payload
memcpy(buffer, payload, length);
buffer[length] = '\0';

// Convert it to integer
char *end = nullptr;
long value = strtol(buffer, &amp;end, 10);

// Check for conversion errors
if (end == buffer || errno == ERANGE)
  ; // Conversion error occurred
else
  Sterial.println(value);
</code></pre>

<hr>

<p>Another approach, which avoids using a separate large[ish] buffer just for the purposes of zero-termination, would be</p>

<pre><code>// Build a `scanf` format string that will read no more than `length`
// characters without relying on zero-termination of the payload
char format[16];
snprintf(format, sizeof format, "%%%ud", length);

// Convert the payload
int payload_value = 0;
if (sscanf((const char *) payload, format, &amp;payload_value) == 1)
  Serial.println(payload_value);
else
  ; // Conversion error occurred
</code></pre>

<p>However, this approach is less protected from integer overflow than the previous one.</p>

<hr>

<p>Note that most of the above "jumping through the hoops" is dedicated to adding a zero-terminator to the input buffer. If instead you opt for ensuring zero-termination on the sender's side, then it would all reduce to a simple</p>

<pre><code>// Convert C-string to integer
char *end = nullptr;
long value = strtol((const char *) payload, &amp;end, 10);

// Check for conversion errors
if (end == buffer || errno == ERANGE)
  ; // Conversion error occurred
else
  Sterial.println(value);
</code></pre>

<p>No extra buffers required.</p>
