Hi all.
Just to let you know that Carriots has published some code to send data to their platform with an Arduino YUN. You can check it here: https://www.carriots.com/tutorials/send_stream/arduino_yun
The code uses the Process library from the YUN's Bridge to launch a curl command.
I drop the code here also. Let me know if I can help you with something related to Carriots
#include <Process.h>
#define APIKEY "98346..ab4" // TO BE REPLACED with your Carriots APIKEY
#define DEVICE "test@carriots" // TO BE REPLACED with your Device's ID developer
// set up net client info:
const unsigned long postingInterval = 10000; //delay between updates to Carriots
unsigned long lastRequest = 0; // when you last made a request
String dataString = "";
void setup() {
// start serial port:
Bridge.begin();
Serial.begin(9600);
while (!Serial); // wait for Network Serial to open
Serial.println("Carriots client");
// Do a first update immediately
updateData();
sendData();
lastRequest = millis();
}
void loop() {
// get a timestamp so you can calculate reading and sending intervals:
long now = millis();
// if the sending interval has passed since your
// last connection, then connect again and send data:
if (now - lastRequest >= postingInterval) {
updateData();
sendData();
lastRequest = now;
}
}
void updateData() {
// convert the readings to a String to send it:
dataString = "{\"protocol\":\"v1\",\"checksum\":\"\",\"device\":\"";
dataString += DEVICE;
dataString += "\",\"at\":\"now\",\"data\":{\"temp\":";
dataString += random(10) + 20;
dataString += "}}";
Serial.println("\n\nDataString:\n"+dataString);
}
void sendData() {
// form the string for the APIKEY header parameter:
String apiString = "carriots.apikey: ";
apiString += APIKEY;
// Send the HTTP POST request
Process carriots;
Serial.print("\n\nSending data... ");
carriots.begin("curl");
carriots.addParameter("-k");
carriots.addParameter("--request");
carriots.addParameter("POST");
carriots.addParameter("--data");
carriots.addParameter(dataString);
carriots.addParameter("--header");
carriots.addParameter(apiString);
carriots.addParameter("https://api.carriots.com/streams/");
carriots.run();
Serial.println("done!");
// If there's incoming data from the net connection,
// send it out the Serial:
while (carriots.available() > 0) {
char c = carriots.read();
Serial.write(c);
}
}
Enjoy!