Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a project regarding health monitoring, I used NodeMCU esp8266 device and ad8232 for ecg and also max30102 for spo2 and bpmI wanted to display these three variables on ubidots using wifi but the platform says there is no information “no found information” , If you have only one variable, ecg for example, the platform responds and displays the chart. But it does not respond if I want to work with the three variables. please help if the error is in the code. this is the code for

What I have tried:

declare variables:
<code>
#define DEVICE_LABEL "monitoring" // Put the device label
#define VARIABLE_LABEL_1 "ecgmoy" // Put the variable label
#define VARIABLE_LABEL_2 "spo2" // Put the variable label
#define VARIABLE_LABEL_3 "heartRate" // Put the variable label</code>

and for send and display :

    <code> dtostrf(ecgmoy, 4, 2, str_val_1);
       dtostrf(spo2, 4, 2, str_val_2);
       dtostrf(heartRate, 4, 2, str_val_3);
    sprintf(topic, "%s", ""); // Cleans the topic content
    sprintf(topic, "%s%s", "/v1.6/devices/", DEVICE_LABEL); 
    sprintf(payload, "%s", ""); // Cleans the payload content
     sprintf(payload, "{\"%s\":", VARIABLE_LABEL_1); // Adds the variable label
    sprintf(payload, "%s {\"value\": %s}", payload, str_val_1); // Adds the value
    sprintf(payload, "{\"%s\":", VARIABLE_LABEL_2); // Adds the variable label
   sprintf(payload, "%s {\"value\": %s}", payload, str_val_2); // Adds the value
   sprintf(payload, "%s, \"%s\":", payload, VARIABLE_LABEL_3); // Adds the variable label
   sprintf(payload, "%s {\"value\": %s}", payload, str_val_3); // Adds the value
    sprintf(payload, "%s}", payload); // Closes the dictionary brackets
    Serial.println("Publishing data to Ubidots Cloud");
    client.publish(topic, payload);
    client.loop();  
    delay(10);   
    }</code>
    

please help !
Posted
Updated 7-Oct-21 5:34am

1 solution

Not necessarily the problem, but the code lines like
C
sprintf(payload, "%s blah blah blah", payload)
are not guaranteed to do what you expect. The input and output buffers should not overlap. When compiling with gcc 10 it warns me
warning: ‘sprintf’ argument 3 overlaps destination object ‘payload’ [-Wrestrict]
Since all your format strings are string types ("%s"), look at using strcat instead. For better performance, you could look at stpcpy(), if your platform supports it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900