Ubidots Community

Arduino IDE trouble using esp8266 to update a variable

Hi. I’m using esp8266 with the arduino IDE.
I’m trying to send a test variable using the following code:

/****************************************
 * Include Libraries
 ****************************************/

#include "Ubidots.h"

/****************************************
 * Define Instances and Constants
 ****************************************/

const char* UBIDOTS_TOKEN = "I Pasted my Token here";  // Put here your Ubidots TOKEN
const char* WIFI_SSID = "my network"; // Put here your Wi-Fi SSID
const char* WIFI_PASS = "my password"; // Put here your Wi-Fi password

Ubidots ubidots(UBIDOTS_TOKEN, UBI_HTTP);

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

// Put here your auxiliar functions

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

void setup() {
  Serial.begin(115200);
  ubidots.wifiConnect(WIFI_SSID, WIFI_PASS);

  ubidots.setDebug(true);  // Uncomment this line for printing debug messages
}

void loop() {
  float value1 = random(0, 9) * 10;

  ubidots.add("I pasted the long variable code name here", value1);  // Change for your variable name

  bool bufferSent = false;
  bufferSent = ubidots.send();  // Will send data to a device label that matches the device Id

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

  delay(8000);
}

As you can see this code is from a library called “ubidots-esp8266” https://github.com/ubidots/ubidots-esp8266/archive/master.zip

Based on the serial readout in Arduino IDE it’s connecting to wifi just fine, but the following error has me stumped:

“code”: 403001, “message”: “The user has not permissions to create a new variable.”

I have checked that I’ve created a variable, that the code is correct. I even tried using the “API name” instead. But, I’m stuck. I’m not trying to “create a variable” just update an existing one. But it’s not recognizing that.

What can I try next?

Hi @thefuturebird

A 403 error response code means you’re not using an appropriate token. Can you please clarify if you’re using a Device Token or Account Token? Depending on which it is, there would be considerations needed be taken into account. I’d advise, while you get used to both type of tokens, to use an Account Token which in turn will give permissions to create Devices and its variables.

Also, if you try out with the Account Token you will see a new Device created in your account labelled as the ESP8266 MAC address. This is the default used by the library.
To change that, you can specify a label in the send() method as:

bufferSent = ubidots.send("YOUR_DEVICE_LABEL");

Furthermore, in the add() method, what do you mean by "I pasted the long variable code name here"? Is it the variable label or ID ?

–David

I’m was the token from here:

Imgur

and the variable name from here:

Imgur

Based on your comment I think I may have been using the device token, not the account one? So I looked under “API credentials” and took the default token from there and tried that. But this gave me a new error:

“Could not verify the remote secure server certificate, please make sure that you are using a secure network”

But the data seems to be moving. It’s not sensitive data so is that waring important?

Thanks for your help!