Jump to content









Most Liked Content


#556 Wireless Gardening with Arduino + CC3000 WiFi Modules

Posted by PineappleChili on 14 August 2014 - 12:35 AM

Here ya go!

Looking over it again, I should really create a function for the reconnect since I use those same lines like 5 times. Ah well, some work for this weekend. :)

 

/*Fred's Plant Sensor v1.0
Receives humidity and temperature input from SHT-10 soil Sensor
Receives ambient temperature from DS18B20 temperature sensor
Displays data from sensors to LCD
Uploads data to Carriot via Adafruit CC3000 wifi shield
Refreshes every 10 minutes 
Based on code from M.Schwartz*/

//setting up the LCD screen
#include <LiquidCrystal.h>
// (rs, en, db4, db5, db6, db7)
LiquidCrystal dataDisplay(A0, A1, A2, A3, A4, A5);

//setting up WiFi
#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
#include <string.h>
//#include "utility/debug.h"
//#include <stdlib.h>

#define ADAFRUIT_CC3000_IRQ   3
#define ADAFRUIT_CC3000_VBAT  5
#define ADAFRUIT_CC3000_CS    10
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT, SPI_CLOCK_DIVIDER);
#define WLAN_SSID "xxx"
#define WLAN_PASS "xxx"
#define WLAN_SECURITY WLAN_SEC_WPA2
uint8_t dhcpTimeout;

//Setting up the humidity sensor
#include <SHT1x.h>
const uint8_t humidData = 8;
const uint8_t humidClock= 9;
float airTemp = 0;
float airHumid = 0;
SHT1x humidity(humidData, humidClock);

//setting up ambient temp
#include <OneWire.h>
#include <DallasTemperature.h>
const uint8_t ambientTemp = 7;
OneWire oneWire(ambientTemp);
DallasTemperature sensors(&oneWire);
float soilF = 0;

char soilTChar[32];
char airTempChar[32];
char airHumidChar[32];


//setting up Carriots 
#define API_KEY "xxx"
#define DEVICE  "Soil_Sensor@PineappleChili.PineappleChili"
#define WEBSITE "api.carriots.com"
uint32_t ip;
String data;
uint8_t stringLength = 0;


/*
**************************************
*                 SETUP              *
*Defines LCD Pins and loads LCD      *
*Begins Sensors and reserves Strings *
*Initiates CC3000, connects to wifi  *
**************************************
*/
void setup () {
  Serial.begin(115200);

  //setting up LCD pins
  pinMode(A0, OUTPUT); 
  pinMode(A1, OUTPUT); 
  pinMode(A2, OUTPUT); 
  pinMode(A3, OUTPUT); 
  pinMode(A4, OUTPUT); 
  pinMode(A5, OUTPUT);
  
 //initiate sensors
  sensors.begin();
  
 //LCD load screen 
  dataDisplay.begin(4, 20);  
  
  //connect to wifi
  cc3000.begin();
  Serial.println(F("Initializing CC3000"));
  if (!cc3000.begin()) {
    Serial.print(F("Failed"));
    while(1);
  }
  //Reserving data string
  data.reserve(180);
  
  //connecting to network
  beginning: //goto if connection fails
  Serial.print(F("Attempting to connect to "));
  Serial.println(WLAN_SSID);
  cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY);
  Serial.println(F("Connected"));
  
  //Wait for DHCP to complete
  Serial.println(F("Requesting DHCP"));
  while (!cc3000.checkDHCP()) {
    delay(500);
    Serial.print(F("."));
    dhcpTimeout ++;
    if (dhcpTimeout == 60) {
      Serial.println(F(""));
      Serial.println("DHCP Timeout! Attempting to reconnect.");
      dhcpTimeout = 0;
      goto beginning;
    }
  }
  Serial.println(F(""));
  Serial.println(F("DHCP complete"));

 //get website IP
    ip = 0;
  Serial.print(WEBSITE); Serial.print(F(" -> "));
  while (ip == 0) {
    if (! cc3000.getHostByName(WEBSITE, &ip)) {
      Serial.println(F("Couldn't resolve!"));
    }
    delay(500);
  }
  cc3000.printIPdotsRev(ip);
  Serial.println("");
}


