I’m getting closer. I now have it sending data to Ubidots. None of the data makes sense but at least it’s sending something.
I seem to have solved it. I’ll have to keep an eye on it for a bit but so far so good. I’m sure my program is a bit clunky, but here it is for anyone that might want it:
#include <SparkFunRHT03.h>
// This #include statement was automatically added by the Particle IDE.
#include <Ubidots.h>
#ifndef TOKEN
#define TOKEN "mytokenyourswillbedifferent" // Ubidots TOKEN
#endif
Ubidots ubidots(TOKEN, UBI_TCP); // Comment this line to use another protocol.
//Ubidots ubidots(TOKEN, UBI_HTTP); // Uncomment this line to use HTTP protocol.
//Ubidots ubidots(TOKEN, UBI_UDP); // Uncomment this line to use UDP protocol
const int RHT03_DATA_PIN = D1;//provides temp & humidity inside van
RHT03 rht;//creates the RHT object
const int pinOut = A2;//provides temp under van, near macerator (critical component)
const int pinFridge = A4;//you can guess this one
int tempF = 0;//temp inside van
int humidity = 0;//humidity inside van
int tempOut = 0;//outside temp reading
int tempFridge = 0;//yeah, that one
int SoC = 0;//fuel gauge
FuelGauge fuel;
int lasttempF = 0;//I'll use these to see if we really need to upload data each time
int lasthumidity = 0;
int lasttempOut = 0;
int lasttempFridge = 0;
int lastSoC = 0;
int tempFdelta;
int humiditydelta;
int tempOutdelta;
int tempFridgedelta;
int SoCdelta;
void setup() {
//Serial.begin(115200);
//ubidots.setDebug(true); // Uncomment this line to print debug messages.
rht.begin(RHT03_DATA_PIN);//initialize the RHT sensor
}
void loop() {
int update = rht.update();//get temp and humidity readings from inside the van
int humidity = rht.humidity();
int tempF = rht.tempF();
tempF = (tempF-4);//calibration adjustment
tempOut = ((((((analogRead(pinOut) * (3.3/4095)) *1000.0) - 500)/10)*(9.0/5.0)) + 32.0);//calibrated
tempFridge = ((((((analogRead(pinFridge) * (3.3/4095)) *1000.0) - 500)/10)*(9.0/5.0)) + (32.0-6.0));
SoC = fuel.getSoC();
//Create logic so only significant readings get uploaded to cloud
tempFdelta = tempF-lasttempF;
tempFdelta = abs (tempFdelta);
if(tempFdelta>2 && tempF < 150){
//Serial.printlnf("vanTemp %d\n", tempF);
//Serial.printlnf("lasttempF %d\n", lasttempF);
//Serial.printlnf("tempFdelta %d\n", tempFdelta);
ubidots.add("t", tempF);
lasttempF = tempF;
}
humiditydelta = humidity-lasthumidity;
humiditydelta = abs (humiditydelta);
if(humiditydelta>2){
//Serial.printlnf("humidity %d\n", humidity);
ubidots.add("h", humidity);
lasthumidity = humidity;
}
tempOutdelta = tempOut-lasttempOut;
tempOutdelta = abs (tempOutdelta);
if(tempOutdelta>2 && tempOut < 150){
//Serial.printlnf("tempOut %d\n", tempOut);
ubidots.add("o", tempOut);
lasttempOut = tempOut;
}
tempFridgedelta = tempFridge-lasttempFridge;
tempFridgedelta = abs (tempFridgedelta);
if(tempFridgedelta>2 && tempFridge < 150){
//Serial.printlnf("fridge %d\n", tempFridge);
ubidots.add("f", tempFridge);
lasttempFridge = tempFridge;
}
SoCdelta = SoC-lastSoC;
SoCdelta = abs (SoCdelta);
if(SoCdelta>2){
//Serial.printlnf("SoC %d\n", SoC);
ubidots.add("b", SoC);
lastSoC = SoC;
}
bool bufferSent = false;
bufferSent = ubidots.send(); // Will send data to a device label that matches the device Id
if(bufferSent){
//Do something if values were sent properly
//Serial.println("Values sent by the device");
}
delay(1200000);//only want changed data every 20 minutes
}```
congrats!
Tip: this delay may be too much for a loop(), there are ways of doing it with millis() that do not block.
Example:
outside loop()
unsigned long tempTime = 0;
in loop()
if (millis() - tempTime > 1200000)
{
tempTime = millis();
// do your ubidots business here
}
Also, you might want to add:
SYSTEM_THREAD(ENABLED); // Sytem thread is enabled
Again, congrats!
At some point I did learn that using delays was an issue and started using millis instead. I was actually a little surprised that I had that long a delay in this program but it worked for four (4) years so I left it in.
I’ll have to look into the SYSTEM_THREAD issue when I have more time. I don’t know what that does nor where to put it. I’ll clean up the program at a later date and incorporate your suggestions.
Thanks again for the assistance and, if nothing else, the encouragement.