Errors in Thermo-Hygro Receiver project with CC3000 Wifi Shield

Hi,

I’m trying the following project: I have a wireless thermo-hygro sensor, like this:

I’m trying to read out the signal of the smaller unit using a 433Mhz RF receiver (this type).

When the temperature and humidity readings from the RF receiver are in, i want to post them to a server to save the values, using a CC3000 wifi shield.

I have a functioning program where I print the temperature and humidity values to serial (without posting over wifi to the server). So reading the RF signal works.

I also have a functioning program posting to the server using the CC3000 when I do it in the setup() method, as in the cc3000 webclient example.

But I have to post in the ‘showTempHumi’ callback function of the SensorReceiver, and that’s when it stops working.
The code below has big parts of the code commented out, to pinpoint the first piece of code that seems to break the program. When adding the while()-loop in the postData() function, the callback function fails to work (no Serial output from within the ‘showTempHumi’ and ‘postData’ functions).
When the while()-loop is commented out, the Serial output from the ‘showTempHumi’ and ‘postData’ functions return.

/*
 * This sketch receives and decodes data from a 433MHz thermo/hygro weather sensor.
 * The received data (temperature, humidity, channel) is echo
 *
 * Setup:
 * - Connect digital output of a 433MHz receiver to digital pin 2 of Arduino
 * - Enable the serial monitor at 115200 baud. 
 *
 */

#include <SensorReceiver.h>
#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>

// These are the interrupt and control pins
const uint8_t ADAFRUIT_CC3000_IRQ = 3;  // MUST be an interrupt pin!
// These can be any two pins
const uint8_t ADAFRUIT_CC3000_VBAT = 5;
const uint8_t ADAFRUIT_CC3000_CS = 10;
// Use hardware SPI for the 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); // you can change this clock speed

//const String WLAN_SSID = "Walho87d (extended)";
//const String WLAN_PASS = "063#ock+36DD";
// Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2
//const uint8_t WLAN_SECURITY = WLAN_SEC_WPA2;

const int IDLE_TIMEOUT_MS = 3000;      // Amount of time to wait (in milliseconds) with no data 
                                   // received before closing the connection.  If you know the server
                                   // you're accessing is quick to respond, you can reduce this value.

// What page to grab!
const String WEBSITE = "192.168.1.117";
const String WEBPAGE = "/climate";

uint32_t ip;

void setup() {
  Serial.begin(115200);
  
  Serial.println(F("Hello, CC3000!\n")); 
  
  Serial.println(F("\nInitializing..."));
  if (!cc3000.begin())
  {
    Serial.println(F("Couldn't begin()! Check your wiring?"));
    while(1);
  }
  Serial.println(F("Done!"));
  
  // postData("35", "89");

  // Init the receiver on interrupt pin 0 (digital pin 2).
  // Set the callback to function "showTempHumi", which is called
  // whenever valid sensor data has been received.
  SensorReceiver::init(0, showTempHumi);
}

void loop() {
  // Empty! However, you can do other stuff here if you like.
  delay(1000);
}

void showTempHumi(byte *data) {
  Serial.println(F("In showTempHumi"));
  
  // is data a ThermoHygro-device?
  if ((data[3] & 0x1f) == 0x1e) {
    // Yes!
    byte channel, randomId;
    int temp;
    byte humidity;

    // Decode the data
    SensorReceiver::decodeThermoHygro(data, channel, randomId, temp, humidity);

    // Print temperature. Note: temp is 10x the actual temperature!
    String tempStr = String(temp / 10) + '.' + String(temp % 10);

    postData(tempStr, String(humidity)); 

    Serial.println(F("data posted")); 
  }
}

void postData(String temp, String humidity) {
  if (!cc3000.connectToAP("Walho87d (extended)", "063#ock+36DD", WLAN_SEC_WPA2)) {
    Serial.println(F("Failed!"));
    while(1);
  }
  Serial.println(F("Connected!"));
  
  /* 
     This while-loop seems to break the showTempHumi and postData functions (nothing printed to Serial) 
     Commenting it out brings back the Serial output.
  */
  while (!cc3000.checkDHCP())
  {
    delay(100); // ToDo: Insert a DHCP timeout!
  }  
  
  /*
  ... other code for HTTP post commented out, to pinpoint problem

  */
  
  // You need to make sure to clean up after yourself or the CC3000 can freak out
  // the next time your try to connect ... 
  Serial.println(F("\n\nDisconnecting"));
  cc3000.disconnect();
}

I’ve spent several hours on this problem and really have no idea what’s going wrong.
I am pretty new to Arduino, and am running out of ideas.

All help is welcome :slight_smile: .

ThermoHygroReceiverTest.ino (1.76 KB)

void loop() {
  // Empty! However, you can do other stuff here if you like.
  delay(1000);
}

But stuffing your thumb up your ass for any length of time is stupid,

/* 
     This while-loop seems to break the showTempHumi and postData functions (nothing printed to Serial) 
     Commenting it out brings back the Serial output.
  */
  while (!cc3000.checkDHCP())
  {
    delay(100); // ToDo: Insert a DHCP timeout!
  }

What does checkDHCP() do? What does it actually return?