/*
**************************************
*                 Loop               *
*Read Sensors and track iterations   *
*Display data to LCD                 *
*Formats data for upload             *
*Calls function to upload            *
**************************************
*/
void loop () {
  beginning:  //goto call in the event cc3000 is reset due to DHCP hangup


  //read sensors
  airTemp = humidity.readTemperatureF();
  airHumid = humidity.readHumidity();
  sensors.requestTemperatures();
  soilF = ((sensors.getTempCByIndex(0) * 9)/5)+32;
  delay (100);

  //display sensors to LCD
  dataDisplay.clear();
  dataDisplay.print("Soil: ");
  dataDisplay.print(soilF);
  dataDisplay.print((char)223);
  dataDisplay.setCursor(0,1);
  dataDisplay.print("Air: ");
  dataDisplay.print(airTemp);
  dataDisplay.print((char) 223);
  dataDisplay.print(", ");
  dataDisplay.print(airHumid);
  dataDisplay.print("%");

  // Convert Floats to Chars in order to send them via fastrprint
  // dtostrf( [Float variable] , [Minimum SizeBeforePoint] , [sizeAfterPoint] , [WhereToStoreIt] )
  dtostrf(soilF, 2, 2, soilTChar);
  dtostrf(airTemp, 2, 2, airTempChar);
  dtostrf(airHumid, 2, 2, airHumidChar);

  //you need to concatenate the data string in order to calculate length as Carriotts requires data length in the payload
  String data = "{\"protocol\":\"v2\",\"device\":\""+String(DEVICE)+"\",\"at\":\"now\",\"data\":{\"Air Temperature\":"+(airTempChar)+",\"Humidity\":"+(airHumidChar)+",\"Soil Temperature\":"+(soilTChar)+"}}";
  stringLength = data.length();
  
  /*
  //This is used for initial troubleshooting. Uncomment if your upload fails then verify content length here versus what is reported back from the client
  Serial.print(F("Data Length: "));
  Serial.print(stringLength);
  Serial.println();
  Serial.println(F("POST /streams HTTP/1.1"));
  Serial.println(F("Host: api.carriots.com"));
  Serial.println(F("Accept: application/json"));
  Serial.println(F("User-Agent: Arduino-Carriots"));
  Serial.println(F("Content-Type: application/json"));
  Serial.println("carriots.apikey: " + String(API_KEY));
  Serial.println("Content-Length: " + String(stringLength));
  Serial.print(F("Connection: close"));
  Serial.println();
  Serial.println(data);
  */

  //check to see if connection still exists. If not, reconnect
  if (!cc3000.checkConnected()) {
    Serial.println(F("Lost connection! Attempting to reconnect"));
    cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY);
    Serial.println(F("Connected"));
    //Request DHCP - If not resolved in 30 seconds, try to reconnect to AP and start over
    Serial.println(F("Requesting DHCP"));
    while (!cc3000.checkDHCP()) {
      delay(500);
      Serial.print(F("."));
      dhcpTimeout ++;
      if (dhcpTimeout == 60) {
        Serial.println(F(""));
        Serial.println("DHCP Timeout! Reboot CC3000 and attempt to reconnect.");
        dhcpTimeout = 0;
        cc3000.reboot();
        goto beginning;  
      }
    }
    Serial.println(F(""));
    Serial.println(F("DHCP complete"));

  }
  
//Send data via client to Carriots  
  Adafruit_CC3000_Client client = cc3000.connectTCP(ip, 80);
  if (client.connected()) {
  Serial.println(F("Connected!"));
  client.fastrprintln(F("POST /streams HTTP/1.1"));
  client.fastrprintln(F("Host: api.carriots.com"));
  client.fastrprintln(F("Accept: application/json"));
  client.fastrprintln(F("User-Agent: Arduino-Carriots"));
  client.fastrprintln(F("Content-Type: application/json"));
  client.fastrprint(F("carriots.apikey: ")); 
  client.fastrprintln(API_KEY);
  client.fastrprint(F("Content-Length: "));
  client.println(stringLength);
  client.fastrprintln(F("Connection: close"));
  client.println();
  client.fastrprint(F("{\"protocol\":\"v2\",\"device\":\""));
  client.fastrprint(DEVICE);
  client.fastrprint(F("\",\"at\":\"now\",\"data\":{\"Air Temperature\":"));
  client.fastrprint(airTempChar);
  client.fastrprint(F(",\"Humidity\":"));
  client.fastrprint(airHumidChar);
  client.fastrprint(F(",\"Soil Temperature\":"));
  client.fastrprint(soilTChar);
  client.fastrprintln(F("}}"));
  } else {
//if unable to send data, reset cc3000, reconnect to AP, resolve DHCP, start at beginning of loop
    Serial.println (F("Connection failed! Attempting reboot"));
    cc3000.reboot();
    Serial.println(F("Lost connection! Attempting to reconnect"));
    cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY);
    Serial.println(F("Connected"));
    //Request DHCP - If not resolved in 30 seconds, try to reconnect to AP and start over
    Serial.println(F("Requesting DHCP"));
    while (!cc3000.checkDHCP()) {
      delay(500);
      Serial.print(F("."));
      dhcpTimeout ++;
      if (dhcpTimeout == 60) {
        Serial.println(F(""));
        Serial.println(F("DHCP Timeout! Reboot CC3000 and attempt to reconnect."));
        dhcpTimeout = 0;
        cc3000.reboot();
        goto beginning;  
        }
      }
    Serial.println(F(""));
    Serial.println(F("DHCP complete"));
    }
  
  Serial.println(F("----------"));
  while (client.connected()) {
    while (client.available()) {
      char c = client.read();
      Serial.print(c);
    }
  }
   
  client.close();
  Serial.println(F(""));
  Serial.println(F("Closing Client"));

  //Two delays between loop - 10 min for normal procedure, 2 min for testing
  delay (600000);
//  delay (120000);

}




#530 Wireless Gardening with Arduino + CC3000 WiFi Modules

Posted by PineappleChili on 31 July 2014 - 02:58 PM

Hey again!

 

Wanted to follow up and say that I was able to solve the problem with help from a few different sources. To quickly document it here in the event someone else suffering from the same issue stumbles upon this thread:

 

I updated the CC3000 firmware to version 1.28 which was released recently and addresses some of the stability issues caused by how it handles packets.

I reserved the data string to prevent fragmenting the heap.

 

My router seemed to hate the firmware update and caused the connection to hang at resolving the DHCP after 2 iterations of the loop so I rearranged the sketch to connect to the AP in the Setup. Then I added a check in the loop to make sure the connection still exists before sending the data. If the connection check fails, it reconnects then tries to send again.

 

Finally, and I think this was the major change that helped, I was informed via the Adafruit forums that normal .print and .println functionality on the Arduino goes character by character so sending 400 characters is actually sending 400 individual packets which takes way more traffic than it should. The Adafruit library for the CC3000 has a client.fastrprint and client.fastrprintln function that sends up to 90 bytes in one packet which greatly decreased traffic and thus failures caused by interrupting the traffic. To make sure each packet was only 90 bytes, I had to use chars over strings and instead of concatenating the data string and sending it as one giant thing, I sent it as 5 separate packets and let Carriots concatenate it.

 

All in all, seems like the problems are solved though! I was having difficulty getting it to run 8 hours straight, sending every 10 minutes. To test the changes, I was able to get it to run for a little under 48 hours straight sending every 2 minutes. Some basic error logging showed me what caused that crash and a simple connection check - reconnect on failure has solved that. I'd be happy to post the new code if anyone is interested but don't want to spam the forum with the 200 lines of code otherwise. :)




#113 First Carriots Challenge information

Posted by sdeancos on 21 March 2013 - 11:26 AM

You can see it in action in this video.

 

 

It's incredible!




#818 Reducing Power Consumption on Arduino UNO with CC3000 Breakout Board

Posted by whittaker9 on 09 May 2015 - 02:24 AM

