So I have a basic circuit for a PIR and an LED set up properly. I decided to get ambitious and add functionality to email out when something is detected. However I am having connectivity issues.
I am upgraded to the latest firmware for the CC3000 and am using the 1.0.6 IDE. The code gets me connected to the network and says it assigns a static IP, but in the router config I only see the device connected but no IP is shown. In case it is relevant the router is a Netgear Nighthawk ac router.
Attached is a screenshot showing the issue. Apparently I can't attach code....
Code: Select all
#include <SPI.h>
#include <Adafruit_CC3000.h>
#include <Adafruit_CC3000_Server.h>
#include <ccspi.h>
#include <Client.h>
#include <Temboo.h>
#define ADAFRUIT_CC3000_IRQ 3
#define ADAFRUIT_CC3000_VBAT 5
#define ADAFRUIT_CC3000_CS 10
#define WIFI_SSID "getpwnd-lua" // cannot be longer than 32 characters!
#define WPA_PASSWORD "password"
#define TEMBOO_ACCOUNT "thaweatherman" // Your Temboo account name
#define TEMBOO_APP_KEY_NAME "myFirstApp" // Your Temboo app key name
#define TEMBOO_APP_KEY "key" // Your Temboo app key
int led_pin = 8;
int pir_input = 2;
int pir_state = LOW;
int val = 0;
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT);
Adafruit_CC3000_Client client;
void setup() {
pinMode(led_pin, OUTPUT);
pinMode(pir_input, INPUT);
Serial.begin(115200);
init_network();
}
void loop() {
val = digitalRead(pir_input);
if (val == HIGH) {
digitalWrite(led_pin, HIGH);
delay(150);
if (pir_state == LOW) {
Serial.println("Motion detected");
pir_state = HIGH;
send_email();
}
}
else {
digitalWrite(led_pin, LOW);
delay(300);
if (pir_state == HIGH) {
Serial.println("Motion ended");
pir_state = LOW;
}
}
}
void send_email() {
if (!cc3000.checkConnected()) {
Serial.println(F("Not connected. Restarting connection."));
if (!init_network()) {
Serial.println(F("Connection restart failed"));
delay(15*1000);
return;
}
}
Serial.println("Running SendEmail");
TembooChoreo SendEmailChoreo(client);
// Invoke the Temboo client
SendEmailChoreo.begin();
// Set Temboo account credentials
SendEmailChoreo.setAccountName(TEMBOO_ACCOUNT);
SendEmailChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
SendEmailChoreo.setAppKey(TEMBOO_APP_KEY);
Serial.println("Set Choreo details");
// Set profile to use for execution
SendEmailChoreo.setProfile("Sendemail");
// Identify the Choreo to run
SendEmailChoreo.setChoreo("/Library/Google/Gmail/SendEmail");
// Run the Choreo; when results are available, print them to serial
BANNED();
Serial.println("Choreo finished running\n");
while(SendEmailChoreo.available()) {
char c = SendEmailChoreo.read();
Serial.print(c);
}
SendEmailChoreo.close();
}
int8_t init_network(void)
{
Serial.println("Restarting connection");
cc3000.reboot();
// Set up the CC3000, connect to the access point, and get an IP address.
if (!cc3000.begin()) {
// the following never gets executed. If .begin() fails, it just hangs
while(1);
}
if (!cc3000.connectToAP(WIFI_SSID, WPA_PASSWORD, WLAN_SEC_WPA2)) {
Serial.println(F("Failed to connect to AP!"));
return 0;
}
Serial.println(F("Connected to Wireless Network!"));
/* Serial.println(F("Request DHCP..."));
while (!cc3000.checkDHCP()) {
delay(100);
}*/
uint32_t ip_addr = cc3000.IP2U32(192, 168, 1, 71);
uint32_t mask = cc3000.IP2U32(255, 255, 255, 0);
uint32_t gateway = cc3000.IP2U32(192, 168, 1, 1);
uint32_t dns = cc3000.IP2U32(8, 8, 8, 8);
if (!cc3000.setStaticIPAddress(ip_addr, mask, gateway, dns)) {
Serial.println(F("Failed to set static ip"));
while(1);
}
Serial.println(F("Got IP"));
return -1;
}
The following is the output of buildtest.
Hello, CC3000!
RX Buffer : 131 bytes
TX Buffer : 131 bytes
Free RAM: 1199
Initialising the CC3000 ...
Firmware V. : 1.32
MAC Address : 0x08 0x00 0x28 0x57 0x99 0x97
Networks found: 0
================================================
================================================
Deleting old connection profiles
Attempting to connect to getpwnd-lua
Connected!
Request DHCP
IP Addr: 192.168.1.71
Netmask: 255.255.255.0
Gateway: 192.168.1.1
DHCPsrv: 0.0.0.0
DNSserv: 8.8.8.8
http://www.adafruit.com -> 207.58.139.247
Pinging 207.58.139.247...5 replies
Ping successful!
Closing the connection