1

I tried this code:

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

// These are the interrupt and control pins
#define ADAFRUIT_CC3000_IRQ   3  // MUST be an interrupt pin!
// These can be any two pins
#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
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT, SPI_CLOCK_DIVIDER); // you can change this clock speed


// WLAN parameters
#define WLAN_SSID       "ID"
#define WLAN_PASS       "PASS"
#define WLAN_SECURITY   WLAN_SEC_WPA


#define IDLE_TIMEOUT_MS  3000      // Amount of time to wait (in milliseconds) with no data 
                                   // received before closing the connection.  If you know the server
                                   // you're accessing is quick to respond, you can reduce this value.
#define DHTPIN 7
#define DHTTYPE DHT11



// What page to grab!
#define WEBSITE      "myapp.herokuapp.com" //your website

uint32_t ip;
DHT dht(DHTPIN, DHTTYPE);

const unsigned long connectTimeout  = 15L * 1000L;
void setup(void)
{
    Serial.begin(115200);
    //Serial.begin(9600);
    Serial.println(F("\nInitializing..."));
    if (!cc3000.begin())
  {
    Serial.println(F("Couldn't begin()! Check your wiring?"));
    while(1);
  }
    Serial.print(F("\nAttempting to connect to ")); Serial.println(WLAN_SSID);
    if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
    Serial.println(F("Failed!"));
    while(1);
  }
    Serial.println(F("Connected!"));

    Serial.println(F("Request DHCP"));
  while (!cc3000.checkDHCP())
  {
    delay(100); // ToDo: Insert a DHCP timeout!
  }  
  ///if he login and he can show info/ mean he login and only then continue
    while (! displayConnectionDetails()) {
    delay(1000);
  }
}



void loop(void)
{
 float h = dht.readHumidity();
  float t = dht.readTemperature();

  int temperature = (int) t;
  int humidity = (int) h;

  String temperatures=String(temperature);
  String humiditys=String(humidity);

  Serial.print("Temperature: ");
  Serial.print(temperatures);
  Serial.print(" F /");
  Serial.print("Humidity: ");
  Serial.print(humiditys);
  Serial.print("%");
  Serial.println("");

   // Create the request.
  String request = "GET /plants/0003/create_measurement?capsules=1&humidity=" + humiditys + "&soil_moisture=40&temperature=" + temperatures + " &water_tank=10&light=20&battery=4 HTTP/1.1\r\n";
  // Print and Send the request
  Serial.println("About to send: ");
  Serial.print(request);
  Serial.print(F("Host: "));
  Serial.print(WEBSITE);
  Serial.print(F("\r\n"));
  Serial.print(F("User-Agent: Compost Monitor/1.0\r\n"));
  Serial.println();
  send_request(request);

}

void send_request (String request)
{
  Serial.println("Enter Request");
  ip = 0;
  // Try looking up the website's IP address
  Serial.print(WEBSITE); Serial.print(F(" -> "));
  while (ip == 0) {
    if (cc3000.getHostByName(WEBSITE, &ip)<0) {
      Serial.println(F("Couldn't resolve!"));
    }
    delay(500);
  }


  cc3000.printIPdotsRev(ip);
    Serial.println();
Serial.println("after Ip");

  Adafruit_CC3000_Client www ;
   unsigned long t = millis();

do {
    Serial.println("Into do");
   www = cc3000.connectTCP(ip, 80);
} while((!www.connected()) &&
    ((millis() - t) < connectTimeout));

  String b="0";
  if(www.connected())
  {
  b="1";
  }
  Serial.println("! Out Do" + b);
  if (www.connected()) {
    www.print(request);
    www.print(F("Host: "));
    www.print(WEBSITE);
    www.print(F("\r\n"));
    www.print(F("User-Agent: Compost Monitor/1.0\r\n"));
    www.print(F("\r\n"));
    www.println();
  } else {
    Serial.println(F("Connection failed"));
    return;
  }

  Serial.println(F("-------------------------------------"));
Serial.println("time to reed");
  /* Read data until either the connection is closed, or the idle timeout is reached. */
  unsigned long lastRead = millis();
  while (www.connected() && (millis() - lastRead < IDLE_TIMEOUT_MS)) {
    while (www.available()) {
      char c = www.read();
      Serial.print(c);
      lastRead = millis();
    }
  }
  www.close();
  Serial.println(F("-------------------------------------"));
Serial.println("no time to reed");

}



bool displayConnectionDetails(void)
{
  uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv;

  if(!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv))
  {
    Serial.println(F("Unable to retrieve the IP Address!\r\n"));
    return false;
  }
  else
  {
    Serial.print(F("\nIP Addr: ")); cc3000.printIPdotsRev(ipAddress);
    Serial.print(F("\nNetmask: ")); cc3000.printIPdotsRev(netmask);
    Serial.print(F("\nGateway: ")); cc3000.printIPdotsRev(gateway);
    Serial.print(F("\nDHCPsrv: ")); cc3000.printIPdotsRev(dhcpserv);
    Serial.print(F("\nDNSserv: ")); cc3000.printIPdotsRev(dnsserv);
    Serial.println();
    return true;
  }
}

This sends data to my server. However, no entries are appearing on my server.

  • Welcome to Arduino.SE. Please can you explain your problem? What exactly are you trying to do, and what's not working? – Peter Bloomfield Jul 31 '14 at 14:55
  • hii Peter R. Bloomfield. i try to send the Temperture and Humidity to my server by send them with cc3000 i did like i post (that the full// only without the name of app) and it all work it get to the end but it not adding a record on my server that program should to add to id ="0003" a new record with all the Info such as: capsules=true humidity=37 // as example untill the end but still it not add the record – Asaf Shazar Jul 31 '14 at 14:56
  • Welcome to Arduino SE! This seems more like a server issue than an Arduino issue... is there any way to verify the server is working and this code isn't? Also, what have you tried? Can you narrow it down to a small section of the code? – Anonymous Penguin Jul 31 '14 at 15:19
  • use requestmaker.com to send a properly formatted GET request to your heroku app. If it works, it is your Arduino code, if not, it is your app. – geometrikal Jul 31 '14 at 15:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.