While experimenting with my Adafruit CC3000 Breakout board, I discovered that I could reduce the power consumption of the board by controlling the state of the VBAT signal.  VBAT is also called VBAT_SW_EN on the Texas Instruments datasheet for the CC3000.  When the VBAT signal is high, the CC3000 can draw up to 275 ma of current.  The CC3000 current draw is reduced to about 5 microamps when VBAT is low.  The board must reconnect to the network everytime that you send a payload.

 

 

This sketch has been sending data every minute for over three weeks to the Carriots server.  The sketch requires a guest open wifi network on my router because using a password took 9 seconds to login.  The watchdog timer library that I used can only support watchdog timer intervals up to 8 seconds. 

 

I hardcoded the Carriots server IP address because the getHostByName() function didn't work reliably.  I doubt that the IP address will be changing anytime soon and we also save time by not calling this function.

 

If you try this sketch, make sure that you are using the DHT library that supports the DHT22 sensor.

 

I may have more code than is necessary to place the CC3000 in the standby mode.  Some documents indicate that a wlan_stop() or cc3000.stop() may be all I need to enable the standby mode.  I'll test these functions over the next few days and revise the sketch if they work.

 

Glen

 

#include <Adafruit_CC3000.h>
#include <SPI.h>
#include <string.h>
#include <dht.h>      //dht22 functions
#include <avr/wdt.h>  //watchdog timer functions

/* Define CC3000 chip pins */
#define ADAFRUIT_CC3000_IRQ   3
#define ADAFRUIT_CC3000_VBAT  5
#define ADAFRUIT_CC3000_CS    10

// Temperature and humidity sensor: Pin 2
#define DHT22_PIN 2  
dht DHT;

/* Create CC3000 instances */
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
SPI_CLOCK_DIV2); // you can change this clock speed

/* WLAN parameters */
#define WLAN_SSID       "yournetwork"
#define WLAN_PASS       "yourpassword"	//Not needed when WLAN_SEC_WPA2 is used

/* Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2 */
#define WLAN_SECURITY   WLAN_SEC_UNSEC

/* Carriots parameters */
#define WEBSITE  "api.carriots.com"
#define API_KEY "yourAPIkey"
#define DEVICE  "yourDevice"

/*Initialize variables */
   uint32_t ip = 60+ (244*256) + (224 * 65536L) + (82 * 16777216L);
  
void setup(void)
{
  /* Initialize */
  Serial.begin(115200);
 // Serial.println(F("\nInitializing CC3000..."));
  if (!cc3000.begin())
  {
    Serial.println(F("Couldn't start CC3000! Check wiring?"));
    while(1);
  }
}

void loop(void)
{

  // Start watchdog //reset when watchdog not reset within 8 seconds
  // wdt_enable(WDTO_8S); 

  /* Connect to WiFi network in about 13 seconds */
  cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY);
  Serial.println(F("Connected to WiFi!"));
  
  // Reset watchdog
  // wdt_reset();

  /* Wait for DHCP to complete in about 9 seconds */
  //Serial.println(F("Request DHCP"));
  while (!cc3000.checkDHCP())
  {
     delay(100);
  } 
    // Reset watchdog
  // wdt_reset();

  /* Get the website IP & print it */
//    Serial.print(WEBSITE); Serial.print(F(" -> "));
//    while (ip == 0) {
//      if (! cc3000.getHostByName(WEBSITE, &ip)) {
//        Serial.println(F("Couldn't resolve!"));
//     }
//     delay(500);
//   }
//   
  
  /* Read DHT22 Sensor */
   int chk = DHT.read22(DHT22_PIN);
 
/* TODO: Add a DHT sensor health value to payload  */
  switch (chk)
  {
  case DHTLIB_OK:
    Serial.println("\nDHT22 OK");
    break;
  case DHTLIB_ERROR_CHECKSUM:
    Serial.println("Checksum error");
    break;
  case DHTLIB_ERROR_TIMEOUT:
    Serial.println("Time out error");
    break;
  case DHTLIB_ERROR_CONNECT:
    Serial.println("Connect error");
    break;
  case DHTLIB_ERROR_ACK_L:
    Serial.println("Ack Low error");
    break;
  case DHTLIB_ERROR_ACK_H:
    Serial.print("Ack High error,\t");
    break;
  default:
    Serial.print("Unknown error,\t");
    break;
  }

