I am trying to post temperature measurements from DS18b20 thermal sensors to an online repository using a cc3000 WiFi shield on an Arduino Mega. It works great, once. All the temperatures get read fine. Then I post the data. Then the temperatures all return -127 error values.
If I fix the temperatures to const values, I can send any amount of data over wifi. If I don't send the data over wifi, I can pull temperatures indefinitely.
I can't imagine anyone is set up to test this or has a good way to debug it, so I am open to wild speculation- Any guesses what is going wrong? Any suggestions on how to debug it?
Here is my code:
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
#define temppin 53
#define ADAFRUIT_CC3000_IRQ 3 // MUST be an interrupt pin!
#define ADAFRUIT_CC3000_VBAT 5 // any pin
#define ADAFRUIT_CC3000_CS 10 // any pin
// 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 but DI
#define WLAN_SSID "MyNetwork" // cannot be longer than 32 characters!
#define WLAN_PASS "mypassword"
// Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2
#define WLAN_SECURITY WLAN_SEC_WPA2
uint32_t dweetioIp = 0;
char c;
unsigned long lastpost = 15000L;
OneWire oneWire(temppin);
DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature.
DeviceAddress TS1 = {0x28, 0xFF, 0xB4, 0x5E, 0x68, 0x14, 0x03, 0x60}; // serial numbers
DeviceAddress TS2 = {0x28, 0xFF, 0xFE, 0x4F, 0x68, 0x14, 0x02, 0xDD}; // for DS18b20's
DeviceAddress TS3 = {0x28, 0xFF, 0x3D, 0x5C, 0x68, 0x14, 0x03, 0x5F};
DeviceAddress TS4 = {0x28, 0xFF, 0x16, 0x5C, 0x68, 0x14, 0x03, 0xD7};
DeviceAddress TS5 = {0x28, 0xFF, 0xA3, 0x62, 0x51, 0x14, 0x04, 0xC4};
DeviceAddress TS6 = {0x28, 0xFF, 0xA9, 0x61, 0x68, 0x14, 0x03, 0x22};
DeviceAddress TS7 = {0x28, 0xFF, 0x2A, 0x72, 0x68, 0x14, 0x03, 0x17};
DeviceAddress TS8 = {0x28, 0xFF, 0xD2, 0x61, 0x68, 0x14, 0x03, 0x3F};
DeviceAddress TS9 = {0x28, 0xFF, 0xFA, 0x43, 0x68, 0x14, 0x02, 0xD0};
DeviceAddress TS10 = {0x28, 0xFF, 0x0B, 0x63, 0x68, 0x14, 0x02, 0xCB};
DeviceAddress TS11 = {0x28, 0xFF, 0x97, 0x41, 0x68, 0x14, 0x02, 0x2A};
DeviceAddress TS12 = {0x28, 0xFF, 0x47, 0x7E, 0x68, 0x14, 0x03, 0xF8};
DeviceAddress TS16 = {0x28, 0xC8, 0x47, 0x15, 0x06, 0x00, 0x00, 0xF0};
float t1;
float t2;
float t3;
float t4;
float t5;
float t6;
float t7;
float t8;
float t9;
float t10;
float t11;
float t12;
float t13;
String command = "";
boolean stringComplete = false;
void setup() {
Serial.begin(115200);
sensors.begin();
pinMode(temppin, INPUT);
// Initialize wifi shield
if (!cc3000.begin()) {
Serial.println(F("\n\nFailed to initialize WiFi shield."));
}
Serial.println(F("\n\nInitialized WiFi shield"));
// Connect to wifi network
if (!cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
Serial.println(F("Failed to connect to WiFi network"));
}
Serial.print(F("Connected to "));
Serial.println(F(WLAN_SSID));
// Wait for DHCP to complete (get an IP address)
while (!cc3000.checkDHCP()) {
delay(1000);
Serial.println(F("Waiting to get IP address"));
}
Serial.println(F("Got an IP address\n"));
// Connect to dweet.io
while (dweetioIp == 0) {
if (! cc3000.getHostByName("dweet.io", &dweetioIp)) {
Serial.println(F("Failed to resolve dweetio website"));
}
delay(500);
Serial.println(F("Resolving dweetio website"));
}
Serial.print("Accessed dweetio website at IP address: ");
cc3000.printIPdotsRev(dweetioIp);
Serial.println();
}
void loop() {
// Get temperatures
sensors.requestTemperatures();
delay(1000);
t1 = sensors.getTempC(TS1);
t2 = sensors.getTempC(TS2);
t3 = sensors.getTempC(TS3);
t4 = sensors.getTempC(TS4);
t5 = sensors.getTempC(TS5);
t6 = sensors.getTempC(TS6);
t7 = sensors.getTempC(TS7);
t8 = sensors.getTempC(TS8);
t9 = sensors.getTempC(TS9);
t10 = sensors.getTempC(TS10);
t11 = sensors.getTempC(TS11);
t12 = sensors.getTempC(TS12);
t13 = sensors.getTempC(TS16);
Serial.println(t1);
Serial.println(t2);
Serial.println(t3);
Serial.println(t4);
Serial.println(t5);
Serial.println(t6);
Serial.println(t7);
Serial.println(t8);
Serial.println(t9);
Serial.println(t10);
Serial.println(t11);
Serial.println(t12);
Serial.println(t13);
long curmillis = millis();
if (curmillis - lastpost > 1000*15L) {
// Post data to dweetio
char data[125];
sprintf(data, "?t1=%i&t2=%i&t3=%i&t4=%i&t5=%i&t6=%i&t7=%i&t8=%i&t9=%i&t10=%i&t11=%i&t12=%i&t13=%i",
(int)(t1*10.),(int)(t2*10.),(int)(t3*10.),(int)(t4*10.),(int)(t5*10.),
(int)(t6*10.),(int)(t7*10.),(int)(t8*10.),(int)(t9*10.),(int)(t10*10.),
(int)(t11*10.),(int)(t12*10.),(int)(t13*10.));
Adafruit_CC3000_Client client = cc3000.connectTCP(dweetioIp, 80);
if (client.connected()) {
client.fastrprint(F("GET "));
client.fastrprint(F("/dweet/for/testdweets"));
client.fastrprint(data);
client.fastrprint(F(" HTTP/1.1\r\n"));
client.fastrprint(F("Host: https://www.dweet.io\r\n"));
client.fastrprint(F("\r\n\r\n"));
// client.println();
Serial.println(F("Sent dweet\n"));
} else {
Serial.println(F("Sending dweet failed"));
return;
}
/* Read data until either the connection is closed, or the idle timeout is reached. */
unsigned long lastRead = millis();
while (client.connected() && (millis() - lastRead < 1000)) {
while (client.available()) {
char c = client.read();
Serial.print(c);
lastRead = millis();
}
}
client.close();
Serial.println("Connection to dweet.io closed");
lastpost = millis();
}
}