mirror of
https://github.com/apache/nuttx-apps.git
synced 2025-07-05 19:30:07 +08:00
apps/examples/cc3000 update from David Sidrane. Plus some kruft removal
This commit is contained in:
parent
b914af7836
commit
53b56c781d
@ -693,4 +693,6 @@
|
|||||||
* apps/netutils/telnetd/telnetd_driver.c: Missing argument to
|
* apps/netutils/telnetd/telnetd_driver.c: Missing argument to
|
||||||
debug statement can cause crashes in certain error conditions.
|
debug statement can cause crashes in certain error conditions.
|
||||||
From David Sidrane (2013-10-24).
|
From David Sidrane (2013-10-24).
|
||||||
|
* apps/examples/cc3000: Updates from David Sidrane. Plus
|
||||||
|
some kruft removal (2013-10-24).
|
||||||
|
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
/**************************************************************************
|
/****************************************************************************
|
||||||
*
|
* apps/examples/cc3000/board.c
|
||||||
* ArduinoCC3000Core.cpp - Wrapper routines to make interfacing the Arduino
|
|
||||||
* and the TI CC3000 easier.
|
|
||||||
*
|
*
|
||||||
* This code is based on the TI sample code "Basic WiFi Application"
|
* This code is based on the TI sample code "Basic WiFi Application"
|
||||||
* and has the callback routines that TI expects for their library.
|
* and has the callback routines that TI expects for their library.
|
||||||
@ -11,7 +9,7 @@
|
|||||||
* a TI MSP430, a PIC, etc. but the core library shouldn't have to be
|
* a TI MSP430, a PIC, etc. but the core library shouldn't have to be
|
||||||
* changed.
|
* changed.
|
||||||
*
|
*
|
||||||
* Version 1.0.1b
|
* Derives from an application to demo an Arduino connected to the TI CC3000
|
||||||
*
|
*
|
||||||
* Copyright (C) 2013 Chris Magagna - cmagagna@yahoo.com
|
* Copyright (C) 2013 Chris Magagna - cmagagna@yahoo.com
|
||||||
*
|
*
|
||||||
@ -23,12 +21,28 @@
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
#include "board.h"
|
#include "board.h"
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <nuttx/wireless/cc3000/wlan.h>
|
#include <nuttx/wireless/cc3000/wlan.h>
|
||||||
#include <nuttx/wireless/cc3000/hci.h>
|
#include <nuttx/wireless/cc3000/hci.h>
|
||||||
#include <nuttx/wireless/cc3000.h>
|
#include <nuttx/wireless/cc3000.h>
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#define NETAPP_IPCONFIG_MAC_OFFSET (20)
|
||||||
|
#define CC3000_APP_BUFFER_SIZE (5)
|
||||||
|
#define CC3000_RX_BUFFER_OVERHEAD_SIZE (20)
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
volatile unsigned long ulSmartConfigFinished,
|
volatile unsigned long ulSmartConfigFinished,
|
||||||
ulCC3000Connected,
|
ulCC3000Connected,
|
||||||
ulCC3000DHCP,
|
ulCC3000DHCP,
|
||||||
@ -37,39 +51,21 @@ volatile unsigned long ulSmartConfigFinished,
|
|||||||
|
|
||||||
volatile uint8_t ucStopSmartConfig;
|
volatile uint8_t ucStopSmartConfig;
|
||||||
|
|
||||||
#define NETAPP_IPCONFIG_MAC_OFFSET (20)
|
|
||||||
#define CC3000_APP_BUFFER_SIZE (5)
|
|
||||||
#define CC3000_RX_BUFFER_OVERHEAD_SIZE (20)
|
|
||||||
|
|
||||||
/*
|
|
||||||
uint8_t pucCC3000_Rx_Buffer[CC3000_APP_BUFFER_SIZE + CC3000_RX_BUFFER_OVERHEAD_SIZE];
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* The original version of the function below had Serial.prints()
|
|
||||||
to display an event, but since an async event can happen at any time,
|
|
||||||
even in the middle of another Serial.print(), sometimes the sketch
|
|
||||||
would lock up because we were trying to print in the middle of
|
|
||||||
a print.
|
|
||||||
|
|
||||||
So now we just set a flag and write to a string, and the master
|
|
||||||
loop can deal with it when it wants.
|
|
||||||
*/
|
|
||||||
|
|
||||||
uint8_t asyncNotificationWaiting = false;
|
uint8_t asyncNotificationWaiting = false;
|
||||||
long lastAsyncEvent;
|
long lastAsyncEvent;
|
||||||
uint8_t dhcpIPAddress[4];
|
uint8_t dhcpIPAddress[4];
|
||||||
|
|
||||||
/*-------------------------------------------------------------------
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
The TI library calls this routine when asynchronous events happen.
|
****************************************************************************/
|
||||||
|
/* The TI library calls this routine when asynchronous events happen.
|
||||||
For example you tell the CC3000 to turn itself on and connect
|
*
|
||||||
to an access point then your code can go on to do its own thing.
|
* For example you tell the CC3000 to turn itself on and connect
|
||||||
When the CC3000 is done configuring itself (e.g. it gets an IP
|
* to an access point then your code can go on to do its own thing.
|
||||||
address from the DHCP server) it will call this routine so you
|
* When the CC3000 is done configuring itself (e.g. it gets an IP
|
||||||
can take appropriate action.
|
* address from the DHCP server) it will call this routine so you
|
||||||
|
* can take appropriate action.
|
||||||
---------------------------------------------------------------------*/
|
*/
|
||||||
|
|
||||||
void CC3000_AsyncCallback(long lEventType, char * data, uint8_t length)
|
void CC3000_AsyncCallback(long lEventType, char * data, uint8_t length)
|
||||||
{
|
{
|
||||||
@ -96,10 +92,11 @@ void CC3000_AsyncCallback(long lEventType, char * data, uint8_t length)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case HCI_EVNT_WLAN_UNSOL_DHCP:
|
case HCI_EVNT_WLAN_UNSOL_DHCP:
|
||||||
// Notes:
|
/* Notes:
|
||||||
// 1) IP config parameters are received swapped
|
* 1) IP config parameters are received swapped
|
||||||
// 2) IP config parameters are valid only if status is OK, i.e. ulCC3000DHCP becomes 1
|
* 2) IP config parameters are valid only if status is OK, i.e. ulCC3000DHCP becomes 1
|
||||||
// only if status is OK, the flag is set to 1 and the addresses are valid
|
* only if status is OK, the flag is set to 1 and the addresses are valid
|
||||||
|
*/
|
||||||
|
|
||||||
if (*(data + NETAPP_IPCONFIG_MAC_OFFSET) == 0)
|
if (*(data + NETAPP_IPCONFIG_MAC_OFFSET) == 0)
|
||||||
{
|
{
|
||||||
@ -131,14 +128,11 @@ void CC3000_AsyncCallback(long lEventType, char * data, uint8_t length)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------
|
/* The TI library calls these routines on CC3000 startup.
|
||||||
|
*
|
||||||
The TI library calls these routines on CC3000 startup.
|
* This library does not send firmware, driver, or bootloader patches
|
||||||
|
* so we do nothing and we return NULL.
|
||||||
This library does not send firmware, driver, or bootloader patches
|
*/
|
||||||
so we do nothing and we return NULL.
|
|
||||||
|
|
||||||
---------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
char *SendFirmwarePatch(unsigned long *Length)
|
char *SendFirmwarePatch(unsigned long *Length)
|
||||||
{
|
{
|
||||||
@ -158,19 +152,22 @@ char *SendBootloaderPatch(unsigned long *Length)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------
|
/* This is my routine to simplify CC3000 startup.
|
||||||
|
*
|
||||||
This is my routine to simplify CC3000 startup.
|
* It sets the Arduino pins then calls the normal CC3000 routines
|
||||||
|
* wlan_init() with all the callbacks and wlan_start() with 0
|
||||||
It sets the Arduino pins then calls the normal CC3000 routines
|
* to indicate we're not sending any patches.
|
||||||
wlan_init() with all the callbacks and wlan_start() with 0
|
*/
|
||||||
to indicate we're not sending any patches.
|
|
||||||
|
|
||||||
--------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
void CC3000_Init(void)
|
void CC3000_Init(void)
|
||||||
|
{
|
||||||
|
static bool once = false;
|
||||||
|
|
||||||
|
if (!once)
|
||||||
{
|
{
|
||||||
wireless_archinitialize();
|
wireless_archinitialize();
|
||||||
|
once = true;
|
||||||
|
}
|
||||||
|
|
||||||
CC3000_wlan_init( CC3000_AsyncCallback,
|
CC3000_wlan_init( CC3000_AsyncCallback,
|
||||||
SendFirmwarePatch,
|
SendFirmwarePatch,
|
||||||
|
@ -1,16 +1,13 @@
|
|||||||
/**************************************************************************
|
/***************************************************************************
|
||||||
|
* apps/examples/cc3000basic.c
|
||||||
*
|
*
|
||||||
* ArduinoCC3000.ino - An application to demo an Arduino connected to the
|
* Derives from an application to demo an Arduino connected to the TI CC3000
|
||||||
TI CC3000
|
|
||||||
*
|
|
||||||
* Version 1.0.1b
|
|
||||||
*
|
*
|
||||||
* Copyright (C) 2013 Chris Magagna - cmagagna@yahoo.com
|
* Copyright (C) 2013 Chris Magagna - cmagagna@yahoo.com
|
||||||
* Port to nuttx:
|
* Port to nuttx:
|
||||||
* Alan Carvalho de Assis <acassis@gmail.com>
|
* Alan Carvalho de Assis <acassis@gmail.com>
|
||||||
* David Sidrane <david_s5@nscdg.com>
|
* David Sidrane <david_s5@nscdg.com>
|
||||||
*
|
*
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
* are met:
|
* are met:
|
||||||
@ -18,71 +15,75 @@
|
|||||||
* Don't sue me if my code blows up your board and burns down your house
|
* Don't sue me if my code blows up your board and burns down your house
|
||||||
*
|
*
|
||||||
****************************************************************************
|
****************************************************************************
|
||||||
|
*
|
||||||
|
* To connect an Arduino to the CC3000 you'll need to make these 6 connections
|
||||||
|
* (in addition to the WiFi antenna, power etc).
|
||||||
|
*
|
||||||
|
* Name / pin on CC3000 module / pin on CC3000EM board / purpose
|
||||||
|
*
|
||||||
|
* SPI_CS / 12 / J4-8 / SPI Chip Select
|
||||||
|
* The Arduino will set this pin LOW when it wants to
|
||||||
|
* exchange data with the CC3000. By convention this is
|
||||||
|
* Arduino pin 10, but any pin can be used. In this
|
||||||
|
* program it will be called WLAN_CS
|
||||||
|
*
|
||||||
|
* SPI_DOUT / 13 / J4-9 / Data from the module to the Arduino
|
||||||
|
* This is Arduino's MISO pin, and is how the CC3000
|
||||||
|
* will get bytes to the Arduino. For most Arduinos
|
||||||
|
* MISO is pin 12
|
||||||
|
*
|
||||||
|
* SPI_IRQ / 14 / J4-10 / CC3000 host notify
|
||||||
|
* The CC3000 will drive this pin LOW to let the Arduino
|
||||||
|
* know it's ready to send data. For a regular Arduino
|
||||||
|
* (Uno, Nano, Leonardo) this will have to be connected
|
||||||
|
* to pin 2 or 3 so you can use attachInterrupt(). In
|
||||||
|
* this program it will be called WLAN_IRQ
|
||||||
|
*
|
||||||
|
* SPI_DIN / 15 / J4-11 Data from the Arduino to the CC3000
|
||||||
|
* This is the Arduino's MOSI pin, and is how the Arduino
|
||||||
|
* will get bytes to the CC3000. For most Arduinos
|
||||||
|
* MOSI is pin 11
|
||||||
|
*
|
||||||
|
* SPI_CLK / 17 / J4-12 SPI clock
|
||||||
|
* This is the Arduino's SCK pin. For most Arduinos
|
||||||
|
* SCK is pin 13
|
||||||
|
*
|
||||||
|
* VBAT_SW_EN / 26 / J5-5 Module enable
|
||||||
|
* The Arduino will set this pin HIGH to turn the CC3000
|
||||||
|
* on. Any pin can be used. In this program it will be
|
||||||
|
* called WLAN_EN
|
||||||
|
*
|
||||||
|
* WARNING #1: The CC3000 runs at 3.6V maximum so you can't run it from your
|
||||||
|
* regular 5V Arduino power pin. Run it from 3.3V!
|
||||||
|
*
|
||||||
|
* WARNING #2: When transmitting the CC3000 will use up to 275mA current. Most
|
||||||
|
* Arduinos' 3.3V pins can only supply up to 50mA current, so you'll need a
|
||||||
|
* separate power supply for it (or a voltage regulator like the LD1117V33
|
||||||
|
* connected to your Arduino's 5V power pin).
|
||||||
|
*
|
||||||
|
* WARNING #3: The CC3000's IO pins are not 5V tolerant. If you're using a 5V
|
||||||
|
* Arduino you will need a level shifter to convert these signals to 3.3V
|
||||||
|
* so you don't blow up the module.
|
||||||
|
*
|
||||||
|
* You'll need to shift the pins for WLAN_CS, MOSI, SCK, and WLAN_EN. MISO can be
|
||||||
|
* connected directly because it's an input pin for the Arduino and the Arduino
|
||||||
|
* can read 3.3V signals directly. For WLAN_IRQ use a pullup resistor of 20K to
|
||||||
|
* 100K Ohm -- one leg to the Arduino input pin + CC3000 SPI_IRQ pin, the other
|
||||||
|
* leg to +3.3V.
|
||||||
|
*
|
||||||
|
* You can use a level shifter chip like the 74LVC245 or TXB0104 or you can use
|
||||||
|
* a pair of resistors to make a voltage divider like this:
|
||||||
|
*
|
||||||
|
* Arduino pin -----> 560 Ohm --+--> 1K Ohm -----> GND
|
||||||
|
* |
|
||||||
|
* |
|
||||||
|
* +---> CC3000 pin
|
||||||
|
*
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
To connect an Arduino to the CC3000 you'll need to make these 6 connections
|
/****************************************************************************
|
||||||
(in addition to the WiFi antenna, power etc).
|
* Included Files
|
||||||
|
|
||||||
Name / pin on CC3000 module / pin on CC3000EM board / purpose
|
|
||||||
|
|
||||||
SPI_CS / 12 / J4-8 / SPI Chip Select
|
|
||||||
The Arduino will set this pin LOW when it wants to
|
|
||||||
exchange data with the CC3000. By convention this is
|
|
||||||
Arduino pin 10, but any pin can be used. In this
|
|
||||||
program it will be called WLAN_CS
|
|
||||||
|
|
||||||
SPI_DOUT / 13 / J4-9 / Data from the module to the Arduino
|
|
||||||
This is Arduino's MISO pin, and is how the CC3000
|
|
||||||
will get bytes to the Arduino. For most Arduinos
|
|
||||||
MISO is pin 12
|
|
||||||
|
|
||||||
SPI_IRQ / 14 / J4-10 / CC3000 host notify
|
|
||||||
The CC3000 will drive this pin LOW to let the Arduino
|
|
||||||
know it's ready to send data. For a regular Arduino
|
|
||||||
(Uno, Nano, Leonardo) this will have to be connected
|
|
||||||
to pin 2 or 3 so you can use attachInterrupt(). In
|
|
||||||
this program it will be called WLAN_IRQ
|
|
||||||
|
|
||||||
SPI_DIN / 15 / J4-11 Data from the Arduino to the CC3000
|
|
||||||
This is the Arduino's MOSI pin, and is how the Arduino
|
|
||||||
will get bytes to the CC3000. For most Arduinos
|
|
||||||
MOSI is pin 11
|
|
||||||
|
|
||||||
SPI_CLK / 17 / J4-12 SPI clock
|
|
||||||
This is the Arduino's SCK pin. For most Arduinos
|
|
||||||
SCK is pin 13
|
|
||||||
|
|
||||||
VBAT_SW_EN / 26 / J5-5 Module enable
|
|
||||||
The Arduino will set this pin HIGH to turn the CC3000
|
|
||||||
on. Any pin can be used. In this program it will be
|
|
||||||
called WLAN_EN
|
|
||||||
|
|
||||||
WARNING #1: The CC3000 runs at 3.6V maximum so you can't run it from your
|
|
||||||
regular 5V Arduino power pin. Run it from 3.3V!
|
|
||||||
|
|
||||||
WARNING #2: When transmitting the CC3000 will use up to 275mA current. Most
|
|
||||||
Arduinos' 3.3V pins can only supply up to 50mA current, so you'll need a
|
|
||||||
separate power supply for it (or a voltage regulator like the LD1117V33
|
|
||||||
connected to your Arduino's 5V power pin).
|
|
||||||
|
|
||||||
WARNING #3: The CC3000's IO pins are not 5V tolerant. If you're using a 5V
|
|
||||||
Arduino you will need a level shifter to convert these signals to 3.3V
|
|
||||||
so you don't blow up the module.
|
|
||||||
|
|
||||||
You'll need to shift the pins for WLAN_CS, MOSI, SCK, and WLAN_EN. MISO can be
|
|
||||||
connected directly because it's an input pin for the Arduino and the Arduino
|
|
||||||
can read 3.3V signals directly. For WLAN_IRQ use a pullup resistor of 20K to
|
|
||||||
100K Ohm -- one leg to the Arduino input pin + CC3000 SPI_IRQ pin, the other
|
|
||||||
leg to +3.3V.
|
|
||||||
|
|
||||||
You can use a level shifter chip like the 74LVC245 or TXB0104 or you can use
|
|
||||||
a pair of resistors to make a voltage divider like this:
|
|
||||||
|
|
||||||
Arduino pin -----> 560 Ohm --+--> 1K Ohm -----> GND
|
|
||||||
|
|
|
||||||
|
|
|
||||||
+---> CC3000 pin
|
|
||||||
|
|
||||||
|
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
@ -102,12 +103,14 @@ Arduino pin -----> 560 Ohm --+--> 1K Ohm -----> GND
|
|||||||
#include <nuttx/wireless/cc3000/netapp.h>
|
#include <nuttx/wireless/cc3000/netapp.h>
|
||||||
#include "shell.h"
|
#include "shell.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Function Prototypes
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
void Initialize(void);
|
void Initialize(void);
|
||||||
void helpme(void);
|
void helpme(void);
|
||||||
int execute(int cmd);
|
int execute(int cmd);
|
||||||
void ShowBufferSize(void);
|
void ShowBufferSize(void);
|
||||||
void ShowFreeRAM(void);
|
|
||||||
void Blinker(void);
|
|
||||||
void StartSmartConfig(void);
|
void StartSmartConfig(void);
|
||||||
void ManualConnect(void);
|
void ManualConnect(void);
|
||||||
void ManualAddProfile(void);
|
void ManualAddProfile(void);
|
||||||
@ -115,16 +118,24 @@ void ListAccessPoints(void);
|
|||||||
void PrintIPBytes(uint8_t *ipBytes);
|
void PrintIPBytes(uint8_t *ipBytes);
|
||||||
void ShowInformation(void);
|
void ShowInformation(void);
|
||||||
|
|
||||||
// When operations that take a long time (like Smart Config) are running, the
|
/****************************************************************************
|
||||||
// function Blinker() flashes this LED. It's not required for actual use.
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
#define BLINKER_LED 6
|
|
||||||
#define MS_PER_SEC 1000
|
#define MS_PER_SEC 1000
|
||||||
#define US_PER_MS 1000
|
#define US_PER_MS 1000
|
||||||
#define US_PER_SEC 1000000
|
#define US_PER_SEC 1000000
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Variables
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
uint8_t isInitialized = false;
|
uint8_t isInitialized = false;
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
bool wait(long timeoutMs, volatile unsigned long *what, volatile unsigned long is)
|
bool wait(long timeoutMs, volatile unsigned long *what, volatile unsigned long is)
|
||||||
{
|
{
|
||||||
long t_ms;
|
long t_ms;
|
||||||
@ -134,7 +145,6 @@ bool wait(long timeoutMs, volatile unsigned long *what, volatile unsigned long i
|
|||||||
|
|
||||||
while (*what != is)
|
while (*what != is)
|
||||||
{
|
{
|
||||||
Blinker();
|
|
||||||
usleep(10*US_PER_MS);
|
usleep(10*US_PER_MS);
|
||||||
gettimeofday(&end, NULL);
|
gettimeofday(&end, NULL);
|
||||||
t_ms = ((end.tv_sec - start.tv_sec) * MS_PER_SEC) + ((end.tv_usec - start.tv_usec) / US_PER_MS) ;
|
t_ms = ((end.tv_sec - start.tv_sec) * MS_PER_SEC) + ((end.tv_usec - start.tv_usec) / US_PER_MS) ;
|
||||||
@ -198,8 +208,10 @@ void AsyncEventPrint(void)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case HCI_EVNT_WLAN_KEEPALIVE:
|
case HCI_EVNT_WLAN_KEEPALIVE:
|
||||||
// Once initialized, the CC3000 will send these keepalive events
|
/* Once initialized, the CC3000 will send these keepalive events
|
||||||
// every 20 seconds.
|
* every 20 seconds.
|
||||||
|
*/
|
||||||
|
|
||||||
printf("CC3000 Async event: Keepalive\n");
|
printf("CC3000 Async event: Keepalive\n");
|
||||||
return;
|
return;
|
||||||
break;
|
break;
|
||||||
@ -241,32 +253,44 @@ int execute(int cmd)
|
|||||||
case '1':
|
case '1':
|
||||||
Initialize();
|
Initialize();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '2':
|
case '2':
|
||||||
ShowBufferSize();
|
ShowBufferSize();
|
||||||
ShowFreeRAM();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '3':
|
case '3':
|
||||||
StartSmartConfig();
|
StartSmartConfig();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '4':
|
case '4':
|
||||||
ManualConnect();
|
ManualConnect();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '5':
|
case '5':
|
||||||
ManualAddProfile();
|
ManualAddProfile();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '6':
|
case '6':
|
||||||
ListAccessPoints();
|
ListAccessPoints();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '7':
|
case '7':
|
||||||
ShowInformation();
|
ShowInformation();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '8':
|
case '8':
|
||||||
|
if (!isInitialized)
|
||||||
|
{
|
||||||
|
Initialize();
|
||||||
|
}
|
||||||
shell_main(0, 0);
|
shell_main(0, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'q':
|
case 'q':
|
||||||
case 'Q':
|
case 'Q':
|
||||||
ret = 1;
|
ret = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
printf("**Unknown command \"%d\" **\n", cmd);
|
printf("**Unknown command \"%d\" **\n", cmd);
|
||||||
break;
|
break;
|
||||||
@ -283,7 +307,7 @@ void Initialize(void)
|
|||||||
{
|
{
|
||||||
printf("CC3000 already initialized. Shutting down and restarting...\n");
|
printf("CC3000 already initialized. Shutting down and restarting...\n");
|
||||||
wlan_stop();
|
wlan_stop();
|
||||||
usleep(1000000); //delay 1s
|
usleep(1000000); /* Delay 1s */
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Initializing CC3000...\n");
|
printf("Initializing CC3000...\n");
|
||||||
@ -328,7 +352,6 @@ void Initialize(void)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* This just shows the compiled size of the transmit & recieve buffers */
|
/* This just shows the compiled size of the transmit & recieve buffers */
|
||||||
|
|
||||||
void ShowBufferSize(void)
|
void ShowBufferSize(void)
|
||||||
@ -337,40 +360,31 @@ void ShowBufferSize(void)
|
|||||||
printf("Receive buffer is %d bytes", CC3000_RX_BUFFER_SIZE);
|
printf("Receive buffer is %d bytes", CC3000_RX_BUFFER_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Smart Config is TI's way to let you connect your device to your WiFi network
|
||||||
void ShowFreeRAM(void)
|
* without needing a keyboard and display to enter the network name, password,
|
||||||
{
|
* etc. You run a little app on your iPhone, Android device, or laptop with Java
|
||||||
printf("Free RAM is XXXX bytes... I don't care\n");
|
* and it sends the config info to the CC3000 automagically, so the end user
|
||||||
}
|
* doesn't need to do anything complicated. More details here:
|
||||||
|
*
|
||||||
void Blinker(void)
|
* http://processors.wiki.ti.com/index.php/CC3000_Smart_Config
|
||||||
{
|
*
|
||||||
}
|
* This example deletes any currently saved WiFi profiles and goes over the top
|
||||||
|
* with error checking, so it's easier to see exactly what's going on. You
|
||||||
/*
|
* probably won't need all of this code for your own Smart Config implementation.
|
||||||
Smart Config is TI's way to let you connect your device to your WiFi network
|
*
|
||||||
without needing a keyboard and display to enter the network name, password,
|
* This example also doesn't use any of the AES enhanced security setup API calls
|
||||||
etc. You run a little app on your iPhone, Android device, or laptop with Java
|
* because frankly they're weirder than I want to deal with.
|
||||||
and it sends the config info to the CC3000 automagically, so the end user
|
|
||||||
doesn't need to do anything complicated. More details here:
|
|
||||||
|
|
||||||
http://processors.wiki.ti.com/index.php/CC3000_Smart_Config
|
|
||||||
|
|
||||||
This example deletes any currently saved WiFi profiles and goes over the top
|
|
||||||
with error checking, so it's easier to see exactly what's going on. You
|
|
||||||
probably won't need all of this code for your own Smart Config implementation.
|
|
||||||
|
|
||||||
This example also doesn't use any of the AES enhanced security setup API calls
|
|
||||||
because frankly they're weirder than I want to deal with.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* The Simple Config Prefix always needs to be 'TTT' */
|
||||||
|
|
||||||
// The Simple Config Prefix always needs to be 'TTT'
|
|
||||||
char simpleConfigPrefix[] = {'T', 'T', 'T'};
|
char simpleConfigPrefix[] = {'T', 'T', 'T'};
|
||||||
|
|
||||||
// This is the default Device Name that TI's Smart Config app for iPhone etc. use.
|
/* This is the default Device Name that TI's Smart Config app for iPhone etc. use.
|
||||||
// You can change it to whatever you want, but then your users will need to type
|
* You can change it to whatever you want, but then your users will need to type
|
||||||
// that name into their phone or tablet when they run Smart Config.
|
* that name into their phone or tablet when they run Smart Config.
|
||||||
|
*/
|
||||||
|
|
||||||
char device_name[] = "CC3000";
|
char device_name[] = "CC3000";
|
||||||
|
|
||||||
void StartSmartConfig(void)
|
void StartSmartConfig(void)
|
||||||
@ -444,13 +458,13 @@ void StartSmartConfig(void)
|
|||||||
printf(" Succeed\n");
|
printf(" Succeed\n");
|
||||||
printf(" Stopping CC3000...\n");
|
printf(" Stopping CC3000...\n");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
wlan_stop(); // no error returned here, so nothing to check
|
wlan_stop(); /* No error returned here, so nothing to check */
|
||||||
|
|
||||||
printf(" Pausing for 2 seconds...\n");
|
printf(" Pausing for 2 seconds...\n");
|
||||||
usleep(2000000);
|
usleep(2000000);
|
||||||
|
|
||||||
printf(" Restarting CC3000... \n");
|
printf(" Restarting CC3000... \n");
|
||||||
wlan_start(0); // no error returned here, so nothing to check
|
wlan_start(0); /* No error returned here, so nothing to check */
|
||||||
|
|
||||||
if (!wait_on(20*MS_PER_SEC, &ulCC3000Connected, 1, " Waiting for connection to AP"))
|
if (!wait_on(20*MS_PER_SEC, &ulCC3000Connected, 1, " Waiting for connection to AP"))
|
||||||
{
|
{
|
||||||
@ -466,21 +480,24 @@ void StartSmartConfig(void)
|
|||||||
|
|
||||||
printf(" Sending mDNS broadcast to signal we're done with Smart Config...\n");
|
printf(" Sending mDNS broadcast to signal we're done with Smart Config...\n");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
mdnsAdvertiser(1,device_name,strlen(device_name)); // The API documentation says mdnsAdvertiser()
|
|
||||||
// is supposed to return 0 on success and SOC_ERROR on failure, but it looks like
|
/* The API documentation says mdnsAdvertiser() is supposed to return 0 on
|
||||||
// what it actually returns is the socket number it used. So we ignore it.
|
* success and SOC_ERROR on failure, but it looks like what it actually
|
||||||
|
* returns is the socket number it used. So we ignore it.
|
||||||
|
*/
|
||||||
|
|
||||||
|
mdnsAdvertiser(1,device_name,strlen(device_name));
|
||||||
|
|
||||||
printf(" Smart Config finished Successfully!\n");
|
printf(" Smart Config finished Successfully!\n");
|
||||||
ShowInformation();
|
ShowInformation();
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* This is an example of how you'd connect the CC3000 to an AP without using
|
||||||
This is an example of how you'd connect the CC3000 to an AP without using
|
* Smart Config or a stored profile.
|
||||||
Smart Config or a stored profile.
|
*
|
||||||
|
* All the code above wlan_connect() is just for this demo program; if you're
|
||||||
All the code above wlan_connect() is just for this demo program; if you're
|
* always going to connect to your network this way you wouldn't need it.
|
||||||
always going to connect to your network this way you wouldn't need it.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void ManualConnect(void)
|
void ManualConnect(void)
|
||||||
@ -507,11 +524,12 @@ void ManualConnect(void)
|
|||||||
|
|
||||||
printf(" Manually connecting...\n");
|
printf(" Manually connecting...\n");
|
||||||
|
|
||||||
// Parameter 1 is the security type: WLAN_SEC_UNSEC, WLAN_SEC_WEP,
|
/* Parameter 1 is the security type: WLAN_SEC_UNSEC, WLAN_SEC_WEP,
|
||||||
// WLAN_SEC_WPA or WLAN_SEC_WPA2
|
* WLAN_SEC_WPA or WLAN_SEC_WPA2
|
||||||
// Parameter 3 is the MAC adddress of the AP. All the TI examples
|
* Parameter 3 is the MAC adddress of the AP. All the TI examples
|
||||||
// use NULL. I suppose you would want to specify this
|
* use NULL. I suppose you would want to specify this
|
||||||
// if you were security paranoid.
|
* if you were security paranoid.
|
||||||
|
*/
|
||||||
|
|
||||||
rval = wlan_connect(WLAN_SEC_WPA2,
|
rval = wlan_connect(WLAN_SEC_WPA2,
|
||||||
ssidName,
|
ssidName,
|
||||||
@ -530,22 +548,21 @@ void ManualConnect(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* This is an example of manually adding a WLAN profile to the CC3000. See
|
||||||
This is an example of manually adding a WLAN profile to the CC3000. See
|
* wlan_ioctl_set_connection_policy() for more details of how profiles are
|
||||||
wlan_ioctl_set_connection_policy() for more details of how profiles are
|
* used but basically there's 7 slots where you can store AP info and if
|
||||||
used but basically there's 7 slots where you can store AP info and if
|
* the connection policy is set to auto_start then the CC3000 will go
|
||||||
the connection policy is set to auto_start then the CC3000 will go
|
* through its profile table and try to auto-connect to something it knows
|
||||||
through its profile table and try to auto-connect to something it knows
|
* about after it boots up.
|
||||||
about after it boots up.
|
*
|
||||||
|
* Note the API documentation for wlan_add_profile is wrong. It says it
|
||||||
Note the API documentation for wlan_add_profile is wrong. It says it
|
* returns 0 on success and -1 on failure. What it really returns is
|
||||||
returns 0 on success and -1 on failure. What it really returns is
|
* the stored profile number (0-6, since the CC3000 can store 7) or
|
||||||
the stored profile number (0-6, since the CC3000 can store 7) or
|
* 255 on failure.
|
||||||
255 on failure.
|
*
|
||||||
|
* Unfortunately the API doesn't give you any way to see how many profiles
|
||||||
Unfortunately the API doesn't give you any way to see how many profiles
|
* are in use or which profile is stored in which slot, so if you want to
|
||||||
are in use or which profile is stored in which slot, so if you want to
|
* manage multiple profiles you'll need to do that yourself.
|
||||||
manage multiple profiles you'll need to do that yourself.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void ManualAddProfile(void)
|
void ManualAddProfile(void)
|
||||||
@ -567,22 +584,23 @@ void ManualAddProfile(void)
|
|||||||
|
|
||||||
printf(" Adding profile...\n");
|
printf(" Adding profile...\n");
|
||||||
rval = wlan_add_profile (
|
rval = wlan_add_profile (
|
||||||
WLAN_SEC_WPA2, // WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2
|
WLAN_SEC_WPA2, /* WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2 */
|
||||||
(uint8_t *)ssidName,
|
(uint8_t *)ssidName,
|
||||||
strlen(ssidName),
|
strlen(ssidName),
|
||||||
NULL, // BSSID, TI always uses NULL
|
NULL, /* BSSID, TI always uses NULL */
|
||||||
0, // profile priority
|
0, /* Profile priority */
|
||||||
0x18, // key length for WEP security, undocumented why this needs to be 0x18
|
0x18, /* Key length for WEP security, undocumented why this needs to be 0x18 */
|
||||||
0x1e, // key index, undocumented why this needs to be 0x1e
|
0x1e, /* Key index, undocumented why this needs to be 0x1e */
|
||||||
0x2, // key management, undocumented why this needs to be 2
|
0x2, /* key management, undocumented why this needs to be 2 */
|
||||||
(uint8_t *)AP_KEY, // WPA security key
|
(uint8_t *)AP_KEY, /* WPA security key */
|
||||||
strlen(AP_KEY) // WPA security key length
|
strlen(AP_KEY) /* WPA security key length */
|
||||||
);
|
);
|
||||||
|
|
||||||
if (rval!=255)
|
if (rval!=255)
|
||||||
{
|
{
|
||||||
// This code is lifted from http://e2e.ti.com/support/low_power_rf/f/851/p/180859/672551.aspx;
|
/* This code is lifted from http://e2e.ti.com/support/low_power_rf/f/851/p/180859/672551.aspx;
|
||||||
// the actual API documentation on wlan_add_profile doesn't specify any of this....
|
* the actual API documentation on wlan_add_profile doesn't specify any of this....
|
||||||
|
*/
|
||||||
|
|
||||||
printf(" Manual add profile success, stored in profile: %d\n", rval);
|
printf(" Manual add profile success, stored in profile: %d\n", rval);
|
||||||
|
|
||||||
@ -606,45 +624,44 @@ void ManualAddProfile(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* The call wlan_ioctl_get_scan_results returns this structure. I couldn't
|
||||||
The call wlan_ioctl_get_scan_results returns this structure. I couldn't
|
* find it in the TI library so it's defined here. It's 50 bytes with
|
||||||
find it in the TI library so it's defined here. It's 50 bytes with
|
* a semi weird arrangement but fortunately it's not as bad as it looks.
|
||||||
a semi weird arrangement but fortunately it's not as bad as it looks.
|
*
|
||||||
|
* numNetworksFound - 4 bytes - On the first call to wlan_ioctl_get_scan_results
|
||||||
numNetworksFound - 4 bytes - On the first call to wlan_ioctl_get_scan_results
|
* this will be set to how many APs the CC3000 sees. Although
|
||||||
this will be set to how many APs the CC3000 sees. Although
|
* with 4 bytes the CC3000 could see 4 billion APs in my testing
|
||||||
with 4 bytes the CC3000 could see 4 billion APs in my testing
|
* this number was always 20 or less so there's probably an
|
||||||
this number was always 20 or less so there's probably an
|
* internal memory limit.
|
||||||
internal memory limit.
|
*
|
||||||
|
* results - 4 bytes - 0=aged results, 1=results valid, 2=no results. Why TI
|
||||||
results - 4 bytes - 0=aged results, 1=results valid, 2=no results. Why TI
|
* used 32 bits to store something that could be done in 2,
|
||||||
used 32 bits to store something that could be done in 2,
|
* and how this field is different than isValid below, is
|
||||||
and how this field is different than isValid below, is
|
* a mystery to me so I just igore this field completely.
|
||||||
a mystery to me so I just igore this field completely.
|
*
|
||||||
|
* isValid & rssi - 1 byte - a packed structure. The top bit (isValid)
|
||||||
isValid & rssi - 1 byte - a packed structure. The top bit (isValid)
|
* indicates whether or not this structure has valid data,
|
||||||
indicates whether or not this structure has valid data,
|
* the bottom 7 bits (rssi) are the signal strength of this AP.
|
||||||
the bottom 7 bits (rssi) are the signal strength of this AP.
|
*
|
||||||
|
* securityMode & ssidLength - 1 byte - another packed structure. The top 2
|
||||||
securityMode & ssidLength - 1 byte - another packed structure. The top 2
|
* bits (securityMode) show how the AP is configured:
|
||||||
bits (securityMode) show how the AP is configured:
|
* 0 - open / no security
|
||||||
0 - open / no security
|
* 1 - WEP
|
||||||
1 - WEP
|
* 2 - WPA
|
||||||
2 - WPA
|
* 3 - WPA2
|
||||||
3 - WPA2
|
* ssidLength is the lower 6 bytes and shows how many characters
|
||||||
ssidLength is the lower 6 bytes and shows how many characters
|
* (up to 32) of the ssid_name field are valid
|
||||||
(up to 32) of the ssid_name field are valid
|
*
|
||||||
|
* frameTime - 2 bytes - how long, in seconds, since the CC3000 saw this AP
|
||||||
frameTime - 2 bytes - how long, in seconds, since the CC3000 saw this AP
|
* beacon
|
||||||
beacon
|
*
|
||||||
|
* ssid_name - 32 bytes - The ssid name for this AP. Note that this isn't a
|
||||||
ssid_name - 32 bytes - The ssid name for this AP. Note that this isn't a
|
* regular null-terminated C string so you can't use it
|
||||||
regular null-terminated C string so you can't use it
|
* directly with a strcpy() or Serial.println() etc. and you'll
|
||||||
directly with a strcpy() or Serial.println() etc. and you'll
|
* need a 33-byte string to store it (32 valid characters +
|
||||||
need a 33-byte string to store it (32 valid characters +
|
* null terminator)
|
||||||
null terminator)
|
*
|
||||||
|
* bssid - 6 bytes - the MAC address of this AP
|
||||||
bssid - 6 bytes - the MAC address of this AP
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
typedef struct scanResults
|
typedef struct scanResults
|
||||||
@ -686,15 +703,15 @@ void ListAccessPoints(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
rval = wlan_ioctl_set_scan_params(
|
rval = wlan_ioctl_set_scan_params(
|
||||||
1000, // enable start application scan
|
1000, /* Enable start application scan */
|
||||||
100, // minimum dwell time on each channel
|
100, /* Minimum dwell time on each channel */
|
||||||
100, // maximum dwell time on each channel
|
100, /* Maximum dwell time on each channel */
|
||||||
5, // number of probe requests
|
5, /* Number of probe requests */
|
||||||
0x7ff, // channel mask
|
0x7ff, /* Channel mask */
|
||||||
-80, // RSSI threshold
|
-80, /* RSSI threshold */
|
||||||
0, // SNR threshold
|
0, /* SNR threshold */
|
||||||
205, // probe TX power
|
205, /* Probe TX power */
|
||||||
aiIntervalList // table of scan intervals per channel
|
aiIntervalList /* Table of scan intervals per channel */
|
||||||
);
|
);
|
||||||
|
|
||||||
if (rval!=0)
|
if (rval!=0)
|
||||||
@ -703,14 +720,17 @@ void ListAccessPoints(void)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//printf(" Sleeping 5 seconds to let the CC3000 discover APs...\n");
|
#if 0
|
||||||
//usleep(5000000);
|
printf(" Sleeping 5 seconds to let the CC3000 discover APs...\n");
|
||||||
|
usleep(5000000);
|
||||||
|
#endif
|
||||||
|
|
||||||
printf(" Getting AP count...\n");
|
printf(" Getting AP count...\n");
|
||||||
|
|
||||||
// On the first call to get_scan_results, sr.numNetworksFound will return the
|
/* On the first call to get_scan_results, sr.numNetworksFound will return the
|
||||||
// actual # of APs currently seen. Get that # then loop through and print
|
* actual # of APs currently seen. Get that # then loop through and print
|
||||||
// out what's found.
|
* out what's found.
|
||||||
|
*/
|
||||||
|
|
||||||
if ((rval=wlan_ioctl_get_scan_results(2000, (uint8_t *)&sr))!=0)
|
if ((rval=wlan_ioctl_get_scan_results(2000, (uint8_t *)&sr))!=0)
|
||||||
{
|
{
|
||||||
@ -728,16 +748,16 @@ void ListAccessPoints(void)
|
|||||||
printf(" ");
|
printf(" ");
|
||||||
switch(sr.securityMode)
|
switch(sr.securityMode)
|
||||||
{
|
{
|
||||||
case WLAN_SEC_UNSEC: // 0
|
case WLAN_SEC_UNSEC: /* 0 */
|
||||||
printf("OPEN ");
|
printf("OPEN ");
|
||||||
break;
|
break;
|
||||||
case WLAN_SEC_WEP: // 1
|
case WLAN_SEC_WEP: /* 1 */
|
||||||
printf("WEP ");
|
printf("WEP ");
|
||||||
break;
|
break;
|
||||||
case WLAN_SEC_WPA: // 2
|
case WLAN_SEC_WPA: /* 2 */
|
||||||
printf("WPA ");
|
printf("WPA ");
|
||||||
break;
|
break;
|
||||||
case WLAN_SEC_WPA2: // 3
|
case WLAN_SEC_WPA2: /* 3 */
|
||||||
printf("WPA2 ");
|
printf("WPA2 ");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -768,14 +788,13 @@ void PrintIPBytes(uint8_t *ipBytes)
|
|||||||
printf("%d.%d.%d.%d\n", ipBytes[3], ipBytes[2], ipBytes[1], ipBytes[0]);
|
printf("%d.%d.%d.%d\n", ipBytes[3], ipBytes[2], ipBytes[1], ipBytes[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* All the data in all the fields from netapp_ipconfig() are reversed,
|
||||||
All the data in all the fields from netapp_ipconfig() are reversed,
|
* e.g. an IP address is read via bytes 3,2,1,0 instead of bytes
|
||||||
e.g. an IP address is read via bytes 3,2,1,0 instead of bytes
|
* 0,1,2,3 and the MAC address is read via bytes 5,4,3,2,1,0 instead
|
||||||
0,1,2,3 and the MAC address is read via bytes 5,4,3,2,1,0 instead
|
* of 0,1,2,3,4,5.
|
||||||
of 0,1,2,3,4,5.
|
*
|
||||||
|
* N.B. TI is inconsistent here; nvmem_get_mac_address() returns them in
|
||||||
N.B. TI is inconsistent here; nvmem_get_mac_address() returns them in
|
* the right order etc.
|
||||||
the right order etc.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void ShowInformation(void)
|
void ShowInformation(void)
|
||||||
|
@ -67,7 +67,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef CONFIG_EXAMPLES_TELNETD_CLIENTSTACKSIZE
|
#ifndef CONFIG_EXAMPLES_TELNETD_CLIENTSTACKSIZE
|
||||||
# define CONFIG_EXAMPLES_TELNETD_CLIENTSTACKSIZE 786
|
# define CONFIG_EXAMPLES_TELNETD_CLIENTSTACKSIZE 990
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Other definitions ********************************************************/
|
/* Other definitions ********************************************************/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user