Arduino Uno, CC3000, Sensor, Serial input

Hello all
:cold_sweat: :cold_sweat: :cold_sweat: =( =( =( =( =( =( =( :fearful: :fearful: :fearful:

need a project with Arduino Uno to collect sensor data
through a serial port and then go to your page via wifi xively CC3000

Here I present my algorithm has errors does not display data xively.

someone help me I am very new to this topic.

sketch:

// Libraries
#include <SoftwareSerial.h>
#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
#include <string.h>
#include “utility/debug.h”
#include<stdlib.h> //add the soft serial libray

// Define pin cominication serial
#define rxpin A1 //set the RX pin to pin 2
#define txpin A2 //set the TX pin to pin 3

//enable the soft serial port input
SoftwareSerial myserial(rxpin, txpin);

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

// Use hardware SPI for the remaining pins
// On an UNO, SCK = 13, MISO = 12, and MOSI = 11

// WiFi network (change with your settings !)
#define WLAN_SSID “INFINITUM8DBE33”
#define WLAN_PASS “BC34675B04”
#define WLAN_SECURITY WLAN_SEC_WPA2

// 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

// Xively parameters
#define WEBSITE “https://api.xively.com
#define API_key “HeWQmJNbqjoUWmdg8NwCBIMNgLwOvqrALROFoJ4fhoLddsCH”
#define feedID “1645357341”

uint32_t ip;

String sensorstring = “”; //a string to hold the data from the Atlas Scientific product
boolean sensor_stringcomplete = false; //have we received all the data from the Atlas Scientific product

char sensorstringId = “flow meter”;

void setup()
{
Serial.begin(115200); //set baud rate for the hardware serial port to 38400
Serial.println(“Flow Meter Gas o Nest”);
myserial.begin(38400); //set baud rate for software serial port to 38400

Serial.println(F("\nInitializing CC3000…!"));
if (!cc3000.begin())
{
Serial.println(F(“Couldn’t begin()! Check your wiring?”));
while(1);
}

}

void loop()
{
// Connect to WiFi network
cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY);
Serial.println(F(“Accesando a Punto de Acceso”));

/* Wait for DHCP to complete */
Serial.println(F(“Request DHCP”));
while (!cc3000.checkDHCP())
{
delay(100);
}

// Set the website IP
uint32_t ip = cc3000.IP2U32(216,52,233,120);
cc3000.printIPdotsRev(ip);

// Get data & transform to integers
float s = (char)myserial.read();

int sensorstring = (int) s;

while (myserial.available()) { //while a char is holding in the serial buffer
char inchar = (char)myserial.read(); //get the new char
sensorstring += inchar; //add it to the sensorString
if (inchar == ‘\r’) {sensor_stringcomplete = true;} //if the incoming character is a , set the flag
}

if (sensor_stringcomplete)
{ //if a string from the Atlas Scientific product has been received in its entirety
Serial.print(sensorstring); //use the hardware serial port to send that data to the PC
int sensorstring = (int) s; //sensorstring = “”; //clear the string:
sensor_stringcomplete = false; //reset the flag used to tell if we have received a completed string from the Atlas Scientific product

// Prepare JSON for Xively & get length
int length = 0;

String data = “”;

data = data + “\n” + “{“version”:“1.0.0”,“datastreams” : [ {“id” : “TOTAL LITERS”,“current_value” : “” + int(sensorstring) + “”},”

  • “]}”;

length = data.length();
Serial.print(“Data length”);
Serial.println(length);
Serial.println();

// Print request for debug purposes
Serial.print(“PUT /v1/feeds/”);
Serial.print(feedID);
Serial.println(".json HTTP/1.0");
Serial.println(“Host: api.xively.com”);
Serial.print("X-ApiKey: ");
Serial.println(API_key);
Serial.print("Content-Length: ");
Serial.println(length, DEC);
Serial.print(“Connection: close”);
Serial.println();
Serial.print(data);
Serial.println();

// Send request
Adafruit_CC3000_Client client = cc3000.connectTCP(ip, 80);
if (client.connected()) {
Serial.println(“Connected!”);
client.println(“PUT /v2/feeds/” + String(feedID) + “.json HTTP/1.0”);
client.println(“Host: api.xively.com”);
client.println("X-ApiKey: " + String(API_key));
client.println("Content-Length: " + String(length));
client.print(“Connection: close”);
client.println();
client.print(data);
client.println();
} else {
Serial.println(F(“Connection 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"));
cc3000.disconnect();

// Wait 10 seconds until next update
delay(10000);

}
}

serial_input_a_cc3000_xively.ino (5.61 KB)

1)check your baudrate change it to 9600.

2)Show your connection diagram. If you using sheild share us datasheet & link from where you have purchased.

3)

// Define pin cominication serial

define rxpin A1 //set the RX pin to pin 2

define txpin A2

instead of using analog pin use pin 8 & pin 9 pins of arduino UNO , Also change baudrate

4)put snapshot of Serial Monitor Window to understand where you are going wrong.

Ok anexo esquema de conexions

Hi.

Please use code tags… See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

Tom… :slight_smile: