INT vs. double - INT variable type not accepted?


#1

When I switch from double variable type to INT my data stops being accepted by ubidots. When I switch back to double everything works again. The only difference is the variable type declaration. Am I missing something?

// This #include statement was automatically added by the Particle IDE.
#include "Ubidots/Ubidots.h"

// This #include statement was automatically added by the Particle IDE.
#include "Adafruit_DHT/Adafruit_DHT.h"

//token for ubidots
#define TOKEN "abc123abc123abc123abc123" 

#define DHT1PIN 2                               // fridge temp
#define DHT2PIN 4                               // internal temp

#define DHTTYPE DHT22                           // DHT 22 (AM2302)

Ubidots ubidots(TOKEN);

DHT dhtFridge(DHT1PIN, DHTTYPE);
DHT dhtInternal(DHT2PIN, DHTTYPE);

// Define variables
double fridgeTemp = 0;
double internalTemp = 0;
double fridgeHumid = 0;
double internalHumid = 0;

void setup()
{
  Particle.variable("fridgeT", fridgeTemp);     //make fridge temps avail via var
  Particle.variable("internalT", internalTemp); //make internal temps avail via var
  dhtFridge.begin();
  dhtInternal.begin(); 
  Serial.begin(9600);
  delay(10000);
   } 

void loop()
{
  //Read humidity into humidity vars  
  fridgeHumid = dhtFridge.getHumidity();
  internalHumid= dhtInternal.getHumidity();

  //Read Farenheit into Temp vars
  fridgeTemp = dhtFridge.getTempFarenheit();
  internalTemp = dhtInternal.getTempFarenheit();
  
  ubidots.add("fridgeTemp", fridgeTemp);	    //define fridgeTemp as ubidot var
  ubidots.add("internalTemp", internalTemp);	//define interalTemp as ubidot var
  ubidots.sendAll();                            //send vars to ubidot
  delay(60000);                                 //delay sixty sec

  // Publish temp var for reading remotely
  Particle.publish("fridgeTemp", String(fridgeTemp) + " °F");
  Particle.publish("internalTemp", String(internalTemp) + " °F");
}

#2

Hello @OBSteve,

This happens because the variable value is declared as double on our the library. If you take a look to the file “ubidots.h”, on the ubidots class you will find this public declaration.

void add(char *variable_id, double value);

Btw, we release a new version of the library if you don’t have it yet, update it (version 2.1.9).

Regards.
Maria C


#3

So, do I understand you to mean the INT var type wont work? Or will it with some hacking of the .h file? Or does the new lib fix the issue?
Thanks for the reply


#4

Hey @OBSteve,

I tested sending a int variable type, and I didn’t have any issue sending data to Ubidots. Look!


// This #include statement was automatically added by the Particle IDE.
#include <Ubidots.h>

  int fridgeTemp = 12345;
  int internalTemp = 67890;
//token for ubidots
#define TOKEN "9DriKmYujOJZ2x637376xbFtaSLvq0" 

Ubidots ubidots(TOKEN);

void setup()
{
  Serial.begin(9600);
  delay(10000);
   } 

void loop()
{
  ubidots.add("fridgeTemp", fridgeTemp);	    //define fridgeTemp as ubidot var
  ubidots.add("internalTemp", internalTemp);	//define interalTemp as ubidot var
  ubidots.sendAll();                            //send vars to ubidot
  delay(1000);                                 //delay sixty sec
}

So, update the library to the new version and try again!