[SOLVED]Ubidots working, but code won't compile anymore

I have a couple of sensors on a board communicating with my photon over i2c. The photon sends the data to ubidots.

This has been working great for a few months, and is posting data to ubidots right now:

However, the code won’t build anymore. I don’t want to press “flash” because I don’t know what happened!

I was adding the relay shield library, and decided to do a quick verify, and got the errors below. I commented out what I added but the errors didn’t go away.

garden_sensors.cpp:264:20: warning: invalid suffix on literal; C++11 requires a space between literal and identifier [-Wliteral-suffix]
 
                    ^
garden_sensors.cpp:264:53: warning: invalid suffix on literal; C++11 requires a space between literal and identifier [-Wliteral-suffix]
 
                                                     ^
garden_sensors.cpp:281:20: warning: invalid suffix on literal; C++11 requires a space between literal and identifier [-Wliteral-suffix]
     
                    ^
garden_sensors.cpp:281:54: warning: invalid suffix on literal; C++11 requires a space between literal and identifier [-Wliteral-suffix]
     
                                                      ^
garden_sensors.cpp:298:20: warning: invalid suffix on literal; C++11 requires a space between literal and identifier [-Wliteral-suffix]
     
                    ^
garden_sensors.cpp:298:54: warning: invalid suffix on literal; C++11 requires a space between literal and identifier [-Wliteral-suffix]
     
                                                      ^
In file included from ../wiring/inc/spark_wiring.h:48:0,
                 from ./inc/application.h:36,
                 from garden_sensors.cpp:2:
In static member function 'static bool CloudClass::variable(const T&, const Types& ...) [with T = char [6]; Types = {float}]',
    inlined from 'void setup()' at garden_sensors.cpp:143:38:
../wiring/inc/spark_wiring_cloud.h:81:39: error: call to 'CloudClass::_variable' declared with attribute error: Please change the variable from type `float` to `double` for use with Particle.variable().
         return _variable(name, args...);
                                       ^

In static member function 'static bool CloudClass::variable(const T&, const Types& ...) [with T = char [9]; Types = {float}]',
    inlined from 'void setup()' at garden_sensors.cpp:144:44:
../wiring/inc/spark_wiring_cloud.h:81:39: error: call to 'CloudClass::_variable' declared with attribute error: Please change the variable from type `float` to `double` for use with Particle.variable().
         return _variable(name, args...);
                                       ^
In static member function 'static bool CloudClass::variable(const T&, const Types& ...) [with T = char [4]; Types = {float}]',
    inlined from 'void setup()' at garden_sensors.cpp:145:35:
../wiring/inc/spark_wiring_cloud.h:81:39: error: call to 'CloudClass::_variable' declared with attribute error: Please change the variable from type `float` to `double` for use with Particle.variable().
         return _variable(name, args...);
                                       ^
garden_sensors.cpp: In function 'void loop()':
garden_sensors.cpp:239:43: warning: 'data[4]' may be used uninitialized in this function [-Wmaybe-uninitialized]
         data[5] = Wire.read();
                                           ^
garden_sensors.cpp:239:34: warning: 'data[3]' may be used uninitialized in this function [-Wmaybe-uninitialized]
         data[5] = Wire.read();
                                  ^
garden_sensors.cpp:237:40: warning: 'data[1]' may be used uninitialized in this function [-Wmaybe-uninitialized]
         data[3] = Wire.read();
                                        ^
garden_sensors.cpp:237:31: warning: 'data[0]' may be used uninitialized in this function [-Wmaybe-uninitialized]
         data[3] = Wire.read();
                               ^
make[1]: *** [../build/target/user/platform-6garden_sensors.o] Error 1
make: *** [user] Error 2

Here is my code:


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


#include "HttpClient/HttpClient.h"


#include "Adafruit_TSL2591/Adafruit_TSL2591.h"
#include "Adafruit_TSL2591/Adafruit_Sensor.h"

#include <application.h>
#include <spark_wiring_i2c.h>

// SHT31 I2C address is 0x44(68)
#define Addr 0x44


//ubidots setup

#define VARIABLE_ID "56ede920762542261507ae9e"
#define VARIABLE_ID2 "56ee40fb76254256205bcdcf"
#define VARIABLE_ID3 "56ee46947625427931a1fba6"
#define TOKEN "edited-out"

 HttpClient http;
 http_header_t headers[] = {
        { "Content-Type", "application/json" },
        { NULL, NULL } // NOTE: Always terminate headers will NULL
    };

    http_request_t request;
    http_response_t response;

//end ubidots setup


//lux sensor setup:

Adafruit_TSL2591 tsl = Adafruit_TSL2591(2591); // pass in a number for the sensor identifier (for your use later)