/* Read analog input pins */
  float ADC0 = analogRead(A0) * 0.00488;
  float ADC1 = analogRead(A1)* 0.00488;         
  float ADC2 = analogRead(A2)* 0.00488;
  float ADC3 = analogRead(A3)* 0.00488;
  float ADC4 = analogRead(A4)* 0.00488;
  float ADC5 = analogRead(A5)* 0.00488;

  /* Convert analog data to String */
  String Monitor_0 = doubleToString(ADC0,2);
  String Monitor_1 = doubleToString(ADC1,2);
  String Monitor_2 = doubleToString(ADC2,2);
  String Monitor_3 = doubleToString(ADC3,2);
  String Monitor_4 = doubleToString(ADC4,2);
  String Monitor_5 = doubleToString(ADC5,2);

  /* Prepare JSON for Carriots & get length */
  int length = 0;

  String data = "{\"protocol\":\"v2\",\"device\":\""+String(DEVICE)+"\",\"at\":\"now\",\"data\":{\"T\":"+String(DHT.temperature)+",\"H\":"+String(DHT.humidity)+",\"A0\":"+String(Monitor_0)+",\"A1\":"+String(Monitor_1)+",\"A2\":"+String(Monitor_2)+",\"A3\":"+String(Monitor_3)+",\"A4\":"+String(Monitor_4)+"}}";
 
  length = data.length();

  // Reset watchdog
  //  wdt_reset();

     Adafruit_CC3000_Client client = cc3000.connectTCP(ip, 80);

  // Reset watchdog
  //  wdt_reset();

  if (client.connected()) {
    Serial.println(F("\nConnected to Carriots!"));
    client.fastrprintln(F("POST /streams HTTP/1.1"));
    client.fastrprintln(F("Host: api.carriots.com"));
    client.fastrprintln(F("Accept: application/json"));
    client.fastrprintln(F("User-Agent: Arduino-Carriots"));
    client.fastrprintln(F("Content-Type: application/json"));
    client.fastrprint(F("carriots.apikey: ")); 
    client.fastrprintln(API_KEY);
    client.fastrprint(F("Content-Length: "));
    client.println(String(length));
    client.fastrprintln(F("Connection: close"));
    client.println();
    client.fastrprint(F("{\"protocol\":\"v2\",\"device\":\""));
    client.fastrprint(DEVICE);
    client.fastrprint(F("\",\"at\":\"now\",\"data\":{\"T\":"));
    client.print(String(DHT.temperature));
    client.fastrprint(F(",\"H\":"));
    client.print(String(DHT.humidity));
    client.fastrprint(F(",\"A0\":"));
    client.print(String(Monitor_0));
    client.fastrprint(F(",\"A1\":"));
    client.print(String(Monitor_1));
    client.fastrprint(F(",\"A2\":"));
    client.print(String(Monitor_2));
    client.fastrprint(F(",\"A3\":"));
    client.print(String(Monitor_3));
    client.fastrprint(F(",\"A4\":"));
    client.print(String(Monitor_4));
    client.fastrprintln(F("}}"));
    // Reset watchdog
    //  wdt_reset();
  } 
  else {
    Serial.println(F("Connection to Carriots failed"));    
    //  return;
  }

  Serial.println(F("-------------------------------------"));
  while (client.connected()) {
    while (client.available()) {
      char c = client.read();
      Serial.print(c);
    }
  }
  client.close();
  Serial.println(F("-------------------------------------"));

  Serial.println(F("\n\nDisconnecting from Carriots Service"));
  cc3000.disconnect();
  
  /* Place CC3000 in Standby Mode to reduce power consumption */
  cc3000.stop();
  
  digitalWrite(ADAFRUIT_CC3000_VBAT,LOW);

  /* Reset watchdog & disable */
  //  wdt_reset();
  // wdt_disable();

  /* Wait 1 minute until next update. The maximum value for delay() is unclear. */
  delay(30000); // 30seconds
  delay(30000); // 30 seconds
  
  /* Restore power to cc3000 */
  cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
