Hello! I’m attempting to monitor temperature using a DS18B20 sensor and the Particle Photon. I’m attempting to publish a temp
event via Particle#publish
every 2 minutes. Unfortunately, I’m observing events published every ~16 seconds via the CLI’s handy particle subscribe
. Here’s my project file:
// This #include statement was automatically added by the Particle IDE.
#include "OneWire/OneWire.h"
// This #include statement was automatically added by the Particle IDE.
#include "spark-dallas-temperature/spark-dallas-temperature.h"
#define ONE_WIRE_BUS D2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensor(&oneWire);
DeviceAddress deviceAddress;
const unsigned long sampleDuration = 2 * 60 * 1000UL;
// Initialize with `0` so it runs on the first loop
unsigned long lastSampled = 0;
int16_t temp;
void setup() {
// Serial.begin(9600);
sensor.begin();
// Mutates `deviceAddress`?
sensor.getAddress(deviceAddress, 0);
}
void loop() {
unsigned long now = millis();
if (now - lastSampled >= sampleDuration) {
sensor.requestTemperatures();
temp = sensor.getTemp(deviceAddress);
// Serial.print("Temperature: ");
// Serial.println(temp);
Particle.publish("temp", String(temp));
}
delay(1000);
}
I’ve also tried dropping the if
branch and simply using a delay(12000)
. Same thing happens.
And here’s the output from the CLI:
{"name":"temp","data":"2648","ttl":"60","published_at":"2016-03-09T07:40:42.293Z","coreid":"XXX"}
{"name":"temp","data":"2656","ttl":"60","published_at":"2016-03-09T07:40:58.057Z","coreid":"XXX"}
{"name":"temp","data":"2656","ttl":"60","published_at":"2016-03-09T07:41:13.825Z","coreid":"XXX"}
{"name":"temp","data":"2656","ttl":"60","published_at":"2016-03-09T07:41:29.588Z","coreid":"XXX"}
{"name":"temp","data":"2648","ttl":"60","published_at":"2016-03-09T07:41:45.355Z","coreid":"XXX"}
{"name":"temp","data":"2656","ttl":"60","published_at":"2016-03-09T07:42:01.122Z","coreid":"XXX"}
Any thoughts? Could my firmware be crashing every few seconds?