# Can not get data from Ubidots using particle electron

**URL:** <https://community.particle.io/t/can-not-get-data-from-ubidots-using-particle-electron/45704>\
**Category:** Troubleshooting\
**Created:** [November 29, 2018, 10:09am UTC](https://community.particle.io/t/can-not-get-data-from-ubidots-using-particle-electron/45704 "2018-11-29T10:09:49Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![majj\_11](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/majj_11/32/21851_2.png) [@majj\_11](https://community.particle.io/u/majj_11)\
**Post date:** [November 29, 2018, 10:09am UTC](https://community.particle.io/t/can-not-get-data-from-ubidots-using-particle-electron/45704/1 "2018-11-29T10:09:49Z")

</div>

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](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/f/1/f10aa5629de486baed926c887f676c8b163b9d45.png)

 ![U1](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/9/7/979763e5ece8cd0bca2e577d1722902a137e49d4.PNG)

---

<div class="post-metadata">

**Author:** ![Moors7](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/moors7/32/588_2.png) [@Moors7](https://community.particle.io/u/Moors7)\
**Post date:** [November 29, 2018, 10:32am UTC](https://community.particle.io/t/can-not-get-data-from-ubidots-using-particle-electron/45704/2 "2018-11-29T10:32:37Z")

</div>

> [@majj\_11](#):
>
> I use this code before

What code?

---

<div class="post-metadata">

**Author:** ![majj\_11](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/majj_11/32/21851_2.png) [@majj\_11](https://community.particle.io/u/majj_11)\
**Post date:** [November 29, 2018, 10:37am UTC](https://community.particle.io/t/can-not-get-data-from-ubidots-using-particle-electron/45704/3 "2018-11-29T10:37:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![majj\_11](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/majj_11/32/21851_2.png) [@majj\_11](https://community.particle.io/u/majj_11)\
**Post date:** [November 29, 2018, 10:44am UTC](https://community.particle.io/t/can-not-get-data-from-ubidots-using-particle-electron/45704/4 "2018-11-29T10:44:43Z")

</div>

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’

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [November 29, 2018, 10:53am UTC](https://community.particle.io/t/can-not-get-data-from-ubidots-using-particle-electron/45704/5 "2018-11-29T10:53:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![majj\_11](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/majj_11/32/21851_2.png) [@majj\_11](https://community.particle.io/u/majj_11)\
**Post date:** [November 29, 2018, 12:08pm UTC](https://community.particle.io/t/can-not-get-data-from-ubidots-using-particle-electron/45704/6 "2018-11-29T12:08:57Z")

</div>

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 )

---

<div class="post-metadata">

**Author:** ![jotathebest](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/jotathebest/32/13895_2.png) [@jotathebest](https://community.particle.io/u/jotathebest)\
**Post date:** [November 29, 2018, 11:09pm UTC](https://community.particle.io/t/can-not-get-data-from-ubidots-using-particle-electron/45704/7 "2018-11-29T23:09:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [December 4, 2018, 8:07am UTC](https://community.particle.io/t/can-not-get-data-from-ubidots-using-particle-electron/45704/8 "2018-12-04T08:07:13Z")

</div>

> [@majj\_11](#):
>
> 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’

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()`.

---

<div class="post-metadata">

**Author:** ![mariahernandez](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/mariahernandez/32/24529_2.png) [@mariahernandez](https://community.particle.io/u/mariahernandez)\
**Post date:** [December 4, 2018, 4:29pm UTC](https://community.particle.io/t/can-not-get-data-from-ubidots-using-particle-electron/45704/9 "2018-12-04T16:29:22Z")

</div>

As my colleague @jotathebest, creator of the [Particle Library](https://github.com/ubidots/ubidots-particle) for [Ubidots](http://ubidots.com) 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.

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [December 4, 2018, 4:37pm UTC](https://community.particle.io/t/can-not-get-data-from-ubidots-using-particle-electron/45704/10 "2018-12-04T16:37:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mannydeleon99](https://avatars.discourse-cdn.com/v4/letter/m/77aa72/32.png) [@mannydeleon99](https://community.particle.io/u/mannydeleon99)\
**Post date:** [December 19, 2018, 3:31am UTC](https://community.particle.io/t/can-not-get-data-from-ubidots-using-particle-electron/45704/11 "2018-12-19T03:31:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jotathebest](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/jotathebest/32/13895_2.png) [@jotathebest](https://community.particle.io/u/jotathebest)\
**Post date:** [December 20, 2018, 10:33pm UTC](https://community.particle.io/t/can-not-get-data-from-ubidots-using-particle-electron/45704/12 "2018-12-20T22:33:08Z")

</div>

Hi @mannydeleon99, from the [library docs](https://github.com/ubidots/ubidots-particle), the `send()` method accepts both device label and name parameter, you should use TCP and set the device (datasource) name as follows:

```auto
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

---

<div class="post-metadata">

**Author:** ![mannydeleon99](https://avatars.discourse-cdn.com/v4/letter/m/77aa72/32.png) [@mannydeleon99](https://community.particle.io/u/mannydeleon99)\
**Post date:** [December 20, 2018, 10:52pm UTC](https://community.particle.io/t/can-not-get-data-from-ubidots-using-particle-electron/45704/13 "2018-12-20T22:52:13Z")

</div>

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

```auto
// 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;
      }
}

```

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [December 20, 2018, 11:09pm UTC](https://community.particle.io/t/can-not-get-data-from-ubidots-using-particle-electron/45704/14 "2018-12-20T23:09:55Z")

</div>

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

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

```

or the “converter” method

```cpp
ubidots.send(someString.c_str());

```

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

---

<div class="post-metadata">

**Author:** ![jotathebest](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/jotathebest/32/13895_2.png) [@jotathebest](https://community.particle.io/u/jotathebest)\
**Post date:** [December 21, 2018, 3:04am UTC](https://community.particle.io/t/can-not-get-data-from-ubidots-using-particle-electron/45704/15 "2018-12-21T03:04:06Z")

</div>

> [@mannydeleon99](#):
>
> const char \* device\_label = "WaterMark1";

Hi, I think that changing this

```auto
const char * device_label = "WaterMark1";

```

to

```auto
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:

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

```

All the best

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [December 21, 2018, 4:56am UTC](https://community.particle.io/t/can-not-get-data-from-ubidots-using-particle-electron/45704/16 "2018-12-21T04:56:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mannydeleon99](https://avatars.discourse-cdn.com/v4/letter/m/77aa72/32.png) [@mannydeleon99](https://community.particle.io/u/mannydeleon99)\
**Post date:** [December 21, 2018, 4:06pm UTC](https://community.particle.io/t/can-not-get-data-from-ubidots-using-particle-electron/45704/17 "2018-12-21T16:06:35Z")

</div>

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

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

```

and

```auto
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

```auto
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

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [December 21, 2018, 4:40pm UTC](https://community.particle.io/t/can-not-get-data-from-ubidots-using-particle-electron/45704/18 "2018-12-21T16:40:08Z")

</div>

> [@mannydeleon99](#):
>
> Also I cant particle.publish float data, is what im assuming because I get error messages.

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

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

```

> [@mannydeleon99](#):
>
> 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.

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.

---

<div class="post-metadata">

**Author:** ![jotathebest](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/jotathebest/32/13895_2.png) [@jotathebest](https://community.particle.io/u/jotathebest)\
**Post date:** [December 28, 2018, 3:02pm UTC](https://community.particle.io/t/can-not-get-data-from-ubidots-using-particle-electron/45704/19 "2018-12-28T15:02:10Z")

</div>

Hi there,

> [@mannydeleon99](#):
>
> 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?

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

```auto
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.

> [@ScruffR](#):
>
> 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

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

All the best
