1
\$\begingroup\$

I want to try this project: https://how2electronics.com/iot-ecg-monitoring-ad8232-ecg-sensor-esp8266/

so I implemented the code in Arduino:


#include <ESP8266WiFi.h>
#include <PubSubClient.h>
 
#define WIFISSID "Alexahome" // Put your WifiSSID here
#define PASSWORD "12345678" // Put your wifi password here
#define TOKEN "BBFF-YKxITsj1YPeTMxw7mq8lvYFBpXnCxD" // Put your Ubidots' TOKEN
#define MQTT_CLIENT_NAME "myecgsensor" 
 
/********************************************************************************/
#define VARIABLE_LABEL "myecg" // Assing the variable label
#define DEVICE_LABEL "esp8266" // Assig the device label
 
#define SENSOR A0 // Set the A0 as SENSOR
 
char mqttBroker[] = "industrial.api.ubidots.com";
char payload[100];
char topic[150];
// Space to store values to send
char str_sensor[10];
 
/********************************************************************************/
WiFiClient ubidots;
PubSubClient client(ubidots);
 
void callback(char* topic, byte* payload, unsigned int length) {
 char p[length + 1];
 memcpy(p, payload, length);
 p[length] = NULL;
 Serial.write(payload, length);
 Serial.println(topic);
}
 
void reconnect() {
 // Loop until we're reconnected
 while (!client.connected()) {
 Serial.println("Attempting MQTT connection...");
 
 // Attemp to connect
 if (client.connect(MQTT_CLIENT_NAME, TOKEN, "")) {
 Serial.println("Connected");
 } else {
 Serial.print("Failed, rc=");
 Serial.print(client.state());
 Serial.println(" try again in 2 seconds");
 // Wait 2 seconds before retrying
 delay(2000);
 }
 }
}
 
/********************************************************************************/
void setup() {
 Serial.begin(115200);
 WiFi.begin(WIFISSID, PASSWORD);
 // Assign the pin as INPUT 
 pinMode(SENSOR, INPUT);
 
 Serial.println();
 Serial.print("Waiting for WiFi...");
 
 while (WiFi.status() != WL_CONNECTED) {
 Serial.print(".");
 delay(500);
 }
 
 Serial.println("");
 Serial.println("WiFi Connected");
 Serial.println("IP address: ");
 Serial.println(WiFi.localIP());
 client.setServer(mqttBroker, 1883);
 client.setCallback(callback); 
}
 
void loop() {
 if (!client.connected()) {
 reconnect();
 }
 
 sprintf(topic, "%s%s", "/v1.6/devices/", DEVICE_LABEL);
 sprintf(payload, "%s", ""); // Cleans the payload
 sprintf(payload, "{\"%s\":", VARIABLE_LABEL); // Adds the variable label
 
 float myecg = analogRead(SENSOR); 
 
 /* 4 is mininum width, 2 is precision; float value is copied onto str_sensor*/
 dtostrf(myecg, 4, 2, str_sensor);
 
 sprintf(payload, "%s {\"value\": %s}}", payload, str_sensor); // Adds the value
 Serial.println("Publishing data to Ubidots Cloud");
 client.publish(topic, payload);
 client.loop();
 delay(10);
}

and I can see the "Publishing data to Ubidots Cloud" messages in serial monitor being written one after another, very fast (I guess every 1ms). So it seems that data is being sent quickly, or at least, according to the code.

The problem is that the graph updates really slow in Ubidots Dashboard (like every one minute). I don't know if I should adjust the code or change some settings in Ubidots, or if there might be anything else. What can be done?

toolic
10.8k11 gold badges31 silver badges35 bronze badges
asked May 16, 2024 at 9:44
\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

You might be hitting Ubidots rate limits

How many dots can I send to Ubidots?

This says

  • An Ubidots STEM account has an API rate limit of 1 request per second per token across all devices, and up to 4,000 dots per day.

How many dots can I send with Ubidots free STEM plan?

This says

  • You can send up to 4 requests per second per token, each one can have a maximum of 10,000 bytes. This is valid across all supported protocols — HTTP, MQTT, and TCP & UDP.

You may be hitting an access rate rather than data rate limit.

Russell McMahon
155k18 gold badges222 silver badges410 bronze badges
answered May 17, 2024 at 2:05
\$\endgroup\$
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.