The YUN and Carriots

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!

I just spent a wonderful few hours playing with Yun and Carriots and got the Carriots YUN example up and running sending emails to me when "events" happen on the Yun --BTW I believe their hardware hookup example picture is incorrect. I didn't use that set up and modified my Yun code to account for my sensor setup.

Carriots is a very, very capable (and therefore complicated, so expect to take some time learning how to use it) addition to the Internet of Things world.

I am actually amazed at the apparent lack of interest in Yun/Carriots on this forum???

David Garrison

Thank you for the comment David.
Please let me know how your experience and Carriots step in can be improved. I’m part of the team and love to hear feedback for the good and for the bad :wink:
Regarding the hardware hookup error, tell me too.
BR
Alvaro