wifi -driving me nuts! help

I am trying to send my sensor data to a cloud service, but it not going well. I thinking the wifi cilent is still not right. any thoughts?

I can compile the program and an run the serial monitor a receive information that its connected to the network, but it seems to stop there and not sending any sensor data. gets me up to here in the code.

#include <Wire.h>                              // enable I2C.
#include <SPI.h>                               // ethernet shield libraries
#include <WiFi.h>
#include <Adafruit_CC3000.h>
#include <Adafruit_CC3000_Server.h>
#include <ccspi.h>
#define NUM_CIRCUITS 2                         // <-- CHANGE THIS  set how many I2C circuits are attached to the Tentacle

const unsigned int send_readings_every = 2000; // set at what intervals the readings are sent to the computer (NOTE: this is not the frequency of taking the readings!)
unsigned long next_serial_time;

char sensordata[30];                          // A 30 byte character array to hold incoming data from the sensors
byte sensor_bytes_received = 0;               // We need to know how many characters bytes have been received
byte code = 0;                                // used to hold the I2C response code.
byte in_char = 0;                             // used as a 1 byte buffer to store in bound bytes from the I2C Circuit.

int channel_ids[] = {99, 102};        // <-- A list of I2C ids that you set your circuits to.
String channel_names[] = {"PH", "RTD"};   // <-- CHANGE THIS. A list of channel names (must be the same order as in channel_ids[]) - only used to give a name to the "Signals" sent to initialstate.com
String sensor_data[NUM_CIRCUITS];             // an array of strings to hold the readings of each channel
int channel = 0;                              // INT pointer to hold the current position in the channel_ids/channel_names array

const unsigned int reading_delay = 1000;      // time to wait for the circuit to process a read command. datasheets say 1 second.
unsigned long next_reading_time;              // holds the time when the next reading should be ready from the circuit
boolean request_pending = false;              // wether or not we're waiting for a reading

const unsigned int cloud_update_interval = 10000; // time to wait for the circuit to process a read command. datasheets say 1 second.
unsigned long next_cloud_update;              // holds the time when the next reading should be ready from the circuit



// INITIAL STATE CONFIGURATION
const String ISDestURL = "insecure-groker.initialstate.com";
const String bucketKey = "XXXXXX;
const String bucketName = "XXXX";
const String accessKey = "XXXXXX";
// NOTE: when changing bucketName, make sure you change bucketKey, too. Bucket key can be anything - it's used to differentiate buckets, in case you have multiple.

// NETWORK CONFIGURATION


WiFiClient client;

byte mac[] = { 0x90, 0xA2, 0xDA, 0x0E, 0xC7, 0xF7 }; // assign a MAC address for the ethernet controller - e.g. try the one on the sticker of your ethernet shield
IPAddress ip(192, 168, 1, 177);                    // fill in an available IP address on your network here (uncomment for manual IP)
//IPAddress myDns(8, 8, 8, 8); // fill in your Domain Name Server address here. 8.8.8.8 for Google Public DNS (uncomment for manual IP)


// CC3000 interrupt and control pins
#define ADAFRUIT_CC3000_IRQ   3 // MUST be an interrupt pin!
#define ADAFRUIT_CC3000_VBAT  5 // These can be
#define ADAFRUIT_CC3000_CS   10 // any two pins
// Hardware SPI required for 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);

// WiFi access point credentials
#define WLAN_SSID     "XXXXXX"  // 32 characters max
#define WLAN_PASS     "XXXXXX"
#define WLAN_SECURITY WLAN_SEC_WPA2 // WLAN_SEC_UNSEC/WLAN_SEC_WEP/WLAN_SEC_WPA/WLAN_SEC_WPA2

/////////////////////////////////AJG-END1////////////////////////////////////////////////////

void setup() {

  pinMode(13, OUTPUT);                               // set the led output pin
  Serial.begin(115200);                               // Set the hardware serial port.
  while (!Serial) {
    ; // wait for usb serial (
  }
  Serial.println("starting");
  Wire.begin();                          // enable I2C port.

  delay(1000);                                       // Time for the ethernet shield to boot

  uint32_t ip = 0L, t;

  Serial.begin(115200);
  Serial.println(F("Hello, CC3000!"));


  Serial.print(F("Initializing..."));
  if (!cc3000.begin()) {
    Serial.println(F("failed. Check your wiring?"));
    return;
  }

  Serial.print(F("OK.\r\nConnecting to network..."));
  if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
    Serial.println(F("Failed!"));
    return;
  }
  Serial.println(F("connected!"));

I think the problem is here… not sure what it is though…

  while (!createBucket()) {};                          // create a bucket, if it doesn't exist yet
  next_serial_time = millis() + send_readings_every * 3; // wait a little longer before sending serial data the first time
  next_cloud_update = millis() + cloud_update_interval;
}



