Sending strings to ubidots

Hey there,

i am using a E-Series and i am sending data via a webhook to ubidots.
I have sent values without any problem.
Now I also wanted to send a string.
I get an error that the ubidots.add() function is not capable of handling strings.

Any suggestions.?

Thanks

Check this out. It might help:
https://help.ubidots.com/en/articles/513317-connect-a-particle-device-to-ubidots-over-http-tcp-or-udp

1 Like

Hi @SmartWater -

Have a look at this project I did… sending string values to Ubidots.

Or… have a look at the cod below. I used two different options on sending the string values depending on whether I am using Single or Multiple variables in Ubidots.

lass IPAndName {

public:
    IPAddress address;
    std::string name;
    IPAndName(int a, int b, int c, int d, std::string n);
};

IPAndName::IPAndName(int a, int b, int c, int d, std::string n) : address(a, b, c, d) {
    name = n;
}

IPAndName addresses[] = {               //  IP Address list
    IPAndName(192, 168, 1, 1, "Router"),
    IPAndName(192, 168, 1, 9, "Extender"),
    IPAndName(192, 168, 1, 6, "iPhone"),
    IPAndName(192, 168, 1, 9, "Macbook"),
    IPAndName(192, 168, 1, 10, "iOS"),
    IPAndName(192, 168, 1, 15, "Brother"),
    IPAndName(192, 168, 1, 21, "AppleTV"),
    IPAndName(192, 168, 1, 180, "IP_Phone")
    
};

int number_of_addresses = 8;            //  Specify number of allowed IP's. Should match list.

int numberOfReceivedPackage;
unsigned long lastTime = 0;                      

int status;                             //  Define string

// Establish Ubidots Webhook
const char* WEBHOOK_NAME = "Ubidots";       
Ubidots ubidots("webhook", UBI_PARTICLE);
    
int redPin = D3;                        //  Define RGB pins
int greenPin = D2;    
int bluePin = D1;


void setup() {
        
    pinMode(redPin, OUTPUT);            //  Set RGB pins as output pins
    pinMode(greenPin, OUTPUT);
    pinMode(bluePin, OUTPUT);   
    
    RGB.mirrorTo(D3, D2, D1);           //  Mirror onboard LED
    
}

void loop() {
    
    unsigned long current = millis();

    if (current-lastTime>120000) {                // Every 60 seconds monitor &  publish
        lastTime = current;


    for (int i=0; i<number_of_addresses; i++) {
        numberOfReceivedPackage = WiFi.ping(addresses[i].address);

         if (numberOfReceivedPackage > 0) {
             status = 1;                        // Represents ON in Ubidots Dashboard
         } else {
             status = 0;                        // Represents OFF in Ubidots Dashboard
         }
    delay(1250);
//--Ubidots Webhooks -- Multiple Variable //
    ubidots.add((char*)addresses[i].name.c_str(), status);                  // Create variable in Ubidoits and publish value
 
    bool bufferSent = false;
    bufferSent = ubidots.send(WEBHOOK_NAME, PUBLIC);                        // Use Particle webhooks to send data    
 

// Test Code -- Single variable publish START //

    // ubidots.addContext("Device", (char*)addresses[i].name.c_str());  //str  //tagValue

    // char* context = (char *) malloc(sizeof(char) * 60);

    // /* Builds the context with the array above to send to Ubidots */
    // ubidots.getContext(context);
    // ubidots.add("Device", status, context);  // Change for your variable name  
    
    // bool bufferSent = false;
    // bufferSent = ubidots.send(WEBHOOK_NAME, PUBLIC);  // Will use particle webhooks to send data


// Test Code -- Single variable/ publish/ END  // 
   
    }
  }
}

Enjoy @Ubidots !! Hope this helps.

Regards, Friedl!