0

HOW TO SEND DATA TO OWN WEBPAGE WITH CC3000 [CLOSED]
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

HOW TO SEND DATA TO OWN WEBPAGE WITH CC3000 [CLOSED]

by treeTrunksPi on Thu Sep 29, 2016 5:12 am

Good day!
I would really appreciate your help.

I'm trying to send data using Adafruit's cc3000.
I'm using WebClient sketch from Adafruit_CC3000 library.

I changed the SSID and Password and
Code: Select all | TOGGLE FULL SIZE
#define WEBSITE      "www.website.com"
#define WEBPAGE     "/pages/module_loc.php?dt=2016-09-29+08:31:00&stat=1&lng=14.549155&lat=121.027719"

The problem is it doesn't continue into storing the data to the webpage.

If I just type
Code: Select all | TOGGLE FULL SIZE
http://website.com/pages/module_loc.php?dt=2016-09-29+08:31:00&stat=1&lng=14.549155&lat=121.027719
to the url address bar it loads and it stores the data to the database

but if I place use this webclient sketch
Code: Select all | TOGGLE FULL SIZE
/***************************************************
  This is an example for the Adafruit CC3000 Wifi Breakout & Shield

  Designed specifically to work with the Adafruit WiFi products:
  ----> https://www.adafruit.com/products/1469

  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried & Kevin Townsend for Adafruit Industries. 
  BSD license, all text above must be included in any redistribution
 ****************************************************/
 
 /*
This example does a test of the TCP client capability:
  * Initialization
  * Optional: SSID scan
  * AP connection
  * DHCP printout
  * DNS lookup
  * Optional: Ping
  * Connect to website and print out webpage contents
  * Disconnect
SmartConfig is still beta and kind of works but is not fully vetted!
It might not work on all networks!
*/
#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
#include <string.h>
#include "utility/debug.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

#define WLAN_SSID       "TESTWIFI"           // cannot be longer than 32 characters!
#define WLAN_PASS       "PASS"
// Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2
#define WLAN_SECURITY   WLAN_SEC_WPA2

#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.

// What page to grab!
#define WEBSITE      "www.website.com"
#define WEBPAGE      "/pages/module_loc.php?dt=2016-09-29+15:30:00&stat=1&lng=14.549155&lat=121.027719"


/**************************************************************************/
/*!
    @brief  Sets up the HW and the CC3000 module (called automatically
            on startup)
*/
/**************************************************************************/

uint32_t ip;

void setup(void)
{
  Serial.begin(115200);
  Serial.println(F("Hello, CC3000!\n"));

  Serial.print("Free RAM: "); Serial.println(getFreeRam(), DEC);
 
  /* Initialise the module */
  Serial.println(F("\nInitializing..."));
  if (!cc3000.begin())
  {
    Serial.println(F("Couldn't begin()! Check your wiring?"));
    while(1);
  }
 
  // Optional SSID scan
  // listSSIDResults();
 
  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!"));
 
  /* Wait for DHCP to complete */
  Serial.println(F("Request DHCP"));
  while (!cc3000.checkDHCP())
  {
    delay(100); // ToDo: Insert a DHCP timeout!
  } 

  /* Display the IP address DNS, Gateway, etc. */ 
  while (! displayConnectionDetails()) {
    delay(1000);
  }

  ip = 0;
  // Try looking up the website's IP address
  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);
 
  // Optional: Do a ping test on the website
  /*
  Serial.print(F("\n\rPinging ")); cc3000.printIPdotsRev(ip); Serial.print("..."); 
  replies = cc3000.ping(ip, 5);
  Serial.print(replies); Serial.println(F(" replies"));
  */ 

  /* Try connecting to the website.
     Note: HTTP/1.1 protocol is used to keep the server from closing the connection before all data is read.
  */
  Adafruit_CC3000_Client www = cc3000.connectTCP(ip, 80);
  if (www.connected()) {
    www.fastrprint(F("GET "));
    www.fastrprint(WEBPAGE);
//    www.fastrprint(F(" HTTP/1.1\r\n"));
//    www.fastrprint(F("Host: "));
    www.fastrprint(WEBSITE);
//    www.fastrprint(F("\r\n"));
//    www.fastrprint(F("\r\n"));
    www.println();
  } else {
    Serial.println(F("Connection failed"));   
    return;
  }

  Serial.println(F("-------------------------------------"));
 
  /* 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("-------------------------------------"));
 
  /* You need to make sure to clean up after yourself or the CC3000 can freak out */
  /* the next time your try to connect ... */
  Serial.println(F("\n\nDisconnecting"));
  cc3000.disconnect();
 
}

void loop(void)
{
 delay(1000);
}

/**************************************************************************/
/*!
    @brief  Begins an SSID scan and prints out all the visible networks
*/
/**************************************************************************/

void listSSIDResults(void)
{
  uint32_t index;
  uint8_t valid, rssi, sec;
  char ssidname[33];

  if (!cc3000.startSSIDscan(&index)) {
    Serial.println(F("SSID scan failed!"));
    return;
  }

  Serial.print(F("Networks found: ")); Serial.println(index);
  Serial.println(F("================================================"));

  while (index) {
    index--;

    valid = cc3000.getNextSSID(&rssi, &sec, ssidname);
   
    Serial.print(F("SSID Name    : ")); Serial.print(ssidname);
    Serial.println();
    Serial.print(F("RSSI         : "));
    Serial.println(rssi);
    Serial.print(F("Security Mode: "));
    Serial.println(sec);
    Serial.println();
  }
  Serial.println(F("================================================"));

  cc3000.stopSSIDscan();
}

