sparkfun CC3000 wifi to m2x

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

ok solved the problem.....

the m2x example was using #define, whereas the ping test was using char and unsigned int's.

now onto seeing if i can get this to properly connect to m2x and go the whole route... i had to do some monkeying with the example so that it made sense with my sensor instead of the temperature sensor... i think i might have botched something that has to do with how the info is updated. Or, maybe its another #define verses char issue...

looking in the library for m2x, things seemed to be referenced as int's and char's? i dont really have a grasp on libaries...

thanks

edit: i have changed the m2x references in the header to be lower case and to be char's, to match the example direct (ok apparently i tried to integrate at one point and failed) from m2x listed below:

#include <jsonlite.h>
#include <SPI.h>
#include <SFE_CC3000.h>
#include <SFE_CC3000_Client.h>

#include "M2XStreamClient.h"

char ssid[] = "<HOME-61B2>"; //  your network SSID (name)
char pass[] = "<DELETED>";    // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0;            // your network key Index number (needed only for WEP)

int status = WL_IDLE_STATUS;

char feedId[] = "<DEL:ETED>"; // Feed you want to post to
char streamName[] = "<Test1>"; // Stream you want to post to
char m2xKey[] = "<DELETED>"; // Your M2X access key

const int temperaturePin = 4;
WiFiClient client;
M2XStreamClient m2xClient(&client, m2xKey);

void setup() {
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    while(true);
  }

  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
  }
  Serial.println("Connected to wifi");
  printWifiStatus();
}

void loop() {
  float voltage, degreesC, degreesF;

  voltage = getVoltage(temperaturePin);
  degreesC = (voltage - 0.5) * 100.0;
  degreesF = degreesC * (9.0/5.0) + 32.0;

  Serial.print("voltage: ");
  Serial.print(voltage);
  Serial.print("  deg C: ");
  Serial.print(degreesC);
  Serial.print("  deg F: ");
  Serial.println(degreesF);

  int response = m2xClient.post(feedId, streamName, degreesC);
  Serial.print("M2x client response code: ");
  Serial.println(response);

  if (response == -1) while(1) ;

  delay(5000);
}


void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

float getVoltage(int pin)
{
  return (analogRead(pin) * 0.004882814);
}

edit 2....

the program is getting down to the read sensor, then it doesnt get past the step where it should be sending data. This is around line 127 (about 8 from the bottom) of the first code in the OP. At the least it should give me the Serial.print for the response that it's not getting from m2x?

I've now done a test with another sparkfun example the data.sparkfun.com, to see if i can get this data out over the internets... that example is hanging at the post function too.

I wonder if this is maybe a router problem?

so i finally got a successful post. I had to remove the <> from the m2x feed sections of the code. I also updated the library (released about a week before i actually tried to do all this) which probably helped as well. im now having trouble with multiple feeds, but i think that is a separate thread...

newneo_phyte:
so i finally got a successful post. I had to remove the <> from the m2x feed sections of the code. I also updated the library (released about a week before i actually tried to do all this) which probably helped as well. im now having trouble with multiple feeds, but i think that is a separate thread...

can you detail exactly what fields you used to populate the M2X constants:

// M2X Constants
#define FEED_ID
#define STREAM_NAME
#define M2X_KEY

i'm having the same problem you had but my code is all correct and library is updated. i'm struggling b/c the sparkfun tutorial was obviously written some time before ATT changed the names of the FEED_ID, STREAM_NAME and M2X_KEY fields.

also, did you use the sparkfun forked library or the ATT library?

Thanks,

I just realized my problem. It was idiotic and took way too long to resolve. I had connected the data pin of my DHT11 temperature/humidity sensor to pin 13 on the UNO. Apparently pin 13 is used for the SPI clock. Changed 13 to 8 and the sketch is working properly finally; getting 202 responses.

Are you getting M2X to work reliably?

I find I can post two streams of data from my Arduino to the M2X web page most of the time, but sometimes it drops out for an hour or so. I also have problems with logging into the web site. I have a very easy password but often it will not recognize it for a while and then it starts working again.

I have not yet been able to post a string to a stream of the web site and get the Arduino to read it such as M2X_CC3000_LED.ino. I don't know if I am doing something wrong or if it is just the unreliability of the M2X site.

I gave up on them and transitioned to the data.sparkfun.com server, which i am running on my own server. I had to learn a bit of web procedure to launch it on my own server but in the end it is easier to work with than M2X.

Does data.sparkfun.com have any way to send command data from the web to the CC3000? I need 2-way communication.

Hi. I'm using Arduino Mega 2560 and CC3000 wifi shield. I have a problem. I tried all Adafruit and Arduino's examples, but Wifi shield and Arduino can't connect. Can you help me?

cant connect to the internet or can't connect to m2x? Can you post the header of your sketch?

sherpadoug, sparkfun can send data to the cc3000, im not sure to what extent, though.