LSM303 data from I2C [SOLVED]

thanks peekay123!
It takes me time to respond but I need to educate myself everytime before I answer :smile:
So I should be able to “POST” the data to i.e. Dropbox using TCP Client, then I can use the data from there, right? Is there a limit to size of the “POST”?
Thanks!

1 Like

Dup, you will need to keep your POSTs relatively small, again due to RAM constraints depending on your program’s overall memory requirements. As for posting to a site, as long as it does not require HTTPS then you should be ok, subject to their posting policies (posts per minute, data size, etc). There is a topic on posting data to a Google spreadsheet that you may want to look at as well:

Hi peekay123,
I have things working with google and now i am trying to POST to dropbox. I am able to curl a request and now I want to perform an HTTP POST to Dropbox via client.print. I know the URL structure, method and parameters but I am having difficulty writing the code. I used the Xively example in the attempt to figure it out but it is not clear to me.

DOES this=
curl https://api.dropbox.com/1/datastores/put_delta -d handle= -d rev=1 -d changes="[[“I”, “tasks”, “myrecord”, {“taskname”: “do laundry”, “completed”: false}]]" -H "Authorization: Bearer "

EQUAL this=
/Serial.println(“Connecting to server…”);
if (client.connect(“api.dropbox.com/1/datastores”, 8081))

// Connection succesful, update table
client.print("{");
client.print(" “method” : “put_delta”,");
client.print(" “params” : {},");
client.print(" “handle” : “<DATASTORE-HANDLE>”,");
client.print(" “rev” : “<rev>”,");
client.print(" “changes” : “[[“I”, “tasks”, “myrecord”, {“taskname”: “do laundry”, “completed”: false}]]”);
client.print(" “Authorization” : “<YOUR-ACCESS-TOKEN>”);
client.print("}");
client.println();

thanks!

1 Like

Hi @Dup

I think that Dropbox requires SSL/TLS (i.e. https) and does not allow basic auth. Does your curl request work if you change https to http?

I would love to be wrong, but I think you may need to wait for the Spark team to finish the web hooks feature they are working on.

Hi bko,
Dropbox uses HTTPS just like Xively which I was able to connect to. If I could figure out how to write the code, then I could test it. As I understand it, HTTP has URL structure, Method, Parameters and Body but from the curl command above, I can’t seem to figure out how to write the code
Thanks!

Hi @Dup

The Spark core is not capable of using SSL/TLS https today. If you were talking directly to Xively from a core, you must be using plain http, perhaps with authorization (username and password called basic auth or the Authorization: Bearer token) but not encrypted SSL/TLS.

Since Xively is an IoT company they say:

Notes

While it is possible to communicate with Xively using HTTP, this method is not secure and it is not recommended. It remains a part of the service as an element of legacy support. It is recommended to use ‘HTTPS’ in all API requests: https://api.xively.com.

Dropbox is not an IoT company and requires SSL/TLS encrypted connections in my experience.

1 Like

As @bko mentioned, we don’t have HTTPS support. But even besides that, I think you need a few changes. Maybe something like:

//Serial.println("Connecting to server...");
if (client.connect("api.dropbox.com", 8081)) {
    // Connection succesful, update table
    client.println("POST /1/datastores/put_delta HTTP/1.0");
    client.println("Authorization: Bearer");
    client.println(""); // end of headers, start of data
    client.print("{");
    client.print("'handle': '',");
    client.print("'rev': '1',");
    client.print("'changes': '[['I', 'tasks', 'myrecord', {'taskname': 'do laundry', 'completed': false}]]");
    client.println("}");
}

The Dropbox API docs also mention a ‘nonce’ parameter for the datastores/put_delta call, but I’m not familiar with their API, so I have to assume you know where to get that.

In any case, the above would be closer to the curl command you have. I specified the ‘POST’ HTTP method because that’s what the Dropbox API docs say is needed. The ‘Authorization: Bearer’ header has to be moved up above the regular data. And lastly, I changed the JSON to use single quotes around strings to eliminate all the quote escaping you were doing before, and make things more readable.

Thanks guys!
I will process this stuff and educate myself some more! :slight_smile: Is there another way to get the data onto Dropbox securely i.e. instead of POST perhaps expose the data then GET from Dropbox? My plan is to use an SD card with my core to store the data then somehow get it to Dropbox or something similar
Thanks!

Coming soon from the Spark team will be a “web hooks” feature that lets you register something for the :spark: cloud to do securely to or from another host on the internet, based on a core event or variable or function.

It might be something like, when the cloud gets a Spark.publish() event from your core, you have set it up to do an HTTPS POST to dropbox with the publish data.

You can do this today with your own host on the internet or a few services but having it in the Spark cloud is a major advantage since the connection to and from the cloud is encrypted and private already.

2 Likes