I’m beyond frustration. I started with a Photon, added an Electron. I’m attempting to make a network accessible thermometer. I have a simple prototype wired up on a breadboard, and various versions of my firmware are successfully reading reasonable temperatures and reporting over the Serial connection to a local machine. I can (mostly) get Particle.publish() to put temperature values on the dashboard.
And when I try to create a variable or a function, I get (at best) intermittent results: sometimes the function appears via IFTTT or via my iOS sample program attempting to list devices and their variables and functions. Easily 90% of the time the registered variable/function does not appear. When it DOES appear, it disappears very quickly (within minutes), and rerunning the firmware or resetting the device does not help.
// This #include statement was automatically added by the Particle IDE.
#include "Adafruit_DHT/Adafruit_DHT.h"
#define DHTPIN 5
#define DHTTYPE AM2301
#define version "v.8"
int one_second = 1000;
int one_minute = 60 * one_second;
int temperature = -1000;
double tempC = -1;
String message = "This is a message";
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.println(version);
delay(5*one_second); // allow time for setting up serial monitor
dht.begin();
bool registered = false;
registered = Particle.variable("EvansIntTemp", temperature);
reportOnRegistration(registered, "EvansIntTemp");
registered = Particle.function("EvansGetTemp", getTemperature);
reportOnRegistration(registered, "EvansGetTemp()");
Serial.println(version);
}
void reportOnRegistration(bool registered, String name) {
if (registered) {
Serial.println(name + " registered");
}
else {
Serial.println("Failed to register " + name);
}
}
int getTemperature(String command) {
temperature = dht.getTempFarenheit();
Serial.println(String(temperature) + " F == getTemperature()");
return temperature;
}
void loop() {
temperature = 0;
temperature = getTemperature("");
Serial.println(String(temperature) + " ºF");
delay(one_minute);
}
The printed versions to the Serial port are to make sure that I’ve got the latest version of the program running.
What am I doing wrong?