Hi,
I’ve been struggling with getting my new electron to update a “Particle.variable()”, first time trying this so I know I’m doing something wrong.
here’s the code:
// This #include statement was automatically added by the Particle IDE.
#include "SHT1x.h"
// Specify data and clock connections and instantiate SHT1x object
#define dataPin D0
#define clockPin D1
SHT1x sht1x(dataPin, clockPin);
FuelGauge fuel;
//CellularData data;
String sensorData = "";
long sleepTime = 900; // 15 mins
retained float lastTempC;
retained float lastHumidity;
void setup()
{
// Time setup for serial print
Time.zone(10.00);
Time.setFormat(TIME_FORMAT_ISO8601_FULL);
//Serial.begin(115200); // Open serial connection to report values to host
//Serial.println(Time.timeStr() + " - Starting up...");
//Serial.printlnf(Time.timeStr() + " - System version: %s", System.version().c_str());
if(Particle.variable("data", sensorData) == false)
{
//Serial.printlnf("Failed to register 'data' with Particle...");
}
}
void loop()
{
float _tempC;
float _humidity;
// Read cell data
//Cellular.getDataUsage(data);
// Read values from the sensor
_tempC= sht1x.readTemperatureC();
_humidity = sht1x.readHumidity();
// Print the values to the serial port
//Serial.printlnf("Temperature: %.4f°C, Humidity: %.4f%%, Battery: %.4fVDC, Charge: %.2f%%", _tempC, _humidity, fuel.getVCell(), fuel.getSoC());
//Serial.printlnf("Reading Good: %d, CID: %d, Session Tx: %d, Rx: %d, Total Tx: %d, Rx: %d", data.ok, data.cid, data.tx_session, data.rx_session, data.tx_total, data.rx_total);
if (abs(_tempC - lastTempC) > 0.2 || abs(_humidity - lastHumidity) > 0.5)
{
//Particle.publish("D", String::format("%.2f,%.2f,%.2f,%.2f",_tempC, _humidity, fuel.getVCell(), fuel.getSoC()), PRIVATE, NO_ACK );
sensorData = String::format("%.2f,%.2f,%.2f,%.2f", _tempC, _humidity, fuel.getVCell(), fuel.getSoC());
//Serial.printlnf(Time.timeStr() + " - " + sensorData);
//Particle.variable("data", sensorData);
lastTempC = _tempC;
lastHumidity = _humidity;
}
//delay(60000);
System.sleep(SLEEP_MODE_DEEP, sleepTime);
}
it seems to work if I use a delay but when I use sleep I see it connect but no updates.
any help would be appreciated.