Using an UNO, i am attempting to connect to m2x for a data logging project. A couple months back i had a similar thread with an Adafruit CC3000, but i could not get anywhere... So i bought a Sparkfun CC3000 which seemed to already have functioning examples for M2X. I have done successful ping tests and initialization tests etc. However, i cannot seem to get the shield to even connect to the network while running the m2x example. Internet is functioning properly and SSID and Passwords are correct/copy and pasted from windows utilities.
First is the m2x example, what follows is a functioning ping test. You dont need to read past Setup, the code program has not gotten past that point yet....
/****************************************************************
M2X_CC3000_Post.ino
Post temperature data to AT&T's M2X
Shawn Hymel @ SparkFun Electronics
August 19, 2014
Manually connects to a WiFi network and an M2X stream. Reads
temperature data from an HTU21D temperature and posts it to the
M2X stream.
Change AP_SSID, AP_PASSWORD, AP_SECURITY, FEED_ID, STREAM_NAME,
and M2X_KEY to match your WiFi and M2X parameters.
The security mode is defined by one of the following:
WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA, WLAN_SEC_WPA2
Resources:
Include SPI.h, SFE_CC3000.h, SFE_CC3000_Client.h, jsonlite.h,
M2XStreamClient.h, Wire.h, HTU21D.h
Development environment specifics:
Written in Arduino 1.0.5
Tested with Arduino UNO R3
This code is beerware; if you see me (or any other SparkFun
employee) at the local, and you've found our code helpful, please
buy us a round!
Distributed as-is; no warranty is given.
****************************************************************/
#include <SPI.h>
#include <SFE_CC3000.h>
#include <SFE_CC3000_Client.h>
#include <jsonlite.h>
#include <M2XStreamClient.h>
#include <Wire.h>
// Parameters
#define POST_DELAY_MS 10000 // Post to stream every 10 seconds
// Pins
#define CC3000_INT 2 // Needs to be an interrupt pin (D2/D3)
#define CC3000_EN 7 // Can be any digital pin
#define CC3000_CS 10 // Preferred is pin 10 on Uno
// Connection info data lengths
#define IP_ADDR_LEN 4 // Length of IP address in bytes
// WiFi Constants
#define AP_SSID "<HOME-61B2>" // SSID of network
#define AP_PASSWORD "<DELETED FOR THIS POST>" // Password of network
#define AP_SECURITY WLAN_SEC_WPA2 // Security of network
#define TIMEOUT 30000 // Milliseconds
// M2X Constants
#define FEED_ID "<DELETED FOR THIS POST>"
#define STREAM_NAME "<Test1>"
#define M2X_KEY "<DELETED FOR THIS POST>"
// Global Variables
SFE_CC3000 wifi = SFE_CC3000(CC3000_INT, CC3000_EN, CC3000_CS);
SFE_CC3000_Client client = SFE_CC3000_Client(wifi);
M2XStreamClient m2x_client(&client, M2X_KEY);
const int sensPin=4;
long sensor,inches;
// Setup. Configure HTU21D, WiFi, and M2X.
void setup() {
ConnectionInfo connection_info;
IPAddress ip_addr;
IPAddress remote_ip;
PingReport ping_report = {0};
int i;
// Initialize UART for debugging
Serial.begin(115200);
Serial.println();
Serial.println(F("SparkFun CC3000 - M2X Post"));
//sensor ini
pinMode(sensPin,INPUT);
// Initialize CC3000 (configure SPI communications)
if ( wifi.init() ) {
Serial.println(F("CC3000 initialization complete"));
} else {
Serial.println(F("Something went wrong during CC3000 init!"));
}
// Connect using DHCP
Serial.print(F("Connecting to SSID: "));
Serial.println(AP_SSID);
if(wifi.connect(AP_SSID, AP_SECURITY, AP_PASSWORD, TIMEOUT)) {
Serial.println(F("Connected!"));
} else {
Serial.println(F("Error: Could not connect to AP"));
}
if ( !wifi.getConnectionInfo(connection_info) ) {
Serial.println("Error: Could not obtain connection details");
} else {
Serial.println("Connected!");
Serial.print("IP Address: ");
for (i = 0; i < IP_ADDR_LEN; i++) {
Serial.print(connection_info.ip_address[i]);
if ( i < IP_ADDR_LEN - 1 ) {
Serial.print(".");
}
}
}
}
// Main loop. Post sensor readings at regular intervals.
void loop() {
// Read sensor
sensor=pulseIn(sensPin,HIGH);
inches=sensor/147;
// Print reading to console with degree symbol and 'C'
Serial.print(F("Inches: "));
Serial.print(inches);
// Post data to your stream
int response = m2x_client.post(FEED_ID, STREAM_NAME, inches);
// If we fail to receive a response, stop running
Serial.print(F("Post response: "));
Serial.println(response);
if ( response == -1 ) {
while(1);
}
// Wait to post to stream again
delay(POST_DELAY_MS);
}
the working ping test:
//DEVELOPER COMMENTS DELETED FOR BREVITY
#include <SPI.h>
#include <SFE_CC3000.h>
// Pins
#define CC3000_INT 2 // Needs to be an interrupt pin (D2/D3)
#define CC3000_EN 7 // Can be any digital pin
#define CC3000_CS 10 // Preferred is pin 10 on Uno
// Connection info data lengths
#define IP_ADDR_LEN 4 // Length of IP address in bytes
// Constants
char ap_ssid[] = "HOME-61B2"; // SSID of network
char ap_password[] = "DELETED FOR POST"; // Password of network
unsigned int ap_security = WLAN_SEC_WPA2; // Security of network
unsigned int timeout = 30000; // Milliseconds
char remote_host[] = "www.sparkfun.com"; // Host to ping
unsigned int num_pings = 3; // Number of times to ping
// Global Variables
SFE_CC3000 wifi = SFE_CC3000(CC3000_INT, CC3000_EN, CC3000_CS);
void setup() {
ConnectionInfo connection_info;
IPAddress ip_addr;
IPAddress remote_ip;
PingReport ping_report = {0};
int i;
// Initialize Serial port
Serial.begin(115200);
Serial.println();
Serial.println("---------------------------");
Serial.println("SparkFun CC3000 - Ping Test");
Serial.println("---------------------------");
// Initialize CC3000 (configure SPI communications)
if ( wifi.init() ) {
Serial.println("CC3000 initialization complete");
} else {
Serial.println("Something went wrong during CC3000 init!");
}
// Connect and wait for DHCP-assigned IP address
Serial.print("Connecting to: ");
Serial.println(ap_ssid);
if(!wifi.connect(ap_ssid, ap_security, ap_password, timeout)) {
Serial.println("Error: Could not connect to AP");
}
// Gather connection details and print IP address
if ( !wifi.getConnectionInfo(connection_info) ) {
Serial.println("Error: Could not obtain connection details");
} else {
Serial.println("Connected!");
Serial.print("IP Address: ");
for (i = 0; i < IP_ADDR_LEN; i++) {
Serial.print(connection_info.ip_address[i]);
if ( i < IP_ADDR_LEN - 1 ) {
Serial.print(".");
}
}
Serial.println();
}
// Perform a DNS lookup to get the IP address of a host
Serial.print("Looking up IP address of: ");
Serial.println(remote_host);
if ( !wifi.dnsLookup(remote_host, &remote_ip) ) {
Serial.println("Error: Could not lookup host by name");
} else {
Serial.print("IP address found: ");
for (i = 0; i < IP_ADDR_LEN; i++) {
Serial.print(remote_ip[i], DEC);
if ( i < IP_ADDR_LEN - 1 ) {
Serial.print(".");
}
}
Serial.println();
}
// Ping IP address of remote host
Serial.print("Pinging ");
for (i = 0; i < IP_ADDR_LEN; i++) {
Serial.print(remote_ip[i], DEC);
if ( i < IP_ADDR_LEN - 1 ) {
Serial.print(".");
}
}
Serial.print(" ");
Serial.print(num_pings, DEC);
Serial.println(" times...");
if ( !wifi.ping(remote_ip, ping_report, 3, 56, 1000) ) {
Serial.println("Error: no ping response");
} else {
Serial.println("Pong!");
Serial.println();
Serial.print("Packets sent: ");
Serial.println(ping_report.packets_sent);
Serial.print("Packets received: ");
Serial.println(ping_report.packets_received);
Serial.print("Min round time (ms): ");
Serial.println(ping_report.min_round_time);
Serial.print("Max round time (ms): ");
Serial.println(ping_report.max_round_time);
Serial.print("Avg round time (ms): ");
Serial.println(ping_report.avg_round_time);
Serial.println();
}
// Disconnect
if ( wifi.disconnect() ) {
Serial.println("Disconnected");
} else {
Serial.println("Error: Could not disconnect from network");
}
// Done!
Serial.println("Finished ping test");
}
void loop() {
// Do nothing
delay(1000);
}
thanks a lot for any help