[SOLVED] Electron assertion failure if sending and receiving variables to and from Ubidots

Hi, I am using a Particle Electron to send and receive variables to and from Ubidots. I have tested sending and receiving data in separate firmware however when I attempt to combine sending and receiving in a single piece of code I get a SOS assertion failure. If someone could assist that would be very much appreciated as I have tried my best to solve the issue, here is my code:

#include <Ubidots.h>
#include <math.h>

#ifndef TOKEN
#define TOKEN "..."
#endif 

#ifndef DEVICE_LABEL
#define DEVICE_LABEL "..."
#endif

#ifndef VAR_ID_1
#define VAR_ID_1 "..."  // motorOn
#endif

CANChannel can(CAN_D1_D2);
Ubidots ubidots(TOKEN);

//Motor Controller Variables
bool motor1F = 0;
bool motor2F = 0;
bool motor3F = 0;
float motorRpm = 0;
float motorCrnt = 0;
float motorFlt = 0;
float contrlT = 0;
float motorT = 0;
float motorFltSub = 0;
float motorOn = 0;

// Other variables
int lastPublishL = 0;
int lastPublishS = 0;

void setup() {
    can.begin(250000);
}

void loop() {
    
    CANMessage message;
    
    if(can.available() > 0){
        
        can.receive(message);
        
        if (message.id == 0x130){ //Motor Controller 1
            motorRpm = canToValue(message.data[0], message.data[1], 1, 0);
            motorCrnt = canToValue(message.data[6], message.data[7], 0.1, 0);
            motor1F = 1;
        }  
        
        if (message.id == 0x140){ //Motor Controller 2
            motorFlt = canToValue1(message.data[6], 1, 0);
            motor2F = 2;
        }
        
        if (message.id == 0x150){ //Motor Controller 3
            contrlT = canToValue1(message.data[0], 1, -50);
            motorT = canToValue1(message.data[1], 1, -50);
            motorFltSub = canToValue(message.data[3], message.data[4], 1, 0);
            motor3F = 1;
        }
    }
    
    //Create ubidots variables - 10s upload period
    if (millis()-lastPublishS > 10000) {
        lastPublishS = millis();
        
        //Motor variables - Transmit only if CAN message received
        if (motor1F == 1){
            ubidots.add("RPM", motorRpm);
            ubidots.add("Motor Current", motorCrnt);
            ubidots.sendAll();
            motor1F = 0;
        }
        
        if (motor2F == 1){    
            ubidots.add("Motor fault code", motorFlt);
            ubidots.sendAll();
            motor2F = 0;
        }    
        
        if (motor3F == 1){    
            ubidots.add("Controller temp", contrlT);
            ubidots.add("Motor temp", motorT);
            ubidots.add("Motor fault subcode", motorFltSub);
            ubidots.sendAll();
            motor3F = 0;
        }
        
        motorOn = ubidots.getValue(VAR_ID_1);
        
        CANMessage control;
        control.extended = true;
        control.len = 1;
        control.id = 0x160;
        control.data[0] = motorOn;
        
        can.transmit(control);
    }
}

// Convert 2 byte data to a decimal value
float canToValue (int dec1, int dec2, float dis, int off) {
    int i = floor(dec1/16);
    int j = dec1 - (16*i);
    int k = floor(dec2/16);
    int l = dec2 - (16*k);
    float value = ((i*4096 + j*256 + k*16 + l)*dis)+off;
    return value;
}

// Convert 1 byte data to a decimal value
float canToValue1 (int dec1, float dis, int off) {
    float value = (dec1*dis)+off;
    return value;
}

Greetings, I have made a small test and at my side I can retrieve and send properly values using the library, please refer to the test script below:

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

/****************************************
 * Include Libraries
 ****************************************/
#include <Ubidots.h>

/****************************************
 * Define Constants
 ****************************************/

#ifndef TOKEN
#define TOKEN ""  // Put here your Ubidots TOKEN
#endif
#ifndef VAR_ID
#define VAR_ID "591074ea18f9363cb05b8854"  // Put here your data source name
#endif
#ifndef VAR_LABEL
#define VAR_LABEL "fuel" // Put here your variable api label
#endif
#ifndef DEVICE_LABEL
#define DEVICE_LABEL "truck" // Put here your device api label
#endif


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

//Put here your auxiliar functions


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


Ubidots ubidots(TOKEN);

void setup() {
    Serial.begin(115200);
    //ubidots.setDebug(true); //Uncomment this line for printing debug messages
}
void loop() {
    /*
    * Obtains values using TCP according to structure specified at
    * http://help.ubidots.com/developers/send-data-to-ubidots-over-tcp-or-udp
    */
    float value1 = ubidots.getValue(VAR_ID);
    float value2 = ubidots.getValueWithDatasource(DEVICE_LABEL, VAR_LABEL);

    /*
    * Obtains values using HTTP according to structure specified at
    * https://ubidots.com/docs/api/index.html#get-values
    */
    float value3 = ubidots.getValueHTTP(VAR_ID);

    // Evaluates the results obtained
    if(value1!=ERROR_VALUE){
      Serial.print("value obtained from Ubidots:");
      Serial.println(value1);
    }
    if(value2!=ERROR_VALUE){
      Serial.print("value 2:");
      Serial.println(value2);
    }
    if(value3!=ERROR_VALUE){
      Serial.print("value 3:");
      Serial.println(value3);
    }
    
    /*
    Sends data to Ubidots
    */
    
    float value4 = random(0, 1000)*1.0;
    ubidots.setDeviceLabel("truck");
    ubidots.add("fuel", value4);
    bool bufferSent = false;
    if(ubidots.isDirty()){  // There are stored values in buffer
      bufferSent = ubidots.sendAll();
    }

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

Result:

imagen

I have looked into your script and notice that when you use the add() method you include blank spaces inside your variable label, blank spaces are not allowed so please replace them by a middle script.

Now, as you are using third party libraries I am not sure if they can throw hardware exceptions during your routine or if they have any incompatibility with our library, from my tests the Ubidots library by itself does not throw exceptions so I would advice you to test if there is any issue of this kind with the can library.

All the best