Photon Cyan steady (problem in code)

Hi,
Try to use SYSTEM_THREAD(ENABLED) in your code and initialize your MQTT client like this:

MQTT client("server", 1883, callback, true); (more info about 4th par here )

also try to get rid of all of your String use snprintf() instead

example of using snprintf() on onlinegdb

#include <iostream>

using namespace std;

float Tin = 2.33897; //Tempruture 
float H = 87.45; // Humidity
int alret = 5; // Alret

const char env_template[] = "\"field1=\"%.2f,\"&field2=\"%.2f,\"&field3=\"%d";
char data[sizeof(env_template) + 32 ];

void mqttpublish() 
{
snprintf(data, sizeof(data), env_template, Tin, H, alret );   
}

int main()
{
    mqttpublish();
    cout<<"env data "<<data;

    return 0;
}

results:

1 Like