Jump to content









Photo

Stream data not appearing in carriot


  • Please log in to reply
2 replies to this topic

#1 cevert

cevert

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 07 October 2016 - 06:43 PM

Using an arduino uno with a adafruit cc3000 wifi shield. The code looks to be looping and running correctly but I cannot see any data in data stresms. Most of this has been copied and pasted from example codes with little pieces here and there being added. I am pretty new with arduinos and this is only my 3 or 4h project

 

#include <OneWire.h>
#include <DallasTemperature.h>

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


#define ONE_WIRE_BUS_PIN 2
#define DS18B20 8 
#define ADAFRUIT_CC3000_IRQ   3  
#define ADAFRUIT_CC3000_VBAT  5
#define ADAFRUIT_CC3000_CS    10

#define WLAN_SSID       "****"
#define WLAN_PASS       "****"
#define WLAN_SECURITY   WLAN_SEC_WPA2

#define WEBSITE  "api.carriots.com"

const String API_KEY = "*******";
const String DEVICE =  "*******";

OneWire oneWire(ONE_WIRE_BUS_PIN);
DallasTemperature sensors(&oneWire);

DeviceAddress Probe01 = { 0x28, 0x4E, 0x7D, 0x1A, 0x06, 0x00, 0x00, 0x0B }; 
DeviceAddress Probe02 = { 0x28, 0x34, 0xE2, 0xE9, 0x06, 0x00, 0x00, 0x7D };

Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,
                                         SPI_CLOCK_DIV2);

uint32_t ip;




void setup()   
{
  // start serial port to show results
  Serial.begin(115200);
  Serial.print("Initializing Temperature Control Library Version ");
  Serial.println(DALLASTEMPLIBVERSION);
  
  sensors.begin();
  
  sensors.setResolution(Probe01, 10);
  sensors.setResolution(Probe02, 10);

  Serial.println(F("\nInitializing..."));
  if (!cc3000.begin())
  {
    Serial.println(F("Couldn't begin()! Check your wiring?"));
    while(1);
  }
 cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY);
  Serial.println(F("Connected!"));
  
  /* Wait for DHCP to complete */
  Serial.println(F("Request DHCP"));
  while (!cc3000.checkDHCP())
  {
    delay(100);
  }  
 
  // Get the website IP & print it
  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);
}



void loop(){
  sensors.requestTemperatures(); 

  Serial.println();
  Serial.print("Number of Devices found on bus = ");  
  Serial.println(sensors.getDeviceCount());   

 
  Serial.print("Probe 01 (DS18B20) temperature is: C ");
  Serial.print(sensors.getTempC(Probe01));
  Serial.println();

  Serial.print("Probe 02 (DS18B20U) temperature is: C ");
  Serial.print(sensors.getTempC(Probe02));
  Serial.println();
 Serial.println();
  Serial.println();
   Serial.println();
   
 String t1 = doubleToString(sensors.getTempC(Probe01),2);
 String t2 = doubleToString(sensors.getTempC(Probe02),2);



String data = "{\"protocol\":\"v2\",\"device\":\""+DEVICE+"\",\"at\":\"now\",\"data\":{\"T1\":"+String(t1)+"}}";
    int thisLength = data.length();

//,\"Temperatur02\":"+String(temp2)+"


  Serial.println("POST /streams HTTP/1.1");
  Serial.println("Host: api.carriots.com");
  Serial.println("Accept: application/json");
  Serial.println("User-Agent: Arduino-Carriots");
  Serial.println("Content-Type: application/json");
  Serial.println("carriots.apikey: " + API_KEY);
  Serial.println("Content-Length: " + String(thisLength));
  Serial.print("Connection: close");
  Serial.println();
  Serial.println(data);
  
  // Send request
  Adafruit_CC3000_Client client = cc3000.connectTCP(ip, 80);
  if (client.connected()) {
    Serial.println("Connected!");
    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.println("carriots.apikey: ");
    client.println(String(API_KEY));
    client.println("Content-Length: ");
    client.println(String(thisLength));
    client.println("Connection: close");
    client.println();
    client.println(data);
    
  } else {
    Serial.println(F("Connection failed"));    
    return;
  }
 delay(60000);
}

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);
  }
}

 


 



#2 cevert

cevert

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 07 October 2016 - 08:19 PM

New progress has been made

 

This is the error that is occuring

 

HTTP/1.1 401 Unauthorized
Date: Fri, 07 Oct 2016 20:17:42 GMT
Content-Type: application/vnd.carriots.api.v2+json
Content-Length: 33
Server: Carriots REST API
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true-Length,Content-Type,Cache-Control
Connection: close
 
{ "response": "Not authorized." }-------------------------------------
 
 
Uno is currently at 83% program storage


#3 Yoleon

Yoleon

    Sugar Master

  • Members
  • PipPipPip
  • 30 posts

Posted 10 October 2016 - 10:54 AM

Hi Cervet,

 

I have been looking the code and i have found an error in the construction of the variable "data".

 

String data = "{\"protocol\":\"v2\",\"device\":\""+DEVICE+"\",\"at\":\"now\",\"data\":{\"T1\":"+String(t1)+"}}";

 

You need to escape the quotes in the variable "t1":

 

String data = "{\"protocol\":\"v2\",\"device\":\""+DEVICE+"\",\"at\":\"now\",\"data\":{\"T1\":\""+String(t1)+"\"}}";

 

You can also check the API KEY to verify that is not read only.

 

I hope this help you.

 

Carriots Staff






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users