/**************************************************************************/
/*
    Displays some basic information on this sensor from the unified
    sensor API sensor_t type (see Adafruit_Sensor for more information)
*/
/**************************************************************************/
void displaySensorDetails(void)
{
  sensor_t sensor;
  tsl.getSensor(&sensor);
  Serial.println("------------------------------------");
  Serial.print  ("Sensor:       "); Serial.println(sensor.name);
  Serial.print  ("Driver Ver:   "); Serial.println(sensor.version);
  Serial.print  ("Unique ID:    "); Serial.println(sensor.sensor_id);
  Serial.print  ("Max Value:    "); Serial.print(sensor.max_value); Serial.println(" lux");
  Serial.print  ("Min Value:    "); Serial.print(sensor.min_value); Serial.println(" lux");
  Serial.print  ("Resolution:   "); Serial.print(sensor.resolution); Serial.println(" lux");
  Serial.println("------------------------------------");
  Serial.println("");
  delay(500);
}

/**************************************************************************/
/*
    Configures the gain and integration time for the TSL2591
*/
/**************************************************************************/
void configureSensor(void)
{
  // You can change the gain on the fly, to adapt to brighter/dimmer light situations
  //tsl.setGain(TSL2591_GAIN_LOW);    // 1x gain (bright light)
  tsl.setGain(TSL2591_GAIN_MED);      // 25x gain
  // tsl.setGain(TSL2591_GAIN_HIGH);   // 428x gain

  // Changing the integration time gives you a longer time over which to sense light
  // longer timelines are slower, but are good in very low light situtations!
  tsl.setTiming(TSL2591_INTEGRATIONTIME_100MS);  // shortest integration time (bright light)
  // tsl.setTiming(TSL2591_INTEGRATIONTIME_200MS);
  // tsl.setTiming(TSL2591_INTEGRATIONTIME_300MS);
  // tsl.setTiming(TSL2591_INTEGRATIONTIME_400MS);
  // tsl.setTiming(TSL2591_INTEGRATIONTIME_500MS);
  // tsl.setTiming(TSL2591_INTEGRATIONTIME_600MS);  // longest integration time (dim light)

  /* Display the gain and integration time for reference sake */
  Serial.println("------------------------------------");
  Serial.print  ("Gain:         ");
  tsl2591Gain_t gain = tsl.getGain();
  switch(gain)
  {
    case TSL2591_GAIN_LOW:
      Serial.println("1x (Low)");
      break;
    case TSL2591_GAIN_MED:
      Serial.println("25x (Medium)");
      break;
    case TSL2591_GAIN_HIGH:
      Serial.println("428x (High)");
      break;
    case TSL2591_GAIN_MAX:
      Serial.println("9876x (Max)");
      break;
  }
  Serial.print  ("Timing:       ");
  Serial.print((tsl.getTiming() + 1) * 100, DEC);
  Serial.println(" ms");
  Serial.println("------------------------------------");
  Serial.println("");
}

// end lux sensor setup


// setup variables

float cTemp = 0.0, fTemp = 0.0, humidity = 0.0, tLux = 0.0;

void setup(void)
{
  Serial.begin(9600);

  Serial.println("Starting Adafruit TSL2591 Test!");

  if (tsl.begin())
  {
    Serial.println("Found a TSL2591 sensor");
  }
  else
  {
    Serial.println("No sensor found ... check your wiring?");
    while (1);
  }

  /* Display some basic information on this sensor */
  displaySensorDetails();

  /* Configure the sensor */
  configureSensor();



    // Set Particle variables
    Particle.variable("i2cdevice", "SHT31");
    Particle.variable("cTemp", cTemp);
    Particle.variable("humidity", humidity);
    Particle.variable("lux", tLux);
    
    
    // Initialise I2C communication as MASTER 
    Wire.begin();
    // Initialise serial communication, set baud rate = 9600
    

    Serial.begin(9600);
}


/*
void advancedRead(void)
{
  // More advanced data read example. Read 32 bits with top 16 bits IR, bottom 16 bits full spectrum
  // That way you can do whatever math and comparisons you want!
  uint32_t lum = tsl.getFullLuminosity();
  uint16_t ir, full;
  ir = lum >> 16;
  full = lum & 0xFFFF;
  Serial.print("[ "); Serial.print(millis()); Serial.print(" ms ] ");
  Serial.print("IR: "); Serial.print(ir);  Serial.print("  ");
  Serial.print("Full: "); Serial.print(full); Serial.print("  ");
  Serial.print("Visible: "); Serial.print(full - ir); Serial.print("  ");
  Serial.print("Lux: "); Serial.println(tsl.calculateLux(full, ir));
  float tLux = (tsl.calculateLux(full, ir));
  Particle.publish("Lux: ",  String(tLux));
  delay(300);
  
}
*/


