There shouldn't be any internal sleep tasks - either the Oak is doing what it's told, or something went wrong!TM. I've had Oaks running 24x7 for a few weeks now, one doing deepSleeps as it is a sensor node, and the other running all the time, as it is a display module. So did you just whack together something from the generic ESP8266 I mentioned earlier, or did you use some other code?
I have cobbled together some code for the unidots dashboard, and it seems to be working ok so far. It basically starts up, gets the reading (ditches the first in case it is wrong as usually is), if there was no fails published temp to particle and unidots, if there was a fail, publish so to particle, and then deepSleep for one minute, which causes the unit to completely go to sleep, and the reset after 60 seconds in order to wake up and start all over again. After some stress testing for a day or two, I'll be changing it to 10 minute intervals. If you want to use it, you just need to put in your API and variable keys just above the setup function.
The retry code around getTemp is because I eneded up with a load of 'P' (or is it PAR?) variant DS18B20 temperature sensors, and they are a bit stubborn in giving up the temperature - I think a longer delay is needed between asking for and getting the temperature, but a retry was a serviceable quick fix until I go back and work it out.
// Initial DS18B20 code: OneWire DS18S20, DS18B20, DS1822 Temperature Example
// Initial Thingspeak code: exeng thingspeak oak code example
// Initial ubidots code: ubidots ESP8266 as stand-alone Module example
#define STATUS_LED 1
#define DS18S20_PIN 2
//#define DEBUG
#define DEBUG_OI Serial
#ifdef DEBUG
#define DebugBegin(...) DEBUG_OI.begin(__VA_ARGS__)
#define DebugPrint(...) DEBUG_OI.print(__VA_ARGS__)
#define DebugPrintln(...) DEBUG_OI.println(__VA_ARGS__)
#define DebugWrite(...) DEBUG_OI.write(__VA_ARGS__)
#else
// Define the counterparts that cause the compiler to generate no code
#define DebugBegin(...) (void(0))
#define DebugPrint(...) (void(0))
#define DebugPrintln(...) (void(0))
#define DebugWrite(...) (void(0))
#endif
#include <OneWire.h>
#include <WiFiClient.h>
#include <ESP8266WiFi.h>
OneWire ds(DS18S20_PIN); //(a 4.7K resistor is necessary)
char tempStr[8];
float tempC = 0.0;
int retries = 0;
int status = WL_IDLE_STATUS; // the Wifi radio's status
WiFiClient client;
//Unidots variables
String idvariable = "----------Put your variableid in here---------";
String token = "----------Put your token here-----------";
void setup(void)
{
//Particle.publish("DS18x20_Temperature");
DebugBegin(9600);
pinMode(STATUS_LED, OUTPUT);
digitalWrite(STATUS_LED, LOW);
while ( WiFi.status() != WL_CONNECTED)
{
digitalWrite(STATUS_LED, HIGH);
status = WiFi.begin();
// wait 10 seconds for connection:
delay(10000);
digitalWrite(STATUS_LED, LOW);
}
//ditch first reading from DS18B20
tempC = getTemp();
if (tempC <= -1000 && retries < 5)
{
tempC = getTemp();
retries++;
}
}
void loop(void)
{
if (tempC <= -1000 && retries < 5)
{
tempC = getTemp();
retries++;
}
//tempF = celsius * 1.8 + 32.0;
dtostrf(tempC, 5, 2, tempStr);
// either publish error state to particle, or temperature to particle and thingspeak
if(tempC <= -1000)
{
Particle.publish("ubidots_DS18B20 Error", tempStr, 60, PRIVATE);
}
else
{
Particle.publish("ubidots_tempC", tempStr, 60, PRIVATE);
updateUnidots(tempC);
}
DebugPrint(" Temperature = ");
DebugPrint(tempC);
DebugPrintln(" Celsius");
// DebugPrint(tempF);
// DebugPrintln(" Fahrenheit");
// power save for 60 seconds
ESP.deepSleep(60 * 1000000, WAKE_RF_DEFAULT);
}
float getTemp()
{
byte i;
byte present = 0;
byte type_s;
byte data[12];
byte addr[8];
float celsius, fahrenheit;
if ( !ds.search(addr)) {
DebugPrintln("No more addresses.");
DebugPrintln();
ds.reset_search();
delay(250);
return -1000.00;
}
DebugPrint("ROM =");
for ( i = 0; i < 8; i++) {
DebugWrite(' ');
DebugPrint(addr[i], HEX);
}
if (OneWire::crc8(addr, 7) != addr[7]) {
DebugPrintln("CRC is not valid!");
return -2000.0;
}
DebugPrintln();
// the first ROM byte indicates which chip
switch (addr[0]) {
case 0x10:
DebugPrintln(" Chip = DS18S20"); // or old DS1820
type_s = 1;
break;
case 0x28:
DebugPrintln(" Chip = DS18B20");
type_s = 0;
break;
case 0x22:
DebugPrintln(" Chip = DS1822");
type_s = 0;
break;
default:
DebugPrintln("Device is not a DS18x20 family device.");
return -3000.0;
}
ds.reset();
ds.select(addr);
ds.write(0x44, 1); // start conversion, with parasite power on at the end
delay(1000); // maybe 750ms is enough, maybe not
// we might do a ds.depower() here, but the reset will take care of it.
present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad
DebugPrint(" Data = ");
DebugPrint(present, HEX);
DebugPrint(" ");
for ( i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds.read();
DebugPrint(data[i], HEX);
DebugPrint(" ");
}
DebugPrint(" CRC=");
DebugPrint(OneWire::crc8(data, 8), HEX);
DebugPrintln();
// Convert the data to actual temperature
// because the result is a 16 bit signed integer, it should
// be stored to an "int16_t" type, which is always 16 bits
// even when compiled on a 32 bit processor.
int16_t raw = (data[1] << 8) | data[0];
if (type_s) {
raw = raw << 3; // 9 bit resolution default
if (data[7] == 0x10) {
// "count remain" gives full 12 bit resolution
raw = (raw & 0xFFF0) + 12 - data[6];
}
} else {
byte cfg = (data[4] & 0x60);
// at lower res, the low bits are undefined, so let's zero them
if (cfg == 0x00) raw = raw & ~7; // 9 bit resolution, 93.75 ms
else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
//// default is 12 bit resolution, 750 ms conversion time
}
celsius = (float)raw / 16.0;
return celsius;
}
boolean updateUnidots(float value)
{
// if you get a connection, report back via serial:
int num=0;
String var = "{\"value\": " + String(value)+"}";
num = var.length();
if (client.connect("things.ubidots.com", 80)) {
DebugPrintln("connected ubidots");
delay(100);
client.println("POST /api/v1.6/variables/"+idvariable+"/values HTTP/1.1");
DebugPrintln("POST /api/v1.6/variables/"+idvariable+"/values HTTP/1.1");
client.println("Content-Type: application/json");
DebugPrintln("Content-Type: application/json");
client.println("Content-Length: "+String(num));
DebugPrintln("Content-Length: "+String(num));
client.println("X-Auth-Token: "+token);
DebugPrintln("X-Auth-Token: "+token);
client.println("Host: things.ubidots.com\n");
DebugPrintln("Host: things.ubidots.com\n");
client.print(var);
DebugPrint(var+"\n");
}
else {
// if you didn't get a connection to the server:
DebugPrintln("ubidots connection failed");
DebugPrintln("NotConnected");
return false;
}
return true; //successful connection
}