Sending strigs to the Dashboard


#1

Hi there:grinning:
I am using Photon, which receives a parsed string of char through the serial port from external MCU.
That string includes 8 temperature values which can be recovered and stored on 8 char variable
How to send each one of those variables to be displayed through gauges or tables in the dashboard.
What type of variable should I use with Ubidots platform?

On the other hand how Ubidots define an array of characters?

Thank you.


#2

Greetings, answering your questions:

That string includes 8 temperature values which can be recovered and stored on 8 char variable
How to send each one of those variables to be displayed through gauges or tables in the dashboard.

Ubidots stores values as time series where each value is related with a specific Unix timestamp:

imagen

If you wish to send several values for the same variable, aka temperature you will have to set the timestamp to store per each value, if not, there is no way that Ubidots know what date to use for your stored value. For sending several values in bulk, please refer to our REST API.

What type of variable should I use with Ubidots platform?

Your dots are stored in RAW variables, but you can use synthetic variables as well to process data if you need it.

On the other hand how Ubidots define an array of characters?

I do not quite understand this questions, Ubidots does not β€˜define’ char arrays, Ubidots just receives your data through TCP, UDP, HTTP or MQTT. If you rephrase this, probably I can answer your doubt.

All the best


#3

@jotathebest
Thank for your answer.
Maybe I did not explain correctly, but I have 8 float variables for temperatures values.
Those 8 values should be streamed ever 5 minutes, so I have built a string with an initializer and a delimiter
after each of those 8 float values.
I plan to send that string from external MCU over serial to the photon, once I am there using β€œstrtok” , I’ll be able to recover those float values and send them to Ubidots Dashboard. The reason for using external MCU like Cypress PSoC 5LP is because all the analog real state is inside one only chip. Photon is only a connectivity media for the internet.
Thank you again let’s see what will happen.


#4

@jotathebest

Hi again
I am wondering why Ubidots libraries don’t let me compile the function strtok.?
I am sending to the photon using Ubidots libraries the following string:
A77.99%80.35%80.15%36.72%78.31%110.97%78.33%81.27%
Those are 8 temperature values.
Using strtok I am recovering each of those temperatures like string values

Temp0 = strtok (Temp,"%");

Temp1 = strtok (NULL, β€œ%”);

Temp2= strtok (NULL, β€œ%”);

Temp3= strtok (NULL, β€œ%”);

Temp4= strtok (NULL, β€œ%”);

Temp5= strtok (NULL, β€œ%”);

Temp6= strtok (NULL, β€œ%”);

Temp7= strtok (NULL, β€œ%”);

Then I assume I can convert those values to float, in such way that they can be sent to Ubidots dashboard.

sscanf(Temp0, β€œ%f”, &value0);
sscanf(Temp1, β€œ%f”, &value1);
sscanf(Temp2, β€œ%f”, &value2);
sscanf(Temp3, β€œ%f”, &value3);
sscanf(Temp4, β€œ%f”, &value4);
sscanf(Temp5, β€œ%f”, &value5);
sscanf(Temp6, β€œ%f”, &value6);
sscanf(Temp7, β€œ%f”, &value7);

The point is that the compiler only accepts the following statement:

Temp0 = strtok (Temp,"%");

*But NOT the followings ones, so it starts to throw errors:

Temp1 = strtok (NULL, β€œ%”);

Temp2= strtok (NULL, β€œ%”);

Temp3= strtok (NULL, β€œ%”);

Temp4= strtok (NULL, β€œ%”);

Temp5= strtok (NULL, β€œ%”);

Temp6= strtok (NULL, β€œ%”);

Temp7= strtok (NULL, β€œ%”);

Thank you for some help.


#5

Greetings, strtok() is not a function or method from any of our libraries, it is a native C/C++ method, so if you are getting compiler errors probably there is something wrong with the data type that you are trying to split. This error is not related with our Particle Library.

I advise you to reference this link for more information about strtok() and how to use it.

All the best


#7

@jotathebest

Hi, I hope you spent a great weekend.
I am excited about getting my code running with the educational version.
I’m sending 8 variables to dashboard every 60 seconds.
There is an issue I would like to comment and it is that everything runs well for 2 or 3 hours.
After that time period, the dashboard page freeze and you need to refresh it.
I am posting the code here and to your convenience, I refreshing the code’s job.
Photon receive trough RX pin this string :
A78.04%81.09%80.20%36.75%78.40%111.13%78.35%81.66% β€˜\n’
The variables are unparsed, converted to float type and send to Ubidots Dashboard.
The external MCU send that string every 5 seconds so that when is time to send data to Ubidots dashboard, there are updated reading values.
If you can give me some clue about the dashboard freeze and if this is related with the code I will appreciate very much.
Her is the code, and if you have some suggestion it is gonna be welcome.
Thank you very much.