/**************************************************************************/
/*!
    @brief  Tries to read the IP address and other connection details
*/
/**************************************************************************/
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 is what shows:
Code: Select all | TOGGLE FULL SIZE
Free RAM: 7131

Initializing...

Attempting to connect to TESTWIFI
Connected!
Request DHCP

IP Addr: 192.168.1.8
Netmask: 255.255.255.0
Gateway: 192.168.1.1
DHCPsrv: 192.168.1.1
DNSserv: 192.168.1.1
www.website.com -> 182.50.x.x

Can anyone please show me the code of http://www.adafruit.com/testwifi/index.html?
Last edited by treeTrunksPi on Thu Sep 29, 2016 11:08 pm, edited 2 times in total.

treeTrunksPi
 
Posts: 24
Joined: Mon Feb 02, 2015 2:38 am

Re: HOW TO SEND DATA TO WEBPAGE

by adafruit_support_rick on Thu Sep 29, 2016 11:47 am

Don't you want to do a POST instead of a GET?

adafruit_support_rick
 
Posts: 35091
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: HOW TO SEND DATA TO WEBPAGE

by treeTrunksPi on Thu Sep 29, 2016 8:52 pm

It still doesn't continue.

Can you tell me more about this part?
Code: Select all | TOGGLE FULL SIZE
  Adafruit_CC3000_Client www = cc3000.connectTCP(ip, 80);
  if (www.connected()) {
    www.fastrprint(F("POST "));
    www.fastrprint(WEBPAGE);
    www.fastrprint(F(" HTTP/1.1\r\n"));
    www.fastrprint(F("Host: ")); www.fastrprint(WEBSITE); www.fastrprint(F("\r\n"));
    www.fastrprint(F("\r\n"));
    www.println();
  } else {
    Serial.println(F("Connection failed"));   
    return;
  }

Changed some of my codes.

This is the revised Webclient.ino
Code: Select all | TOGGLE FULL SIZE
#define WEBSITE      "www.website.com"
#define WEBPAGE      "/pages/module_car.php?em=email@gmail.com&pw=s7jjejqf&dt=2016-09-30+08:30:00&stat=1&lng=14.549155&lat=121.027719"

Code: Select all | TOGGLE FULL SIZE
    www.fastrprint(F("POST "));
    www.fastrprint(WEBPAGE);
    www.fastrprint(F(" HTTP/1.1\r\n"));
    www.fastrprint(F("Host: ")); www.fastrprint(WEBSITE); www.fastrprint(F("\r\n"));
    www.fastrprint(F("\r\n"));
    www.println();


This is my code from module_car.php
Code: Select all | TOGGLE FULL SIZE
<?php
include("config.php");

if($_SERVER["REQUEST_METHOD"] == "GET") {

    $email = $_GET['em'];
    $password = $_GET['pw'];
    $date_time = $_GET['dt'];
    $longitude = $_GET['lng'];
    $latitude = $_GET['lat'];
    $status = $_GET['stat'];
   
    echo ($email . '<br>'. $password . '<br>' . $date_time . '<br>' . $longitude . '<br>' . $latitude . '<br>' . $status);
   
    $module_card_check = "SELECT `email`, `password` FROM account WHERE `email` = '$email' AND `password` = '$password'";
   
    $result1 = mysqli_query($db, $module_car_check) or die("Error: ".mysqli_error($db));
    $row = mysqli_fetch_array($result1, MYSQLI_ASSOC);
    $count = mysqli_num_rows($result1);

   
    echo($count);
   
    if($count == 1) {
        $module_car_query = "INSERT INTO car_monitoring (`date_time`, `status`, `longitude`, `latitude`)
                     VALUES('$date_time', '$status', '$longitude', '$latitude');";
       
        mysqli_query($db, $module_card_query) or die("Error: ".mysqli_error($db));
       
        echo("
                <h1 style='color: green'>OK</h1>
            ");
        mysqli_close($db);
    }
    else {
        echo("
                <h1 style='color: red'>ERROR</h1>
            ");
        mysqli_close($db);
    }
}
?>
Last edited by treeTrunksPi on Tue Oct 04, 2016 10:03 pm, edited 1 time in total.

treeTrunksPi
 
Posts: 24
Joined: Mon Feb 02, 2015 2:38 am

Re: HOW TO SEND DATA TO OWN WEBPAGE WITH CC3000

by treeTrunksPi on Thu Sep 29, 2016 11:05 pm

Thank you for your reply

This is closed. I think it has something to do with length.
Admin, does anyone know the maximum length of the WEBPAGE?

treeTrunksPi
 
Posts: 24
Joined: Mon Feb 02, 2015 2:38 am

Re: HOW TO SEND DATA TO OWN WEBPAGE WITH CC3000 [CLOSED]

by adafruit_support_mike on Fri Sep 30, 2016 3:54 am

It depends on how you're trying to handle it in memory. If you're just printing the data to a Serial Monitor as it goes past, you can keep going all day. If you're trying to store the page so you can search for some piece of text, you're limited by the amount of free memory in your microcontroller.

adafruit_support_mike
 
Posts: 53141
Joined: Thu Feb 11, 2010 2:51 pm

Please be positive and constructive with your questions and comments.