SPI_CLOCK_DIV2); // you can change this clock speed

  digitalWrite(ADAFRUIT_CC3000_VBAT,HIGH);
  
 cc3000.reboot();
 if (!cc3000.begin())
  {
    Serial.println(F("Couldn't start CC3000! Check wiring?"));
    while(1);
  }

}

// Convert double to string
String doubleToString(float input,int decimalPlaces){
  if(decimalPlaces!=0){
    String string = String((int)(input*pow(10,decimalPlaces)));
    if(abs(input)<1){
      if(input>0)
        string = "0"+string;
      else if(input<0)
        string = string.substring(0,1)+"0"+string.substring(1);
    }
    return string.substring(0,string.length()-decimalPlaces)+"."+string.substring(string.length()-decimalPlaces);
  }
  else {
    return String((int)input);
  }
}





#505 Retrieving another devices data from a particular device's listener

Posted by sdeancos on 17 July 2014 - 09:25 AM

Hi,

 

I think that you can use for example this:

 

import com.carriots.sdk.Stream;


def streams = Stream.findBy(["_t": "str", "device": "Your_id_developer_device"])

def my_temperature = streams[0].data.temperature // for first streams

// or maybe for all streams and save in variable.

def my_temperatures = []
streams.each { it ->
  my_temperatures.add(it.data.temperatures)
}

 

The result from findBy its a groovy map class.

 

I hope this help you,

 

Best regards!



						


#382 Arduino Alarm System "Connection Failed"

Posted by grupp26 on 19 May 2014 - 06:18 PM

what does the Json string look like when you print the on serial?

I'm 90% sure that it is something with the json string that causes trouble.
change the code to something like that I have written and see. hope that helps.

 

String json = "{\"protocol\":\"v2\",\"device\":\""+DEVICE+"\",\"at\":1356390000,\"data\":{\"light\":\""+txt+"\"}}";

 

Serial.println(F("1.        "));

Serial.print("json");


// Make a HTTP request
client.println("POST /streams HTTP/1.1");
client.println("Host: api.carriots.com");
client.println("Accept: application/json");
client.println("User-Agent: Arduino-Carriots");
client.println("Content-Type: application/json");
client.print("carriots.apikey: ");
client.println(APIKEY);
client.print("Content-Length: ");
int thisLength = json.length();
client.println(thisLength);
client.println("Connection: close");
client.println();

client.println(json);

 

Serial.println(F("2.        "));

Serial.print("json");




#291 Online Thermometer Service

Posted by javier on 17 January 2014 - 12:55 AM

I would like to share with you a small project that I have built at Makespace Madrid http://www.makespacemadrid.org .

 

The objective of the project is to build an online thermometer using one of the WiFi devices donated to makespace by electricImp http://electricimp.com/. I use Carriots to collect temperature readings from electricImp and publish them at ducksboard https://ducksboard.com/

 

Thanks to the features provided by Carriots the integration of all the services is straight forward and I have built the online service without having to deploy any server.

 

The picture shows the high level architecture. If you want more information, you can find a detailed tutorial in Spanish here http://wiki.makespac...onectado_online

 

Flow_eImp_carriots_ducksboard.jpg

 

Done by @tumaku_




#208 Carriots, Panic's Status Board, and PythonAnywhere!!!

Posted by Zambiot on 07 May 2013 - 10:35 AM

OK all you Carriots lovers out there.  I have just published a tutorial that I think you will get great use out of.  Jump on over to my Instructable to learn how to connect your Carriots account with Panic's Status Board using PythonAnywhere.  With this first tutorial, you can get your device's status right on your iPad (or web browser), without having to dig through the Control Panel.

 

http://www.instructa...ics-Status-Boa/

 

I've attached an image showing my basic status board.  I plan to create more widgets, and in turn tutorials, so that you too can have your device information in a quick to read format.

Attached Thumbnails

  • IMG_0026.PNG



#150 Carriots and PythonAnywhere

Posted by Zambiot on 01 April 2013 - 02:17 PM

Here is another piece of Python code for use with Carriots.  This code is not too different from above, but what this code does is list all items, up to 1000, that match the requested parameters.  Uncomment your desired parameters and edit the values.  Add in any other parameters you want that you see in the API Streams List method.  This particular script has the output suppressed, but that is easily changed if you like to see lots of data scrolling by in front of your eyes.  

 

