Can not get data from Ubidots using particle electron

Hello,
Please check the attachment, I am facing problem as i cant see data on Ubidots , I use this code before and everything working fine but now i changed the Ubidots token and from the pictures it says no activity , any idea please?

i am using (ubidots.setDatasourceName(“Vibration_trial_111”);

Thank you

image

What code?

i meant the code that sending data already is working with me the only change is another particle electron and i deployed the code and a new ubidots account (the code has been used previously and sending data ok), now i don’t know what happen

now i updat ubidots library to last version 3.0.0 i got this error,
‘class Ubidots’ has no member named ‘setDatasourceName’
‘class Ubidots’ has no member named ‘sendAll’

IIRC, the datasource scheme has been deprecated by Ubidots.
To see how things are done now, you may need to reinvestigate the examples that come with the new library.

1 Like

just to update you,

it seems hardware problem, because i tried old particle electron and it did work, really confusing, because i opened a new particle electron V020 same as the old one i have but the colour of the labels on the particle is not white as the previous one and i get same issue,

I can see data on console but not on ubidots (it sent the mane as sources data but not variable values )

Greetings, if you post your code probably I can give you additional hints about the issue, from your image I only see that the vibration variable has a blank space, which is not allowed inside a variable label at Ubidots.

All the best

Maybe @mariahernandez can chime in here to provide a way forward.
AFAICT DatasourceName and its siblings have been deprecated and sendAll() has been “rebranded” as just send().

As my colleague @jotathebest, creator of the Particle Library for Ubidots mentioned before, if you @majj_11 provide us the code which is giving the issue we can provide additional hints to solve the issue presented.

Cheers,
Maria C.

3 Likes

Thanks @mariahernandez for the response.
Would be good if his public profile would disclose the official affiliation of @jotathebest with Ubidots.

I just came across another thread with the same issue, hence I remembered reading this thread here and came back to expand on my previous answer.

Hello, what can I use if I need to replace DatasourceName in my code.

Hi @mannydeleon99, from the library docs, the send() method accepts both device label and name parameter, you should use TCP and set the device (datasource) name as follows:

send("device-label", "device-name")

Please keep in mind that the device name will not change if it is already created at Ubidots.

All the best

1 Like

Thanks I figured that out but not the problem is that I cant send string data (?) I need to convert it to char i think??? Im somewhat new and dont know how to convert string to char. I will attached my code. I tried to convert it but it didnt work. apologize for the sloppiness. This was code taken from Vinduino

// This #include statement was automatically added by the Particle IDE.
#include <Ubidots.h>
#include <math.h>
// This #include statement was automatically added by the Particle IDE.
#define NUM_READS 11    // Number of sensor reads for filtering

#ifndef UBIDOTS_TOKEN
#define UBIDOTS_TOKEN "add your token here"
#endif

const char * device_label = "WaterMark1"; // Edit here your device label


Ubidots ubidots(UBIDOTS_TOKEN, UBI_HTTP);

typedef struct {        // Structure to be used in percentage and resistance values matrix to be filtered (have to be in pairs)
  int moisture;
  long resistance;
  double tension;
} values;



const long knownResistor = 4700;  // Constant value of known resistor in Ohms

int activeDigitalPin = 6;         // 6 or 7 interchangeably
int supplyVoltageAnalogPin;       // 6-ON: A0, 7-ON: A1
int sensorVoltageAnalogPin;       // 6-ON: A1, 7-ON: A0

int supplyVoltage;                // Measured supply voltage
int sensorVoltage;                // Measured sensor voltage


values valueOf[NUM_READS];        // Calculated moisture percentages and resistances to be sorted and filtered

int i;                            // Simple index variable


void setup() {
  // initialize serial communications at 9600 bps:
  Serial.begin(9600); 

  

  // initialize the digital pin as an output.
  // Pin 6 is sense resistor voltage supply 1
  pinMode(6, OUTPUT);    

  // initialize the digital pin as an output.
  // Pin 7 is sense resistor voltage supply 2
  pinMode(7, OUTPUT);   

  delay(200);   
}

void loop() {

  // read sensor, filter, and calculate resistance value
  // Noise filter: median filter

  for (i=0; i<NUM_READS; i++) {

    setupCurrentPath();      // Prepare the digital and analog pin values

    // Read 1 pair of voltage values
    digitalWrite(activeDigitalPin, HIGH);                 // set the voltage supply on
    delay(10);
    supplyVoltage = analogRead(supplyVoltageAnalogPin);   // read the supply voltage
    sensorVoltage = analogRead(sensorVoltageAnalogPin);   // read the sensor voltage
    digitalWrite(activeDigitalPin, LOW);                  // set the voltage supply off  
    delay(10); 

    // Calculate resistance and moisture percentage without overshooting 100
    // the 0.5 add-term is used to round to the nearest integer
    // Tip: no need to transform 0-1023 voltage value to 0-5 range, due to following fraction
    valueOf[i].resistance = long( float(knownResistor) * ( supplyVoltage - sensorVoltage ) / sensorVoltage + 0.5 );
    valueOf[i].moisture = min( int( pow( valueOf[i].resistance/31.65 , 1.0/-1.695 ) * 400 + 0.5 ) , 100 );
//	  valueOf[i].tension = round( -20 * (double(valueOf[i].resistance)/1000) * ( 1 - 0.55)); // Watermark 0 < 1 kOhm
    valueOf[i].tension = round( ( -3.213 * (double(valueOf[i].resistance)/1000) - 4.093) / ( 1 - 0.009733 * (double(valueOf[i].resistance)/1000) - 0.01205*24)); // Watermark 1 < 8 kOhm
//    valueOf[i].tension = round(-2.246 - (5.239 * (double(valueOf[i].resistance)/1000)) - 0.06756 * pow(valueOf[i].resistance/1000,2)); // Watermark > 8 kOhm
//  valueOf[i].moisture = min( int( pow( valueOf[i].resistance/331.55 , 1.0/-1.695 ) * 100 + 0.5 ) , 100 );

  }

  // end of multiple read loop

  // Sort the moisture-resistance vector according to moisture
  sortMoistures();

  // Print out median values
  //Serial.print("sensor resistance = ");
  Serial.print(valueOf[NUM_READS/2].resistance);
  Serial.print(",");
  Serial.print(valueOf[NUM_READS/2].moisture);
   Serial.print(",");
  Serial.print(valueOf[NUM_READS/2].tension);
 Serial.println ();

 String moisture =  String(valueOf[NUM_READS/2].moisture);
 String resistance =  String(valueOf[NUM_READS/2].resistance);
String tension =  String(valueOf[NUM_READS/2].tension);

int moisture_len = moisture.length() + 1;
int resistance_len = resistance.length() + 1;
int tension_len = tension.length() + 1;

char moisture1[moisture_len];
char tension1[resistance_len];
char resistance1[tension_len];

moisture.toCharArray(moisture1, moisture_len);
resistance.toCharArray(tension1, resistance_len);
tension.toCharArray(resistance1, tension_len);

Particle.publish("moisture1", moisture, PRIVATE); // publish to cloud
Particle.publish("tension1", tension, PRIVATE);
Particle.publish("resistance1", resistance, PRIVATE);

 ubidots.add("moisture", moisture1);
  ubidots.add("tension", tension1);
  ubidots.add("resistance", resistance1);



bool bufferSent = false;
  bufferSent = ubidots.send(device_label);  // Will send data to a device label that matches the device Id

  if(bufferSent){
    // Do something if values were sent properly
    Serial.println("Values sent by the device");
  }
  // delay until next measurement (msec)
  delay(10000);   

}

void setupCurrentPath() {
  if ( activeDigitalPin == 6 ) {
    activeDigitalPin = 7;
    supplyVoltageAnalogPin = A1;
    sensorVoltageAnalogPin = A0;
  }
  else {
    activeDigitalPin = 6;
    supplyVoltageAnalogPin = A0;
    sensorVoltageAnalogPin = A1;
  }
}

// Selection sort algorithm
void sortMoistures() {
  int j;
  values temp;
  for(i=0; i<NUM_READS-1; i++)
    for(j=i+1; j<NUM_READS; j++)
      if ( valueOf[i].moisture > valueOf[j].moisture ) {
        temp = valueOf[i];
        valueOf[i] = valueOf[j];
        valueOf[j] = temp;
      }
}

If you have a String object and need to pass it as char* you can use an explicit type cast

String someString = "Whatever";
ubidots.send((const char*)someString);

or the “converter” method

ubidots.send(someString.c_str());

However, I’d advise for getting rid of String completely and just stick with char[] wherever possible.

Hi, I think that changing this

const char * device_label = "WaterMark1";

to

char * device_label = "WaterMark1";

should do the trick.

Additionally, the add() method receives a char pointer for the variable label and a float type value, so instead of adding a char array value (aka moisture1) you must use a float number:

float moisture_float = (float)valueOf[NUM_READS/2].moisture;
ubidots.add("moisture", moisture_float);

All the best

Are your functions modifying the incoming strings?
If not, why are your functions demanding modifiable strings to be passed?

I appreciate you guys helping me with this. Very grateful. I tried both

float moisture_float = (float)valueOf[NUM_READS/2].moisture;
ubidots.add("moisture", moisture_float);

and

String someString = "Whatever";
ubidots.send((const char*)someString); 

And I get no error which is great but the data is not being sent to ubidots.

Im not sure how this

bool bufferSent = false;
  bufferSent = ubidots.send(device_label);  // Will send data to a device label that matches the device Id

  if(bufferSent){
    // Do something if values were sent properly
    Serial.println("Values sent by the device");
  }

works because I open a serial comm (from ardunio ide) and dont get any messages, I do get the data thought. If the data is not being sent, will I see a message there?

ScruffR - I think they are modifying the incoming string but this code was originally made by Reinier van der Lee and Theodore Kaskalis and im still trying to understand the code.

Also I cant particle.publish float data, is what im assuming because I get error messages.
Thanks again

No surprise there, Particle.publish() can only deal with strings. In order to send a float varialble I’d suggest something like this

  char evtData[32];
  snprintf(evtData, sizeof(evtData), "%.2f", 123.456);
  Particle.publish("evtName", evtData, PRIVATE);

My question was actually directed at @jotathebest about the implementation of the Ubidots library.
A function that is not supposed to modify a char* parameter should not demand a modifiable (non-const) parameter.
On the other hand if it needs to modify the parameter (e.g. char* or char[]) it is also supposed to demand the size of the buffer to know the limits (unless the potential for buffer violation is explicitly documented - e.g. sprintf() vs. snprintf()) and it would also be good practice to document why and how the parameter will be modified.

1 Like

Hi there,

you can use this method to make available debug messages through the serial port:

ubidots.setDebug(true);

the add method accepts a char pointer and a float type value, so make sure that you are using these data types.

You are right ScruffR, this is something that I will fix in the next library release.

All the best

1 Like