I’m trying to use the sample Ubidots NodeJS client: (https://github.com/ubidots/ubidots-node) and the authorization works fine, returns a token and everything. But every request after that returns a malformed resource id error (using the getDatasource and get Variable methods). I believe it was working several weeks ago I believe, but it isn’t any more. I’ve checked to make sure the variable and datasource names is in the console.
Can you post your code? Please.
I just tested the library with the example and it works good for me.
I haven’t had a chance to go back and play with it. I’m also having troubles with another library for photons, so I’m not sure if it’s something wrong with my computer and the web ide, because things were working (both with the Ubidots and the other Photon code). But here is the code:
// This #include statement was automatically added by the Particle IDE.
#include <Ubidots.h>
#include <application.h>
#include <spark_wiring_i2c.h>
#define TOKEN "" // Put here your Ubidots TOKEN
#define DATA_SOURCE_TAG "Photon1" // Put here your data source name, Ubidot will create one with that name
// HCPA-5V-U3 I2C address is 0x28(40)
#define Addr 0x28
double cTemp = 0.0, fTemp = 0.0, humidity = 0.0;
Ubidots ubidots(TOKEN);
void setup() {
ubidots.setDatasourceName(DATA_SOURCE_TAG);
// Initialize I2C communication as Master
Wire.begin();
// Initialize serial communication, set baud rate = 9600
Serial.begin(9600);
// Start I2C transmission
Wire.beginTransmission(Addr);
// Send general start command
Wire.write(0x80);
// Stop I2C transmission
Wire.endTransmission();
delay(300);
}
void loop() {
//retrieve a value
double value;
//the first value, go to UbiDots dashboard, devices, copy created tag for device
//or add "Photon1" or whatever to the tags that are on the device that is created.
value = ubidots.getValueWithDatasource("Photon1", "ftemperature");
Serial.println(value);
delay(500);
//send values
unsigned int data[4];
// Start I2C transmission
Wire.beginTransmission(Addr);
// Stop I2C transmission
Wire.endTransmission();
// Request 4 bytes of data
Wire.requestFrom(Addr, 4);
// Read 4 bytes of data
// humidity msb, humidity lsb, cTemp msb, cTemp lsb
if (Wire.available() == 4)
{
Serial.println("got data from sensor");
data[0] = Wire.read();
data[1] = Wire.read();
data[2] = Wire.read();
data[3] = Wire.read();
// Convert the data to 14-bits which is the resolution of the sensors
// (0.01%RH) and (0.01°C)
humidity = (((data[0] & 0x3F) * 256) + data[1]) / 16384.0 * 100.0;
cTemp = (((data[2] * 256) + (data[3] & 0xFC)) / 4) / 16384.0 * 165.0 - 40.0;
fTemp = (cTemp * 1.8) + 32;
Serial.println(fTemp);
//The library has a feature to add extra information inside a variable.
//In this example, the code will send a temperature value with extra information: latitude and longitude.
//Ubidots has a widget to display a real time position in a map. The widget looks for “lat” and “lng” keys
//inside the context key of the variable’s values.
char context[25];
sprintf(context, "lat=43.0861$lng=-77.6705");
ubidots.add("ftemperature", fTemp, context);
ubidots.add("ctemperature", cTemp);
ubidots.add("humidity", humidity);
ubidots.sendAll();
} else {
Serial.println("didn't get data from sensor");
}
delay(5000);
}
]