// This example is to get the last value of a variable from the Ubidots API

// This example is to save multiple variables to the Ubidots API with TCP method


/* End the srtring with '\n' */

/*  A78.04%81.09%80.20%36.75%78.40%111.13%78.35%81.66% '\n' */

//***********************  Ubidots1.4  ****************************************

/****************************************
 * Include Libraries
 ****************************************/

#include "Ubidots.h"
#include <string.h>
#include <stdio.h>
/****************************************
 * Define Constants
 ****************************************/
#define VARIABLE_ID "   "
#ifndef TOKEN
#define TOKEN "A1E-aqMXpkP85LiFUJWtmHuTLRID5X9eTc"  // Put here your Ubidots TOKEN
#endif
Ubidots ubidots(TOKEN);

void lookForIni(void);
void waitForString(void);


int Aflag;
char Temp[100]={'\0'};  
char data;

unsigned long lastvalues;// Global initialize to 0
const unsigned long Sendvalues = 60000L;
char* Temp0;
char* Temp1;
char* Temp2;
char* Temp3;
char* Temp4;
char* Temp5;
char* Temp6;
char* Temp7;



double value0;
double value1;
double value2;
double value3;
double value4;
double value5;
double value6;
double value7;

/****************************************
 * Auxiliar Functions
 ****************************************/

void waitForString() //  store the string received for external MCU
{
    
int i=0;
data=0;
unsigned long tend;
unsigned long tini = millis();

  while (Serial1.available( ) &&  data !='A')  // check for A

        { data =  Serial1.read();}

   while ( Serial1.available( )  && data!='\n' )

     {   
          Temp[i] =  Serial1.read();
         
          i++; 
          unsigned long tend = millis();
             if ((tend-tini)>20)
               { break;}
             }
/*  Sensor Read values as strings */
 
Temp0 = strtok (Temp,"%");
Temp1 = strtok (NULL, "%");
Temp2= strtok (NULL, "%");
Temp3= strtok (NULL, "%");
Temp4= strtok (NULL, "%");
Temp5= strtok (NULL, "%");
Temp6= strtok (NULL, "%");
Temp7= strtok (NULL, "%");         
         
/*Sensor  Read values as float */        
value0=atof(Temp0);
value1=atof(Temp1);
value2=atof(Temp2);
value3=atof(Temp3);
value4=atof(Temp4);
value5=atof(Temp5);
value6=atof(Temp6);
value7=atof(Temp7);

}

/****************************************
 * Main Functions
 ****************************************/

void setup() {
    
 
  Serial1.begin(57600);
  //ubidots.setDebug(true);  //Uncomment this line for printing debug messages
}

void loop() {
  unsigned long topLoop = millis(); 

    if ( (topLoop - lastvalues) >= Sendvalues) 
        { lastvalues = topLoop;
        waitForString();
        
   ubidots.add("Data0", value0);  // Change for your variable name
  ubidots.add("Data1", value1);
  ubidots.add("Data2", value2);
  ubidots.add("Data3", value3);
  ubidots.add("Data4", value4);
  ubidots.add("Data5", value5);
  ubidots.add("Data6", value6);
  ubidots.add("Data7", value7);
  
  }

   ubidots.setMethod(TYPE_TCP);  //Set to TCP the way to send data

  bool bufferSent = false;
  if(ubidots.isDirty()){  // There are stored values in buffer
    bufferSent = ubidots.sendAll();
      
         }
  
}






#8

Greetings, you should send up to 5 variables per request using our library, so your code should be:

ubidots.add("Data0", value0);  // Change for your variable name
ubidots.add("Data1", value1);
ubidots.add("Data2", value2);
ubidots.add("Data3", value3);
ubidots.add("Data4", value4);
if(ubidots.isDirty()){  // There are stored values in buffer
  bufferSent = ubidots.sendAll();
       }
ubidots.add("Data5", value5);
ubidots.add("Data6", value6);
ubidots.add("Data7", value7);
if(ubidots.isDirty()){  // There are stored values in buffer
  bufferSent = ubidots.sendAll();
       }

About your question of the dashboards, sometimes due to the load of the educational server, the TCP pool connection for the real-time subscription is restarted and you have to refresh your dashboard to make available again real-time data visualization. If this visualization is critical for you, probably an industrial account instead of an educational one is suitable for your actual application.

All the best