Hi,
I’m using an Electron to publish some sensor measures, the problem is, sometimes sends and sometimes did not send info to particle.
Does anybody knows why?
thank’s
Hi,
I’m using an Electron to publish some sensor measures, the problem is, sometimes sends and sometimes did not send info to particle.
Does anybody knows why?
thank’s
Seeing what code it’s running would definitely help.
But it mentions the last reset being because of power management. Could the battery be running low?
Like @Moors7 said, please share your code.
Are you getting the same results with the Electron plugged in through USB?
Hi,
Below you can see the code, I hope you like it
Yes the publishing fails with and without battery connected. The USB is allways on.
Thank’s for your help
Eduard`
///////////////////////////////////////////////////////////////////////////
/////////////////////////Libraries////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
#include <OneWire.h>
#include <Adafruit_DHT.h>
#include "DS18.h"
//char publishString[256];
///////////////////////////////////////////////////////////////////////////
/////////////////////////Pin definition////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
/////////////////////////Pins for Dallas Sensors/////////////////////////
DS18 sensor1(D6);
DS18 sensor2(D7);
/////////////////////////Pin for light sensor/////////////////////////
const int lightPin = A1;
/////////////////////////Pin for DHT Sensor/////////////////////////
const int DHTPIN=A0;
#define DHTTYPE DHT22 // DHT 22 (AM2302)
// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor
DHT dht(DHTPIN, DHTTYPE);
/////////////////////////Pin for UV/////////////////////////
const int UVPin = A2;
/////////////////////////Pin for Water Mark/////////////////////////
int WMPin = A3; // the cell and 10K pulldown are connected to a0
/////////////////////////Pin for Deacgon Leaf Sensor/////////////////////////
const int LeafSensor1=A4; //Leaf Sensor on Analog Pin A4
void setup() {
Time.zone(+2);
/////////////////////////Temperature Ambient Reading/////////////////////////
Serial.begin(9600);
digitalWrite(D6, HIGH);
sensor1.read();
double temp = sensor1.celsius();
digitalWrite(D6, LOW);
delay(2000);
/////////////////////////Temperature Soil Reading/////////////////////////
digitalWrite(D7, HIGH);
sensor2.read();
double tempsoil = sensor2.celsius();
digitalWrite(D7, LOW);
delay(2000);
/////////////////////////Battery level Reading/////////////////////////
FuelGauge fuel;
float batt;
batt = fuel.getVCell();
/////////////////////////Humidity Reading/////////////////////////
dht.begin();
delay(2000);
//digitalWrite(A0, HIGH);
double hum = dht.getHumidity();
delay(2000);
//digitalWrite(A0, LOW);
/////////////////////////Light Sensor Reading/////////////////////////
//digitalWrite(A1, HIGH);
delay(2000);
double light;
light=analogRead(lightPin);
/////////////////////////UV Sensor Reading/////////////////////////
//digitalWrite(A2, HIGH);
delay(2000);
double sensorValue;
long sum=0;
for(int i=0;i<1024;i++)
{
sensorValue=analogRead(UVPin);
sum=sensorValue+sum;
delay(2);
}
sum = sum >> 10;
double mV=sum*4980.0/1023.0;
float illum = ((mV/1000*307)/25);
//digitalWrite(A2, LOW);
delay(2000);
/////////////////////////Water Mark Reading/////////////////////////
double WMValue = analogRead(WMPin);
int WMValueP = map(WMValue, 767, 3420, 0, 100); //Convert to Percentage
delay(2000);
/////////////////////////Decagon Leaf Sensor Reading/////////////////////////
double leaf = analogRead(LeafSensor1);
int leafP = map(leaf, 630, 1733, 0, 100); //Convert to Percentage
delay(2000);
//////////////////////////////////////////////////////////////////////////
////////// Particle publish ///////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
String Stemp = String(temp);
String Slight= String(light);
String Stempsoil =String(tempsoil);
String Shum = String(hum);
String Sbatt = String(batt);
String Ssoil = String(WMValueP);
String Sleaf = String(leafP);
String Sleafv = String(leaf);
String Ssoilv = String(WMValue);
String SUV = String(mV);
delay(1000);
String publishString = "{\"temp\":" + Stemp + ",\"tempsoil\":" + Stempsoil + ",\"hum\":" + Shum + ",\"light\":" + Slight + ",\"batt\":" + Sbatt + ",\"groundsoil\":" + Ssoil + ",\"leaf\":" + leafP + ",\"leafv\":" + Sleafv + ",\"soilV\":" + Ssoilv + ",\"UV\":" + SUV + "}";
delay(1000);
Particle.publish("SD",publishString,60,PRIVATE);
if ((Time.hour() >= 05) && (Time.hour() <= 22) )
{
/////////////////////////Sleep for 2 minutes to save battery/////////////////////////
System.sleep(SLEEP_MODE_DEEP, 2 * 60);
}
else
/////////////////////////Sleep for 2 minutes to save battery/////////////////////////
System.sleep(SLEEP_MODE_DEEP, 3 * 60);
}
void loop() {
}
You have 20 seconds of blocking code in Setup().
That can’t help the situation.
Hi Rftop
I did not understand, so sorry!!!
thank’s for your help
HI,
The problem is the script has a failure but I don’t know where or why?
I put a publish after every reading to see where the script stops publishing…I found where, I commented these lines, but stops before…a nightmare.
Is it possible to debug the script? that’s critical to find where is the problem…I’m desperated
Thank’s
The battery always need to be plugged in, otherwise it can lose power when transmitting data, due to current peaks. That's might explain the power errors.
What improvements have you made since (the delays for example?)
Hi #Moors7
The battery has already connected and full power. See below the code, but all stops after leaf reading
There is any way to debug the process? I tryied to do the same process with serial and it works correctly.
Thank’s for you help
Eduard
void setup() {
Time.zone(+2);
/////////////////////////Temperature Ambient Reading/////////////////////////
Serial.begin(9600);
digitalWrite(D6, HIGH);
sensor1.read();
double temp = sensor1.celsius();
digitalWrite(D6, LOW);
delay(2000);
Particle.publish("temp", String(temp), 60, PRIVATE);
/////////////////////////Temperature Soil Reading/////////////////////////
digitalWrite(D7, HIGH);
sensor2.read();
double tempsoil = sensor2.celsius();
digitalWrite(D7, LOW);
delay(2000);
Particle.publish("tempsoil", String(tempsoil), 60, PRIVATE);
/////////////////////////Battery level Reading/////////////////////////
FuelGauge fuel;
float batt;
batt = fuel.getVCell();
Particle.publish("batt", String(batt), 60, PRIVATE);
/////////////////////////Humidity Reading/////////////////////////
dht.begin();
//delay(2000);
//digitalWrite(A0, HIGH);
double hum = dht.getHumidity();
//delay(2000);
//digitalWrite(A0, LOW);
Particle.publish("hum", String(hum), 60, PRIVATE);
/////////////////////////Light Sensor Reading/////////////////////////
//digitalWrite(A1, HIGH);
//delay(2000);
double light;
light = analogRead(lightPin);
Particle.publish("light", String(light), 60, PRIVATE);
/////////////////////////UV Sensor Reading/////////////////////////
//digitalWrite(A2, HIGH);
//delay(2000);
double sensorValue;
long sum = 0;
for (int i = 0; i < 1024; i++)
{
sensorValue = analogRead(UVPin);
sum = sensorValue + sum;
delay(2);
}
sum = sum >> 10;
double mV = sum * 4980.0 / 1023.0;
float illum = ((mV / 1000 * 307) / 25);
//digitalWrite(A2, LOW);
//delay(2000);
Particle.publish("uv", String(mV), 60, PRIVATE);
/////////////////////////Water Mark Reading/////////////////////////
double WMValue = analogRead(WMPin);
int WMValueP = map(WMValue, 767, 3420, 0, 100); //Convert to Percentage
//delay(2000);
Particle.publish("WMValue", String(WMValue), 60, PRIVATE);
Particle.publish("WMValueP", String(WMValueP), 60, PRIVATE);
/////////////////////////Decagon Leaf Sensor Reading/////////////////////////
double leaf = analogRead(LeafSensor1);
delay(100);
//double leafP = map(leaf, 630, 1733, 0, 100); //Convert to Percentage
//delay(2000);
Particle.publish("leaf", String(leaf), 60, PRIVATE);
//Particle.publish("leafp",String(leafP),60,PRIVATE);
//////////////////////////////////////////////////////////////////////////
////////// Particle publish ///////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
Particle.publish("SD", "11", 60, PRIVATE);
String Stemp = String(temp);
String Slight = String(light);
String Stempsoil = String(tempsoil);
String Shum = String(hum);
String Sbatt = String(batt);
String Ssoil = String(WMValueP);
//String Sleaf = String(leafP);
//String Sleafv = String(leaf);
String Ssoilv = String(WMValue);
String SUV = String(mV);
//delay(1000);
String publishString = "{\"temp\":" + Stemp + ",\"tempsoil\":" + Stempsoil + ",\"hum\":" + Shum + ",\"light\":" + Slight + ",\"batt\":" + Sbatt + ",\"groundsoil\":" + Ssoil + ",\"soilV\":" + Ssoilv + ",\"UV\":" + SUV + "}";//",\"leaf\":" + leafP ++ ",\"leafv\":" + Sleafv
//delay(1000);
Particle.publish("SD", publishString, 60, PRIVATE);
if ((Time.hour() >= 05) && (Time.hour() <= 22) )
{
/////////////////////////Sleep for 2 minutes to save battery/////////////////////////
System.sleep(SLEEP_MODE_DEEP, 2 * 60);
}
else
/////////////////////////Sleep for 2 minutes to save battery/////////////////////////
System.sleep(SLEEP_MODE_DEEP, 3 * 60);
}
void loop() {
}
a new strange thing:
sometines the info comes from the name of the machine “Electron_XXX” and sometimes comes from a long ID
I’m a newbie, but here is what I would try:
The loop() will constantly read all the sensors and update the variables.
Perform the Publish Event for publishString in an IF STATEMENT that checks for your pre-determined publish delay.
Right now you CODE “attempts” to publish way too often.
Hi Rftop
At last I think I found the problem. Particle did not accept a long Json (I don’t know why) I divided the json in two jsons, and putting 4000 delay between and now it works.
How long was your string?
https://docs.particle.io/reference/firmware/photon/#particle-publish-
I had the same issue. The Electron can go to sleep before the publish completes. It is a simple fix, just add Particle.process() after you last publish, before the sleep command. This makes it wait until the publish has finished.
Cheers,
David Barrett
This should have been taken care of with 0.6.0 (probably 0.5.3 already) on Electrons and 0.7.0 should do for WiFi devices too.
Hi DavidBarrett
I’ll try do this, thank you very much
Best
Eduard