void loop(void)
  {
    
  // displaySensorDetails();
  
  
  // lux calculations
  
  uint32_t lum = tsl.getFullLuminosity();
  uint16_t ir, full;
  ir = lum >> 16;
  full = lum & 0xFFFF;
  Serial.print("[ "); Serial.print(millis()); Serial.print(" ms ] ");
  Serial.print("IR: "); Serial.print(ir);  Serial.print("  ");
  Serial.print("Full: "); Serial.print(full); Serial.print("  ");
  Serial.print("Visible: "); Serial.print(full - ir); Serial.print("  ");
  Serial.print("Lux: "); Serial.println(tsl.calculateLux(full, ir));
  float tLux = (tsl.calculateLux(full, ir));
  delay(300);
  
  
  
  
  //advancedRead();

  
   // Start I2C Transmission
   Wire.beginTransmission(Addr);
   // Send 16-bit command byte          
   Wire.write(0x2C);
   Wire.write(0x06);
   // Stop I2C transmission
   Wire.endTransmission();
   delay(500);

    unsigned int data[6];
    // Start I2C Transmission
    Wire.beginTransmission(Addr);
    // Stop I2C Transmission
    Wire.endTransmission();
    
    // Request 6 bytes of data from the device
    Wire.requestFrom(Addr,6);
    
    // Read 6 bytes of data
    // temp msb, temp lsb, crc, hum msb, hum lsb, crc
    if(Wire.available() == 6)
    {
        data[0] = Wire.read();
        data[1] = Wire.read();
        data[2] = Wire.read();
        data[3] = Wire.read();
        data[4] = Wire.read();
        data[5] = Wire.read();
    }
    delay(300);
  
    // Convert the data
    float cTemp = ((((data[0] * 256.0) + data[1]) * 175.72) / 65536.0) - 46.85;
    float fTemp = (cTemp * 1.8) + 32;
    float humidity = ((((data[3] * 256.0) + data[4]) * 125) / 65535.0) - 6;
    
    
    
    // Output data to dashboard
    //Particle.publish("Lux: ",  String(tLux));
    Particle.publish("Temperature in Celsius: ",  String(cTemp));
    delay(300);
    Particle.publish("Temperature in Fahrenheit: ", String(fTemp));
    delay(300);
    Particle.publish("Relative Humidity: ",  String(humidity));
    delay(300);
    Particle.publish("Lux: ",  String(tLux));
    delay(300);
    
    
    //ubidots
    

    delay(100);
        
        
    // setting ubidots request path 1
    request.hostname = "things.ubidots.com";
    request.port = 80;
    request.path = "/api/v1.6/variables/"VARIABLE_ID"/values?token="TOKEN;
    
    // sending variable 1 to ubidots
    Serial.println("Sending data ...");
    request.body = "{\"value\":" + String(cTemp) + "}";

    // Ubidots Variable 1 Post request
    http.post(request, response, headers);
    Serial.println(response.status);
    Serial.println(response.body);
    
    delay(100);
    

    // setting ubidots request path 2
    request.hostname = "things.ubidots.com";
    request.port = 80;
    request.path = "/api/v1.6/variables/"VARIABLE_ID2"/values?token="TOKEN;        
    
     // sending varible 2 to ubidots
    Serial.println("Sending data ...");
    request.body = "{\"value\":" + String(humidity) + "}";

    // Ubidots variable 2 Post request
    http.post(request, response, headers);
    Serial.println(response.status);
    Serial.println(response.body);
    
    delay(100);

Really strange because this code flashed just fine just a couple months ago!

First replace the <...> in your includes with "..." - even if it would work it’s just not “right” :wink: (e.g. look here http://stackoverflow.com/questions/3162030/difference-between-angle-bracket-and-double-quotes-while-including-heade)
Deducing from your other library includes, I’d guess you are using Web IDE soe you won’t need those two includes at a

#include <application.h>
#include <spark_wiring_i2c.h>

Since application.h is added by the preprocessor and hence includes spark_wiring_i2c.h anyway.

But this preproessor might cause the errors, so try removing the comments and/or the blank lines at the top.
If this doesn’t help try adding this at the top

#pragma SPARK_NO_PREPROCESSOR
#include "Particle.h"

// add function prototypes (forward declarations) where required

Checking the error:

Please change the variable from type float to double for use with Particle.variable().

Checking the docs:
https://docs.particle.io/reference/firmware/photon/#particle-variable-

Checking your code:

float cTemp = 0.0, fTemp = 0.0, humidity = 0.0, tLux = 0.0;

Any ideas ;)?

Thanks @Moors7!

That was the issue. Thanks also @ScruffR for the syntax tips.

How come it was no problem to compile this a few weeks ago, but all of a sudden it’s catching this float vs double issue?

The error message was recently added.
Before it dud build without error but the result was wrong. But since it’s better to have no result than a wrong one the extra checks were added.
See this