Evothings on arduino cc3000 wifi board

Ask, and ye shall receive.
renan
Posts: 2
Joined: 23:05, 04 Oct 2014

Evothings on arduino cc3000 wifi board

Postby renan » 23:20, 04 Oct 2014

I was trying to adapt the evothings example Arduino LED On/Off TCP code to a cc3000 wifi shield board, using the Adafruit Library.
Below the example code of the WebClient library(it worked this way. My board could connect).

Code: Select all

#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       "myNetwork"           // cannot be longer than 32 characters!
#define WLAN_PASS       "myPassword"
// 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.adafruit.com"
#define WEBPAGE      "/testwifi/index.html"


/**************************************************************************/
/*!
    @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);
 
  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;
  }
}


How can I use Arduino LED On/Off TCP with this code?

User avatar
micke
Posts: 256
Joined: 20:49, 18 Nov 2013

Re: Evothings on arduino cc3000 wifi board

Postby micke » 17:55, 05 Oct 2014

Hi Renan,

I am not familiar with the Adafruit_CC3000 library, but what I would do is to take the source from arduinowifi.ino and step by step replace the WiFi code to use the CC3000 library.

Is CC3000 not compatible with the Arduino WiFi library? Would it work to just use the unmodified code from arduinowifi.ino? Says on the product page it is compatible, but I have not used Adafruit boards unfortunately.

Best regards, Mikael

renan
Posts: 2
Joined: 23:05, 04 Oct 2014

Re: Evothings on arduino cc3000 wifi board

Postby renan » 21:25, 06 Oct 2014

I run the arduinowifi.ino and the board couldn't find the shield, then I tried with examples of the arduino wifi examples and again the same result.
When I tried with the Adafruit_CC3000 library the board was capable to find the shield and communicate.
I believe CC3000 is not compatible with the Arduino WiFi library but I'm not sure.
I'll try to follow your advice, tks for the fast reply.

Best Regards,

Renan

User avatar
micke
Posts: 256
Joined: 20:49, 18 Nov 2013

Re: Evothings on arduino cc3000 wifi board

Postby micke » 22:41, 08 Oct 2014

Hi again, asked a friend about the compatibility, and he said they are not compatible, as you say yourself.
Any progress on porting the code to CC3000?
Best regards, Mikael

ardiri
Posts: 58
Joined: 16:13, 28 May 2014

Re: Evothings on arduino cc3000 wifi board

Postby ardiri » 02:45, 09 Oct 2014

you will need to port the WiFi code to the Adafruit CC3000 library

https://github.com/adafruit/Adafruit_CC3000_Library

unfortunately; due to the nature of Arduino shields and their designs not all libraries are 100% compatible with each other. we have seen the same pattern with Bluetooth Low Energy implementations as well where the UUID of services and characteristics are different based on the manufacturer of the hardware.
// Aaron
Chief Technology Officer
Evothings AB http://www.evothings.com/


Return to “Questions and answers”

Who is online

Users browsing this forum: No registered users and 1 guest