void loop() {
  updateSensors();                // read / write to the sensors. returns fast, does not wait for the data to arrive
  updateSerial();                 // write sensor data to the serial port
  updateCloud();                  // send the sensor data to the cloud. returns fast, except when a cloud update is due.

You should post

  1. the complete code, not only fragments
  2. in one block between code tags

-> so one could see how the functions look like and - I am curious to see, if the while loop belongs to the setup or to a function.

void setup() {

  pinMode(13, OUTPUT);                               // set the led output pin
  Serial.begin(115200);                               // Set the hardware serial port.
  while (!Serial) {
    ; // wait for usb serial (
  }
  Serial.println("starting");
  Wire.begin();                          // enable I2C port.

  delay(1000);                                       // Time for the ethernet shield to boot

  /////////////////////////////////AJG-BEGIN1////////////////////////////////////////////////////
  uint32_t ip = 0L, t;

  Serial.begin(115200);
  Serial.println(F("Hello, CC3000!"));


  Serial.print(F("Initializing..."));
  if (!cc3000.begin()) {
    Serial.println(F("failed. Check your wiring?"));
    return;
  }

  Serial.print(F("OK.\r\nConnecting to network..."));
  if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
    Serial.println(F("Failed!"));
    return;
  }
  Serial.println(F("connected!"));

  /////////////////////////////////AJG-END1////////////////////////////////////////////////////

  //  while (Ethernet.begin(mac) == 0) {                 // Try to get an IP (DHCP). For a custom IP config, change to Ethernet.begin(mac, ip, myDns)
  //    Serial.println("Failed to configure Ethernet");
  //    delay(5000);
  //  }

  // Serial.print("IP address:\t");
  //  Serial.println(Ethernet.localIP());

  while (!createBucket()) {};                          // create a bucket, if it doesn't exist yet
  next_serial_time = millis() + send_readings_every * 3; // wait a little longer before sending serial data the first time
  next_cloud_update = millis() + cloud_update_interval;
}



void loop() {
  updateSensors();                // read / write to the sensors. returns fast, does not wait for the data to arrive
  updateSerial();                 // write sensor data to the serial port
  updateCloud();                  // send the sensor data to the cloud. returns fast, except when a cloud update is due.
 
  
  
  
  //  other arduino stuff here


  
}


// send the data to the cloud - but only when it's time to do so
void updateCloud() {

  //if (client.available()) {    // uncomment for debugging
  //  char c = client.read();
  //  Serial.write(c);
  //}

  if (millis() >= next_cloud_update) {                // is it time for the next serial communication?

    while (!sendData());

    next_cloud_update = millis() + cloud_update_interval;
  }
}



// do serial communication in a "asynchronous" way
void updateSerial() {
  if (millis() >= next_serial_time) {              // is it time for the next serial communication?
    Serial.println("---------------");
    for (int i = 0; i < NUM_CIRCUITS; i++) {       // loop through all the sensors
      Serial.print(channel_names[i]);              // print channel name
      Serial.print(":\t");
      Serial.println(sensor_data[i]);              // print the actual reading
    }
    Serial.println("---------------");
    next_serial_time = millis() + send_readings_every;
  }
}



// take sensor readings in a "asynchronous" way
void updateSensors() {
  if (request_pending) {                          // is a request pending?
    if (millis() >= next_reading_time) {          // is it time for the reading to be taken?
      receiveReading();                           // do the actual I2C communication
    }
  } else {                                        // no request is pending,
    channel = (channel + 1) % NUM_CIRCUITS;       // switch to the next channel (increase current channel by 1, and roll over if we're at the last channel using the % modulo operator)
    requestReading();                             // do the actual I2C communication
  }
}

Are you using a Tentacle shield and I2C? have you pre-set the I2C adresses?

do you have a working code independent of the Ethernet stuff working with just the tentacle shield and delivering the right sensor values?

Similarly, can you get rid of all the code dealing with the Tentacle but keep the functions returning dummy values and see if you manage to connect to the internet?

J-M-L:
Are you using a Tentacle shield and I2C? have you pre-set the I2C adresses?

do you have a working code independent of the Ethernet stuff working with just the tentacle shield and delivering the right sensor values?

Similarly, can you get rid of all the code dealing with the Tentacle but keep the functions returning dummy values and see if you manage to connect to the internet?

YES! I am using the tentacle shield ! so awesome your familiar, what is your experience! i just want my data sent over wifi now…

I do have working code in another sketch w/o any networking. My ph and temp sensors work great and display on a LCD.
So I have two sketches one for the shield which works great reading sensors and displaying on LCD.

and the other… the one I posted above trying to just get the info sent to a data site