import requests, json

app_url = "http://api.carriots.com/"
app_element = "streams/"
app_filter = ""
app_key = "YOUR_API_KEY_HERE"

headers = {"carriots.apikey":app_key}

#Enter any filter parameters in the params section below
params = {}
#params = {'device':'testdevice@Carriots'}
#params = {'device':'testdevice@Carriots', 'at_from':1364468250, 'at_to':1364774400}

print ""

print "Getting streams from Carriots..."
carriotsResponse = requests.get(app_url + app_element, params=params, headers=headers)
binary = carriotsResponse.content
output = json.loads(binary)

#Print all streams retrieved
#print output

print ""
print "There are " + str(len(output['result'])) + " streams retrieved from Carriots."
print "The URL of the request: " + carriotsResponse.url
print ""

 

 




#801 Help sending data and status to Carriots, Arduino UNO CC3000 wifi

Posted by whittaker9 on 09 April 2015 - 01:48 AM

Anthony,

 

I've been running your code for a few days.  The program locks up after it's been running for about a day.  The program stops after printing "Connection failed" . Using the watchdog timer as you suggested seems to be a good way to help the program recover. 

 

I see that there is a  "return" statement after the "Serial.println" statement. I would think that this would cause the program to exit the loop{} and end the program.  Wouldn't it be better to let the loop continue?

 

 

Glen




#552 Confirmation on Limit of Request/Stream

Posted by dompablo on 11 August 2014 - 12:28 PM

Hi tahir,
 
The limits are per account.
 
The message you received is probably because of a HTTP requests limit, maybe a listener that use BasicHttp( ).
 
Retrieving data from carriots is not considered as an outbound request.
 
Hope it helps!



#336 Send Sms to UK mobile

Posted by sdeancos on 14 March 2014 - 10:50 AM

Hi,

 

I think the prefix should be written with 00, you can see it in the documentation:

 

https://www.carriots...y_libraries#sms

 

For example: 00447713264242

 

I hope this can help you, and if you have any doubt don't hesitate to ask here.




#333 Graph Doesn't Appear on Webpage

Posted by jpastor on 07 March 2014 - 11:13 AM

Hello rongans

We have seen your apikey log. The problem is that you are sending float values like a string (with quotes). However we have made ​​an improvement to contemplate that case and it is already solved.

Thanks for the comment.

 

 

 

Enjoy Carriots!




#226 Beer flowmeter

Posted by alvaro on 24 May 2013 - 07:19 AM

Hi all!

 

We've just posted our cool project contribution brought by our team members. It's a beer flowmeter that collect consumption data and sends it to Carriots. You can read more details about the project at https://www.carriots...oject/flowmeter and watch the video at Vimeo.

 

Enjoy!

 

 

1369329170_flowmeter520.jpg

 




#197 Where can I download the Carriots SDK

Posted by sdeancos on 29 April 2013 - 09:04 AM

Hi holyzfy!

 

You try https://github.com/s...cos/clicarriots, its a unofficial simple client for carriots platform in python.

 

Now only can send stream, list streams, get device and list device. I gradually add more functionalities, anyway if anyone is interested in participating this is free software, any contribution is welcome.

 

I hope its helps.

 

Enjoy Carriots!




#1506 New website interface

Posted by MCMGA_Aquaponics on 19 May 2016 - 03:32 PM

Just wanted to congratulate you all on the newly redesigned website.  I like it.  Keep up the good work.




#141 Carriots and PythonAnywhere

Posted by Zambiot on 29 March 2013 - 01:48 AM

I wanted to point out that PythonAnywhere can be used to connect and work with Carriots.  I've asked PythonAnywhere to whitelist api.carriots.com on their free account, so that all can access Carriots and they did!  This means you can write Python scripts or use a Python console to interact with Carriots.  Furthermore you can write your front-end app or web interface in Python and have Carriots be your backend.

 

Perhaps in this thread we can post various scripts for using Carriots API with Python.  I'll get things started.  Add your own code for others to use.

 

