Jump to content









Photo

Stream data not appearing in carriot


  • Please log in to reply
6 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
  • 43 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



#4 manixphegan

manixphegan

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 05 December 2017 - 10:17 AM

Not able to get the data stream through Arduino. Tried to hard code the data, api, etc....still not able to get the data stream from Arduino. Can anyone help me out with it.
I am trying to post data to a web server using Arduino Uno with Ardunio Wifi Shield
 
Here is my code.
 
=====================================================================
 
#include <SPI.h>
#include <WiFi.h>
#include <MFRC522.h>
       // You must include the library here in order to use it in the sketch
 
 
      
const int numElements=3;        // Specify the number of rows in your array, in this case 3
 
#define RST_PIN         9          // Configurable, see typical pin layout above
#define SS_PIN         6        // Configurable, see typical pin layout above
 
MFRC522 mfrc522(SS_PIN, RST_PIN);  // Create MFRC522 instance
char ssid[] = "PheganExportsFO";     //  your network SSID (name)
char pass[] = "phegan@12345";  // your network password
int status = WL_IDLE_STATUS;     // the Wifi radio's status
 
 
 
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
//byte mac[] = {  0x90, 0xA2, 0xDA, 0x10, 0xAE, 0xB8 };
//IPAddress ip(192,168,0,19);       // PLEASE INPUT THE IP Address
 
//SendCarriots sender;              // Instantiate an instance of the SendCarriots library
 
void setup() {
  Serial.begin(9600);               // Start serial port
  Serial.println(F("Starting"));
 
while (!Serial);    // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
  SPI.begin();      // Init SPI bus
  
 // Wifi Stuff
 // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue:
    while (true);
  }
 
  // attempt to connect to Wifi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to WPA SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network:
    status = WiFi.begin(ssid, pass);
  
    // wait 10 seconds for connection:
    delay(1000);
  }
 
}
 
void loop() {
      // Using the instance of the library, call the method send
  IPAddress server(82,223,244,60);
  WiFiClient client;
  if (client.connect(server, 80)) {   // If there's a successful connection
    Serial.println(F("connected"));
 
     String json = "{\"protocol\":\"v2\",\"device\":\"SensorRFIDPhegan1@manixphegan.manixphegan\",\"at\":\"now\",\"data\":{\"weight\":\"14536\"}}";
    
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: SensorRFIDPhegan1@manixphegan.manixphegan");
    client.println("Content-Type: application/json");
    client.print("carriots.apikey: 0b457d44f2aa539de59eb8554b744e2dc6b1babd5a7a3f2eaa487baaf4ba316c");
    client.print("Content-Length: ");
    int thisLength = json.length();
    client.println(thisLength);
    client.println("Connection: close");
    client.println();
client.println(json);
                                                                         
}
}


#5 spidernz

spidernz

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 07 December 2017 - 07:10 PM

Looks like you need to remove the '//' from the following lines

 

//byte mac[] = {  0x90, 0xA2, 0xDA, 0x10, 0xAE, 0xB8 };
//IPAddress ip(192,168,0,19);       // PLEASE INPUT THE IP Address
 
//SendCarriots sender;              // Instantiate an instance of the SendCarriots library
 
Also add the following lines:
 

IPAddress myDns(yyy.yyy.yyy.yyy);

IPAddress gateway(xxx.xxx.xxx.xxx);

IPAddress subnet(255.255.255.0);

 

You will need to replace yyy.yyy.yyy.yyy with the IP address of your local DNS server.

And xxx.xxx.xxx.xxx with the IP address of your local gateway.



#6 ciuccmama

ciuccmama

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 19 December 2017 - 02:39 AM

I'm having a similar problem, this is my first time trying to get Arduino to push data to the cloud.  My sketch seems to be working fine and data is coming out of my Arduino but the device remains "Disconnected" from Carriots and I can't seem to figure out how to fix it.

 

My code is below, any help is greatly appreciated!

 

#include <WiFi.h>
 
char ssid[] = "XXXXX";     //  network SSID (XXX'd for security, it's correct in my code) 
char pass[] = "XXXXXX";    // network password
int status = WL_IDLE_STATUS;     // the Wifi radio's status
int val = 0;
const char* server = "api.carriots.com";
const String APIKEY = "long string of numbers in here, removed for security";
const String DEVICE = "SoilMoisture@ciuccmama.ciuccmama"; // your deviceID
WiFiClient client;
 
byte mac[] = {  0x90, 0xA2, 0xDA, 0x0F, 0xE2, 0x83 };
IPAddress ip(192,168,0,19); 
 
void setup() {
  // initialize serial:
  Serial.begin(9600);
 
  // attempt to connect using WPA2 encryption:
  Serial.println("Attempting to connect to WPA network...");
  status = WiFi.begin(ssid, pass);
 
  // if you're not connected, stop here:
  if ( status != WL_CONNECTED) { 
    Serial.println("Couldn't get a wifi connection");
    while(true);
  } 
  // if you are connected, print out info about the connection:
  else {
    Serial.println("Connected to network");
  }
}
 
void sendStream()
{
  //const int httpPort = 80;
  if (client.connect(server, 80)) {   // If there's a successful connection
    Serial.println(F("connected"));
 
    String json = "{\"protocol\":\"v2\",\"device\":\""+DEVICE+"\",\"at\":\"now\",\"data\":{\"weight\":\""+val+"\"}}";
 
    // 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);
  }
  else {
    // If server connection failed:
    Serial.println(F("connection failed"));
  }
}
void loop() {
  IPAddress server(82,223,244,60);
  IPAddress myDns(192,168,231,1);
  IPAddress gateway(192,168,231,1);
  IPAddress subnet(255,255,255,0);
  val = analogRead(A0);
  Serial.println(val);
  Serial.println(F("Send Data"));
  sendStream();
  delay(3000);
 
  client.flush();
  client.stop();
}


#7 jpastor

jpastor

    Development leader

  • Administrators
  • 176 posts

Posted 26 December 2017 - 03:22 PM

Hi friend

 

Try with this modification in your function "sendStream":

 

void sendStream()
{
  //const int httpPort = 80;
  if (client.connect(server, 80)) {   // If there's a successful connection
    Serial.println(F("connected"));

    // construct the data json
    String json = "{\"protocol\":\"v2\",\"device\":\"" + DEVICE + "\",\"at\":\"now\",";
    String json2 = "\"data\":{\"moisture\":\"" + String(val) + "\"}}";

    // Make an 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()+json2.length();
    client.println(thisLength);
    client.println("Connection: close");
    client.println();
    client.print(json);
    client.println(json2);
  }
  else {
    // If server connection failed:
    Serial.println(F("connection failed"));
  }
}

 

The library "Wifi.h" has some limits with the number of character to send, but if you divide the lines it works.

 

Hope it helps!






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users