I feel the tentacle shield is nice in a lab or education space, quite pricey for tinkering around and adds extra layer of abstraction (Sure it isolates the sensors and eliminates some possible noise or ground issues but that's cool to understand those things at least once in a tinkerer life :-))

They support both serial UART and I2C communication. I understand yours is fully set up as I2C, right? I mean you have set the jumpers like below for the 4 channel slots |500x239

I see you have this definition for the CC3000

#define ADAFRUIT_CC3000_VBAT  [color=red]5[/color] // These can be
#define ADAFRUIT_CC3000_CS   [color=red]10[/color] // any two pins

--> Your Ethernet Board uses SPI so does require 10 and 11. so you can't have the tentacle messing around with those pins.

Have you removed the serial definition jumper –> this is needed to free arduino pins 4,5,6,7,,10 and 11. |500x295

For your code - again hard to say because you did not share a full code...

I can see though that you have twice Serial.begin(115200); in your setup() and the way you deal with timing will overflow at some point. (I know this is in their example but it's not a good practice) don't do millis() >= next_serial_time where next_serial_time is calculated as next_serial_time = millis() + send_readings_every do(millis() - previousTime > send_readings_every)

You declare 13 as an output. pin 13 on a uno is SCK – digital 13 and is used by the SPI protocol which you rely on for ethernet. Are you using PIN 13 for other things in your code like blinking a LED (like they do in one of their example, or you just copied that by mistake)? don't play with PIN 13.

Are you using a CC3000 Breakout or the full CC3000 Shield? if you are using the shield, how are those stacked with the tentacle? Are SDA and SCL pins going through your stack?

Have you looked at "CC3000 WebClient Test"? that's probably better suited for what you want to achieve?

would be easier if you were posting

  • full source code that compiles
  • a drawing (manual) picture of how your connexions are set
  • the exact HW you have

@ageno125, I think @J-M-L pointed you just to the right directions. Try to get the two parts working separately first. Get the sensors working and just blurp something out the serial at the moment you'd like to post to the cloud. On the other hand, get a simple WiFi example working. Once both work, start to merge them.

Not much to add to J-M-Ls comments regarding the pins, jumpers etc - he's exactly right. One word regarding the Tentacle though - it doesn't add a layer of abstraction. In fact, it's completely transparent in terms of communication and just adds a layer of isolation and thus precision. In case you're measuring conductivity (EC) in the same liquid as say, pH, there's no way around proper isolation. Or else, pH/ORP readings will be ga Our example codes add some layer of abstraction, but that's just how we implemented communications with the EZO circuits. That code would work without the shield, too (at least the i2c parts...).

Glad to help if you have any other specific questions regarding Tentacle / EZO circuits.

Patrick / Whitebox Labs

J-M-L:

  • full source code that compiles
  • a drawing (manual) picture of how your connexions are set
  • the exact HW you have

Exactly why I purchased the shield for education, trying to create a lab for my students in reading Ph, temp, etc of soil samples (minus the coding portion) and how they change throughout the day(s). I like the isolation b/c the sensors will be some distance away from the controller.

The jumper on the tentacle shield is pulled and set for I2C as well as the Stamps.

The shield is working fine taking readings another sketch that I have.

Hardware:
-Arduino Uno R3
-Tentacle shield with PH and Temp stamps
-Adafruit cc3000 wifi shield

I have two shields on top of an Arduino Uno R3 fitted into matching headers

Uno R3 (bottom) – Tentacle Shield (middle) – Top Adafruit wifi shield (top)

Jumper: Digital pin7 for a 3.3v buzzer

SCL & SDA pins to a 5v LCD screen (SCL & SDA pins are fully connected across the shields. )
everything else is open. (I removed the LED from pin13)

Taking in your suggestions and looking at the Wificlient example: I seem to connect to my network and to the initial logging site (or I should say receive its IP). It still doesn’t appear to be reading/sending the data.

CODE
Have ATTACHED the complete code as I did no want to leave out any pertinent information.

datalog.ino (16.3 KB)

does your Arduino Uno R3 have the SDA and SCL pins after PIN D13 / GND / AREF ?

|500x500

Have you soldered the SPI ICSP headers on the CC3000 shield and enabled the jumpers? |500x370

J-M-L: does your Arduino Uno R3 have the SDA and SCL pins after PIN D13 / GND / AREF ?

|500x500

Have you soldered the SPI ICSP headers on the CC3000 shield and enabled the jumpers? |500x370

does your Arduino Uno R3 have the SDA and SCL pins after PIN D13 / GND / AREF ? yes. And oh my goodness, I did not soldered those headers, the tentacle shield didn't have a header for it and I must of over looked it... soldering gun heatin up!

NO NO don't solder it! it's actually good you did not do it

as you say the tentacle shield does not have a way to plug those in - so I was worried you had soldered them and the jumpers which would have re-routed the SPI header

You just need to make sure the PINS which are also repressing SPI go through your tentacle fine to the Wifi Shield

J-M-L: NO NO don't solder it! it's actually good you did not do it

as you say the tentacle shield does not have a way to plug those in - so I was worried you had soldered them and the jumpers which would have re-routed the SPI header

You just need to make sure the PINS which are also repressing SPI go through your tentacle fine to the Wifi Shield

oh, that was close.

the PINS are definitely completely pressed and seated nicely on the tentacle headers.

So my next suggestion would be the you try to get a Wifi only code running but with the full 3 layer sandwich to ensure that there are no missing connections.

1/ Can you just try any example with the CC3000 and see if you can connect to the web and do stuff? 2/ can you take your code that is doing just the PH reading and while the "sandwich" is plugged in, try it too.

this way we have a sound based to build from. if that does not work then we need to debug that part