In my streams I have a bunch of bogus test data that I wanted to clean out.  Sure, it probably isn't hurting anything by being there, however, I don't need it and it helps to test and work with known good information and a clean slate.  The following bit of Python code uses Requests to get a List of streams from Carriots and then Delete each stream.  BE CAREFUL RUNNING THIS CODE - IT WILL DELETE!  

 

[EDIT]  A double warning, this code will delete both Status Streams and Data Streams unless you specify a parameter to narrow down the list.  See the API and the use of ?_t=sta.[/EDIT]

 

If you want to filter the list from Carriots, look at List in the API and then add elements in the params section.  For instance  you can filter the list that is retrieved from Carriots for a specific device.  Just add your device's name and comment the params line.

 

Be sure to insert your API Key.

 

This code is using Python 2.7 and uses Requests and JSON.

import requests, json

app_url = "http://api.carriots.com/"
app_element = "streams/"
app_filter = ""
app_key = "Your_API_Key_Here"

headers = {"carriots.apikey":app_key}

#Enter any filter parameters in the params section below
params = {}
#params = {'device': 'testDevice@carriots'}

print ""

print "Getting streams from Carriots..."
carriotsResponse = requests.get(app_url + app_element, params=params, headers=headers)
binary = carriotsResponse.content
output = json.loads(binary)

#Print all streams retrieved
#print output

print "There are " + str(len(output['result'])) + " streams retrieved from Carriots."

print "Deleting each stream..."
good = 0
fail = 0

for stream in range(len(output['result'])):
    carriotsResponse = requests.delete(app_url + app_element + output['result'][stream]['id_developer'] + "/", headers=headers)

    if carriotsResponse.status_code == requests.codes.ok:
        good += 1
    else:
        fail += 1

print ""

print "Total streams processed: good=" + str(good) + " fail=" + str(fail)
print ""



#140 Listener Event for Device Status change?

Posted by Zambiot on 29 March 2013 - 01:26 AM

My listener is working as I would like.  Thank you for the help.  The following is summary of the complete setup so that others can make use of this knowledge.

 

This is a listener that sends an e-mail when a device goes online or offline in a Group.  That is when the "status" changes.

 

1.  Set up your device in Carriots.  Choose a value for "Data Stream Frequency".  For me, I choose a value that was slightly longer than what my device is programmed to update as there can be various network delays and tolerances.  So, say you have a device that posts data once a minute to Carriots, I'd recommend a value of 2, for 2 minutes.  If your device is posting once every 10 minutes, then maybe a value of 11 or 12 minutes.  Status of the device is based on this frequency.  Lets say your device has been logging away at 1 minute intervals.  If, your frequency is set to 2 and you device goes offline, the Status will change 2 minutes after the last data point was logged.  As soon as you device begins logging again, the status is changed again.

 

2.  Create a new listener.  The listener in this example is setup to monitor a Group, but the listener could be for a specific device, asset, project, etc.  In creating the listener, enter the name, description, entity type and ID.

 

3.  For the listener's event, use "Event Device Change State".

4.  For the "If Expression" use "true".

5.  For the "Then Expression" use the following code.  

import com.carriots.sdk.utils.Email;
def email = new Email();
email.to="myemail@mydomain.com";

if (context.data.reason.status=="ok"){
email.subject="Status is OK for " + context.hierarchy.device.id_developer;}
else {
email.subject="Status is not OK for " + context.hierarchy.device.id_developer;}

email.send();

 

There is one thing that you need to edit, it is the e-mail address.  Change "myemail@mydomain.com" to the e-mail address you would like the Status e-mail sent to.

 

Save your listener.  Next time your device comes online and Status is OK, you should get an e-mail.  If you device goes offline and Status is Not OK, you should get an e-mail.  




#116 First Carriots Challenge information

Posted by dompablo on 21 March 2013 - 11:53 AM

You can see it in action in this video.

 

 

It's incredible!

 

Haha, funny video, i've seen a hand appearing in 0:27.




#819 Reducing Power Consumption on Arduino UNO with CC3000 Breakout Board

Posted by sdeancos on 11 May 2015 - 07:20 AM

Great job Glen!

 

It is very interesting!

 

Thank you for sharing your work with the community.

 

BR.