Particle Electron seems to stop publishing. Why?

My Particle seems to be Publishing fine for about 4 publishes then doesnt send any more is this common ??

How fast are you sending your publishes? And how many are you expecting in what time frame? Sounds like you are running into the “1/second” and “4/second burst w/ 4 second cool down” publish limits. See note 1: in the publish documentation. For a better diagnosis, post your code.

I set them to Publish at different rates …15000 ,10000,25000 etc

https://go.particle.io/shared_apps/5b40ff473d8972edeb000c3d

Your code is a bit hard to read because of the bad indentation scheme. I hope that’s a byproduct of a copy and paste operation :wink: . Regarding your publishes, you do have multiple back-to-back publishes in various parts of your code such as the Reset and Fan functions. Also, because your code blocks with numerous lengthy delays, it is possible the cloud functionality isn’t being serviced and so the cloud connection is dropping… which would prevent further publishes until the loop exits and the cloud keepalive is serviced again. Are you seeing anything other than breathing cyan on the status RGB during the loop run? If you must block for so long, then you should periodically call Particle.process() to keep the cloud connection active. This thread may have some pertinent information on the Particle.process(). From that post, you may also want to consider running with:

SYSTEM_MODE(AUTOMATIC);
SYSTEM_THREAD(ENABLED);

2 Likes

LOL …Device is in New York I’m in Mexico cant see it…I shortened the fuel guage timer as a keep alive transmitting every second to see it that will work …Yea sorry about the indentation part haven cleaned it up yet

ok this is F****D I am only sending one string every 10 seconds and it transmits 10 times and stops …I can still call the functions …

#include <Adafruit_MPL3115A2.h>
#include <MPU6050.h>
#include <I2Cdev.h>
#include <Particle.h>


//Found By using I2C SCan
#define LTCADDR1 0x69//Table 1 both LOW (7bit address)Feed
#define LTCADDR2 0x67//Table 1 both LOW (7bit address)Circuit1
#define LTCADDR3 0x6F//Table 1 both LOW (7bit address)Circuit2
#define sda D0 
#define scl D1


#define Relay1 D2 
#define Relay2 D3
#define Relay3 D4
int nDevices;
byte error, address;
//=================
Adafruit_MPL3115A2 baro = Adafruit_MPL3115A2();
//===================
MPU6050 accelgyro;

int16_t ax, ay, az;
int16_t gx, gy, gz;
int Reset1(String command);
int Fan(String command);
int Radio(String command);
#define OUTPUT_READABLE_ACCELGYRO
#define LED_PIN D7 // (Particle is D7)
int buttonState = 0;
int buttonState2 =0;
bool blinkState = false;
//====================
//Table 1 both LOW (7bit address)
byte ADCvinMSB, ADCvinLSB, curSenseMSB, curSenseLSB, AinVMSB, AinVLSB;
unsigned int ADCvin, ADCcur, AinV;
float inputVoltage1, current0p01;
float inputVoltage2,  current0p02;
float inputVoltage3, ADCvoltage, current10, current1, current0p1, current0p03;
int set_port  = 1;
int incomingByte = 0;
// Some standard ports that depend on the layout of the Marvin
long    defaultBaudRate = 57600;
int     reset_port = 5;
int     RN2483_power_port = 6; 
int     led_port = 7;

//*** Set parameters here BEGIN ---->
String  set_nwkskey = "4736606efe9a18878ce550e28f9f375c";
//mac set nwkskey 4736606efe9a18878ce550e28f9f375c
String  set_appskey = "f4023a57dc4ea394bdd62a41c8f39284";
//mac set appskey f4023a57dc4ea394bdd62a41c8f39284
String  set_devaddr = "0247531d";
//mac set devaddr 0247531d
String  set_appeui = "fedcba9876543225";
//mac set appeui fedcba9876543223
//radio set crc off
const char *message = "SolarRelay1";

void setup() {
    
Serial.begin(9600);
Serial1.begin(56000,SERIAL_8N1);

Particle.function("Solar", Reset);
Particle.function("Fan", Fan);
Particle.function("Radio", Radio);
pinMode(led_port, OUTPUT); 
pinMode(D6, OUTPUT);
pinMode(D2, OUTPUT);
pinMode(D3, OUTPUT);
pinMode(D4, OUTPUT);
pinMode(Relay1, OUTPUT);
pinMode(Relay2, OUTPUT);
pinMode(Relay3, OUTPUT);
digitalWrite(D2 ,HIGH);
digitalWrite(D3 ,HIGH);
digitalWrite(D4 ,HIGH);

Wire.begin();

accelgyro.initialize();
Serial.println("Adafruit_MPL3115A2 test!");
baro.begin();

//==============

//=======================
    	Serial.println("Scanning...");
	nDevices = 0;
	for(address = 1; address < 127; address++ )
	{
		Wire.beginTransmission(address);
		error = Wire.endTransmission();
		if (error == 0)
		{
			Serial.print("I2C device found at address 0x");
			if (address<16)
				Serial.print("0");
			Serial.print(address,HEX);
			Serial.println("  !");
			nDevices++;
		}
		else if (error==4)
		{
			Serial.print("Unknow error at address 0x");
			if (address<16)
				Serial.print("0");
			Serial.println(address,HEX);
		}
	}
	if (nDevices == 0)
		Serial.println("No I2C devices found\n");
	else
		Serial.println("done\n");
//================================


//================================


}

void loop() {
  char message[120];
  char data[120];
  char data1[256];
  size_t data_used;
  char msg[56];
  int sensorValue;
  int message1;
  int    status;
  int8_t result;
  int v = (inputVoltage1);
  int c = (current0p01);
  int t = (baro.getTemperature());
  int m1 = (ax);
  int m2 = (ay);
  int m3 = (az);
//======================
    FuelGauge fuel;
    sprintf(message, "%f" , fuel.getSoC());

//=================
  float pascals = baro.getPressure();

  Serial.print(pascals/3377); Serial.println(" Inches (Hg)");

  float tempC = baro.getTemperature();
  Serial.print(tempC); Serial.println("*C");


  delay(5500);    
//======================================


  Wire.beginTransmission(LTCADDR1);//first get Input Voltage - 80V max
  Wire.write(0x1E);
  Wire.endTransmission(false);
  Wire.requestFrom(LTCADDR1, 2, true);
  delay(1);
  ADCvinMSB = Wire.read();
  ADCvinLSB = Wire.read();
  ADCvin = ((unsigned int)(ADCvinMSB) << 4) + ((ADCvinLSB >> 4) & 0x0F);//formats into 12bit integer
  inputVoltage1 = ADCvin * 0.025; //25mV resolution

  Wire.beginTransmission(LTCADDR1);//get ADC Input 2V max
  Wire.write(0x28);
  Wire.endTransmission(false);
  Wire.requestFrom(LTCADDR1, 2, true);
  delay(1);
  AinVMSB = Wire.read();
  AinVLSB = Wire.read();
  AinV = ((unsigned int)(AinVMSB) << 4) + ((AinVLSB >> 4) & 0x0F);//12 bit format
  ADCvoltage = AinV * 0.5E-3; //500uV resolution

  Wire.beginTransmission(LTCADDR1);//get sense current
  Wire.write(0x14);
  Wire.endTransmission(false);
  Wire.requestFrom(LTCADDR1, 2, true);
  delay(1);
  curSenseMSB = Wire.read();
  curSenseLSB = Wire.read();
  ADCcur = ((unsigned int)(curSenseMSB) << 4) + ((curSenseLSB >> 4) & 0x0F);//12 bit format
  //gets voltage across, 25uV resolution, then this converts to voltage for each sense resistor
  current10 = ADCcur * (25E-3) / 10.0; //10mA max, unit is mA
  current1 = ADCcur * (25E-3) / 1.0; //100mA max, unit is mA
  current0p1 = ADCcur * (25E-3) / 0.1; //1A max, unit is mA
  current0p01 = ADCcur * (25E-6) / 0.01;//10A max, unit is A

  //Print everything out
  Serial.print("Feed__");
  Serial.print(inputVoltage1, 2);
  Serial.print("  V  ");  
  Serial.print(ADCvoltage, 4);
  Serial.print("  A  ");
  Serial.println(current0p01, 4);
  int SLR = (inputVoltage1);
  int SCR = (current0p01);

//========================

  Wire.beginTransmission(LTCADDR2);//first get Input Voltage - 80V max
  Wire.write(0x1E);
  Wire.endTransmission(false);
  Wire.requestFrom(LTCADDR2, 2, true);
  delay(1);
  ADCvinMSB = Wire.read();
  ADCvinLSB = Wire.read();
  ADCvin = ((unsigned int)(ADCvinMSB) << 4) + ((ADCvinLSB >> 4) & 0x0F);//formats into 12bit integer
  inputVoltage2 = ADCvin * 0.025; //25mV resolution

  Wire.beginTransmission(LTCADDR1);//get ADC Input 2V max
  Wire.write(0x28);
  Wire.endTransmission(false);
  Wire.requestFrom(LTCADDR2, 2, true);
  delay(1);
  AinVMSB = Wire.read();
  AinVLSB = Wire.read();
  AinV = ((unsigned int)(AinVMSB) << 4) + ((AinVLSB >> 4) & 0x0F);//12 bit format
  ADCvoltage = AinV * 0.5E-3; //500uV resolution

  Wire.beginTransmission(LTCADDR2);//get sense current
  Wire.write(0x14);
  Wire.endTransmission(false);
  Wire.requestFrom(LTCADDR1, 2, true);
  delay(1);
  curSenseMSB = Wire.read();
  curSenseLSB = Wire.read();
  ADCcur = ((unsigned int)(curSenseMSB) << 4) + ((curSenseLSB >> 4) & 0x0F);//12 bit format
  //gets voltage across, 25uV resolution, then this converts to voltage for each sense resistor
  current10 = ADCcur * (25E-3) / 10.0; //10mA max, unit is mA
  current1 = ADCcur * (25E-3) / 1.0; //100mA max, unit is mA
  current0p1 = ADCcur * (25E-3) / 0.1; //1A max, unit is mA
  current0p02 = ADCcur * (25E-6) / 0.01;//10A max, unit is A

  Serial.print("Circuit1_");
  Serial.print(inputVoltage2, 2);
  Serial.print("  V  ");
  Serial.print(ADCvoltage, 4);
  Serial.print("  A  ");
  Serial.println(current0p02, 4);
  int BL = (inputVoltage2);
  int BC = (current0p02);
  sprintf(message, "%2f" , inputVoltage2);

//========================
  Wire.beginTransmission(LTCADDR3);//first get Input Voltage - 80V max
  Wire.write(0x1E);
  Wire.endTransmission(false);
  Wire.requestFrom(LTCADDR3, 2, true);
  delay(1);
  ADCvinMSB = Wire.read();
  ADCvinLSB = Wire.read();
  ADCvin = ((unsigned int)(ADCvinMSB) << 4) + ((ADCvinLSB >> 4) & 0x0F);//formats into 12bit integer
  inputVoltage3 = ADCvin * 0.025; //25mV resolution

  Wire.beginTransmission(LTCADDR3);//get ADC Input 2V max
  Wire.write(0x28);
  Wire.endTransmission(false);
  Wire.requestFrom(LTCADDR3, 2, true);
  delay(1);
  AinVMSB = Wire.read();
  AinVLSB = Wire.read();
  AinV = ((unsigned int)(AinVMSB) << 4) + ((AinVLSB >> 4) & 0x0F);//12 bit format
  ADCvoltage = AinV * 0.5E-3; //500uV resolution

  Wire.beginTransmission(LTCADDR3);//get sense current
  Wire.write(0x14);
  Wire.endTransmission(false);
  Wire.requestFrom(LTCADDR3, 2, true);
  delay(1);
  curSenseMSB = Wire.read();
  curSenseLSB = Wire.read();
  ADCcur = ((unsigned int)(curSenseMSB) << 4) + ((curSenseLSB >> 4) & 0x0F);//12 bit format
  //gets voltage across, 25uV resolution, then this converts to voltage for each sense resistor
  current10 = ADCcur * (25E-3) / 10.0; //10mA max, unit is mA
  current1 = ADCcur * (25E-3) / 1.0; //100mA max, unit is mA
  current0p1 = ADCcur * (25E-3) / 0.1; //1A max, unit is mA
  current0p03 = ADCcur * (25E-6) / 0.01;//10A max, unit is A

  //Print everything out
  Serial.print("Circuit2_");
  Serial.print(inputVoltage3, 2);
  Serial.print("  V  ");
  Serial.print(ADCvoltage, 4);
  Serial.print("  Input_V  ");
  Serial.print(ADCvoltage, 4);
  Serial.print("  A  ");
  Serial.println(current0p03, 4);
  int RV = (inputVoltage3);
  int RC = (current0p03);

  sprintf(message, "PRTBATT %f:TEMP %f :RC %f : RV %f : BL %f : BC %f : SLR %f : SCR %f",fuel.getSoC(),tempC,current0p03 ,inputVoltage3 ,inputVoltage2 ,current0p02 ,inputVoltage1 ,current0p01);
  Particle.publish("String", message,  PRIVATE);

  delay(10000);
}

int Reset(String command) {

  if(command =="1")  {
digitalWrite(D2 ,LOW);
Particle.publish("D3_On", "1",PRIVATE);
Particle.publish("SOLAR_Relay1","1",PRIVATE);
delay(10000);

digitalWrite(D2 ,HIGH);
Particle.publish("D3_Reset", "0",PRIVATE);
Particle.publish("SOLAR_Relay1","0",PRIVATE);

}
}

int Fan(String command) {

 if(command =="2")  {
digitalWrite(D3,LOW);
Particle.publish("D2_On", "1",PRIVATE);
Particle.publish("Fan_Relay1","1",PRIVATE);

}
 else if(command =="3")  {
digitalWrite(D3 ,HIGH);
Particle.publish("D2_Reset", "0",PRIVATE);
Particle.publish("Fan_Relay1","0",PRIVATE);
}
}
int Radio(String command) {
    
 if(command =="4")  {
digitalWrite(D4 ,LOW);
Particle.publish("D1_On", "1",PRIVATE);
Particle.publish("Radio_Relay","1",PRIVATE);
delay(10000);
}
 else if(command =="5")  {
digitalWrite(D4 ,HIGH);
Particle.publish("D1_Reset", "0",PRIVATE);
Particle.publish("Radio_Relay","0",PRIVATE);
}
return 1 ;

}
1 Like

It looks like your code basically does this:

void loop() {
  // define a bunch of variables each loop (why?)
  // Serial Prints
  delay(5500);
  
  // Read I2C sensors
  // Serial Prints
  // Read more I2C sensors
  // More serial Prints

  // sprintf & Publish  [this is normally snprintf (sNprintf)]
  delay(10000);
}

} // end Loop()

As @ninjatill already suggested, you can use SYSTEM_THREAD(ENABLED);
Remove the delays in loop(), you could also use millis() to decide when to take the readings verses hard delays each loop() pass.
Use snprintf verses sprintf for the Publish?

Those may not solve your problem, but are general recommendations that we see on this forum.

Ok I’ll give it a shot

Something like this should get you started :

SYSTEM_THREAD(ENABLED);
// Global
const long interval = 30000;        // interval at which to Read Sensors ( in milliseconds)
unsigned long previousMillis =  0;  // Stores the time of last reading

void loop() {
  if (millis() - previousMillis >= (interval )) {  // enough time has passed so read the sensors
    // Your previous code from loop() goes here
    previousMillis = millis();  // Update the time for the last sensor reading
  }
} // End Loop



OK so this is what I have now …I can’t use snprintf …something to do with my float temperature


#include <Adafruit_MPL3115A2.h>
#include <MPU6050.h>
#include <I2Cdev.h>
#include <Particle.h>
//Found By using I2C SCan
#define LTCADDR1 0x69//Table 1 both LOW (7bit address)Feed
#define LTCADDR2 0x67//Table 1 both LOW (7bit address)Circuit1
#define LTCADDR3 0x6F//Table 1 both LOW (7bit address)Circuit2
#define sda D0 
#define scl D1
#define Relay1 D2 
#define Relay2 D3
#define Relay3 D4
int nDevices;
byte error, address;
//=================
Adafruit_MPL3115A2 baro = Adafruit_MPL3115A2();
//===================
MPU6050 accelgyro;

int16_t ax, ay, az;
int16_t gx, gy, gz;
int Reset1(String command);
int Fan(String command);
int Radio(String command);
#define OUTPUT_READABLE_ACCELGYRO
#define LED_PIN D7 // (Particle is D7)
int buttonState = 0;
int buttonState2 =0;
bool blinkState = false;
//====================
//Table 1 both LOW (7bit address)
byte ADCvinMSB, ADCvinLSB, curSenseMSB, curSenseLSB, AinVMSB, AinVLSB;
unsigned int ADCvin, ADCcur, AinV;
float inputVoltage1, current0p01;
float inputVoltage2,  current0p02;
float inputVoltage3, ADCvoltage, current10, current1, current0p1, current0p03;
int set_port  = 1;
int incomingByte = 0;
// Some standard ports that depend on the layout of the Marvin
long    defaultBaudRate = 57600;
int     reset_port = 5;
int     RN2483_power_port = 6; 
int     led_port = 7;

//*** Set parameters here BEGIN ---->
String  set_nwkskey = "4736606efe9a18878ce550e28f9f375c";
//mac set nwkskey 4736606efe9a18878ce550e28f9f375c
String  set_appskey = "f4023a57dc4ea394bdd62a41c8f39284";
//mac set appskey f4023a57dc4ea394bdd62a41c8f39284
String  set_devaddr = "0247531d";
//mac set devaddr 0247531d
String  set_appeui = "fedcba9876543225";
//mac set appeui fedcba9876543223
//radio set crc off
const char *message = "SolarRelay1";
//========================================
SYSTEM_THREAD(ENABLED);
// Global
const long interval = 30000;        // interval at which to Read Sensors ( in milliseconds)
unsigned long previousMillis =  0;  // Stores the time of last reading
//=======================================

void setup() {
 
Serial.begin(9600);
Serial1.begin(56000,SERIAL_8N1);

Particle.function("Solar", Reset);
Particle.function("Fan", Fan);
Particle.function("Radio", Radio);
pinMode(D6, OUTPUT);
pinMode(D2, OUTPUT);
pinMode(D3, OUTPUT);
pinMode(D4, OUTPUT);
digitalWrite(D2 ,HIGH);
digitalWrite(D3 ,HIGH);
digitalWrite(D4 ,HIGH);

Wire.begin();

accelgyro.initialize();
Serial.println("Adafruit_MPL3115A2 test!");
baro.begin();

    	Serial.println("Scanning...");
	nDevices = 0;
	for(address = 1; address < 127; address++ )
	{
		Wire.beginTransmission(address);
		error = Wire.endTransmission();
		if (error == 0)
		{
			Serial.print("I2C device found at address 0x");
			if (address<16)
				Serial.print("0");
			Serial.print(address,HEX);
			Serial.println("  !");
			nDevices++;
		}
		else if (error==4)
		{
			Serial.print("Unknow error at address 0x");
			if (address<16)
				Serial.print("0");
			Serial.println(address,HEX);
		}
	}
	if (nDevices == 0)
		Serial.println("No I2C devices found\n");
	else
		Serial.println("done\n");
//================================

}

void loop() {
    if (millis() - previousMillis >= (interval )) {  // enough time has passed so read the sensors   
  char message[120];
  char data1[256];
  size_t data_used;
  int sensorValue;
  int    status;
  int8_t result;
 // int Temp
//======================
    FuelGauge fuel;
    sprintf(message, "%f" , fuel.getSoC());
//======================
  float pascals = baro.getPressure();


  float tempC = baro.getTemperature();


//======================================

  Wire.beginTransmission(LTCADDR1);//first get Input Voltage - 80V max
  Wire.write(0x1E);
  Wire.endTransmission(false);
  Wire.requestFrom(LTCADDR1, 2, true);
  delay(1);
  ADCvinMSB = Wire.read();
  ADCvinLSB = Wire.read();
  ADCvin = ((unsigned int)(ADCvinMSB) << 4) + ((ADCvinLSB >> 4) & 0x0F);//formats into 12bit integer
  inputVoltage1 = ADCvin * 0.025; //25mV resolution

  Wire.beginTransmission(LTCADDR1);//get ADC Input 2V max
  Wire.write(0x28);
  Wire.endTransmission(false);
  Wire.requestFrom(LTCADDR1, 2, true);
  delay(1);
  AinVMSB = Wire.read();
  AinVLSB = Wire.read();
  AinV = ((unsigned int)(AinVMSB) << 4) + ((AinVLSB >> 4) & 0x0F);//12 bit format
  ADCvoltage = AinV * 0.5E-3; //500uV resolution

  Wire.beginTransmission(LTCADDR1);//get sense current
  Wire.write(0x14);
  Wire.endTransmission(false);
  Wire.requestFrom(LTCADDR1, 2, true);
  delay(1);
  curSenseMSB = Wire.read();
  curSenseLSB = Wire.read();
  ADCcur = ((unsigned int)(curSenseMSB) << 4) + ((curSenseLSB >> 4) & 0x0F);//12 bit format
  //gets voltage across, 25uV resolution, then this converts to voltage for each sense resistor
  current10 = ADCcur * (25E-3) / 10.0; //10mA max, unit is mA
  current1 = ADCcur * (25E-3) / 1.0; //100mA max, unit is mA
  current0p1 = ADCcur * (25E-3) / 0.1; //1A max, unit is mA
  current0p01 = ADCcur * (25E-6) / 0.01;//10A max, unit is A


  int SLR = (inputVoltage1);
  int SCR = (current0p01);

//========================

  Wire.beginTransmission(LTCADDR2);//first get Input Voltage - 80V max
  Wire.write(0x1E);
  Wire.endTransmission(false);
  Wire.requestFrom(LTCADDR2, 2, true);
  delay(1);
  ADCvinMSB = Wire.read();
  ADCvinLSB = Wire.read();
  ADCvin = ((unsigned int)(ADCvinMSB) << 4) + ((ADCvinLSB >> 4) & 0x0F);//formats into 12bit integer
  inputVoltage2 = ADCvin * 0.025; //25mV resolution

  Wire.beginTransmission(LTCADDR1);//get ADC Input 2V max
  Wire.write(0x28);
  Wire.endTransmission(false);
  Wire.requestFrom(LTCADDR2, 2, true);
  delay(1);
  AinVMSB = Wire.read();
  AinVLSB = Wire.read();
  AinV = ((unsigned int)(AinVMSB) << 4) + ((AinVLSB >> 4) & 0x0F);//12 bit format
  ADCvoltage = AinV * 0.5E-3; //500uV resolution

  Wire.beginTransmission(LTCADDR2);//get sense current
  Wire.write(0x14);
  Wire.endTransmission(false);
  Wire.requestFrom(LTCADDR1, 2, true);
  delay(1);
  curSenseMSB = Wire.read();
  curSenseLSB = Wire.read();
  ADCcur = ((unsigned int)(curSenseMSB) << 4) + ((curSenseLSB >> 4) & 0x0F);//12 bit format
  //gets voltage across, 25uV resolution, then this converts to voltage for each sense resistor
  current10 = ADCcur * (25E-3) / 10.0; //10mA max, unit is mA
  current1 = ADCcur * (25E-3) / 1.0; //100mA max, unit is mA
  current0p1 = ADCcur * (25E-3) / 0.1; //1A max, unit is mA
  current0p02 = ADCcur * (25E-6) / 0.01;//10A max, unit is A


  int BL = (inputVoltage2);
  int BC = (current0p02);

//========================
  Wire.beginTransmission(LTCADDR3);//first get Input Voltage - 80V max
  Wire.write(0x1E);
  Wire.endTransmission(false);
  Wire.requestFrom(LTCADDR3, 2, true);
  delay(1);
  ADCvinMSB = Wire.read();
  ADCvinLSB = Wire.read();
  ADCvin = ((unsigned int)(ADCvinMSB) << 4) + ((ADCvinLSB >> 4) & 0x0F);//formats into 12bit integer
  inputVoltage3 = ADCvin * 0.025; //25mV resolution

  Wire.beginTransmission(LTCADDR3);//get ADC Input 2V max
  Wire.write(0x28);
  Wire.endTransmission(false);
  Wire.requestFrom(LTCADDR3, 2, true);
  delay(1);
  AinVMSB = Wire.read();
  AinVLSB = Wire.read();
  AinV = ((unsigned int)(AinVMSB) << 4) + ((AinVLSB >> 4) & 0x0F);//12 bit format
  ADCvoltage = AinV * 0.5E-3; //500uV resolution

  Wire.beginTransmission(LTCADDR3);//get sense current
  Wire.write(0x14);
  Wire.endTransmission(false);
  Wire.requestFrom(LTCADDR3, 2, true);
  delay(1);
  curSenseMSB = Wire.read();
  curSenseLSB = Wire.read();
  ADCcur = ((unsigned int)(curSenseMSB) << 4) + ((curSenseLSB >> 4) & 0x0F);//12 bit format
  //gets voltage across, 25uV resolution, then this converts to voltage for each sense resistor
  current10 = ADCcur * (25E-3) / 10.0; //10mA max, unit is mA
  current1 = ADCcur * (25E-3) / 1.0; //100mA max, unit is mA
  current0p1 = ADCcur * (25E-3) / 0.1; //1A max, unit is mA
  current0p03 = ADCcur * (25E-6) / 0.01;//10A max, unit is A


  int RV = (inputVoltage3);
  int RC = (current0p03);

  sprintf(message, "PRTBATT %f :TEMP %f :RC %f : RV %f : BL %f : BC %f : SLR %f : SCR %f",fuel.getSoC(),tempC,current0p03 ,inputVoltage3 ,inputVoltage2 ,current0p02 ,inputVoltage1 ,current0p01);
  Particle.publish("String", message,  PRIVATE);
  
    previousMillis = millis();  // Update the time for the last sensor reading
  }
} // End Loop
int Reset(String command) {

  if(command =="1")  {
digitalWrite(D2 ,LOW);
Particle.publish("D3_On", "1",PRIVATE);

delay(10000);

digitalWrite(D2 ,HIGH);
Particle.publish("D3_Reset", "0",PRIVATE);


}
}

int Fan(String command) {

 if(command =="2")  {
digitalWrite(D3,LOW);
Particle.publish("D3_On", "1",PRIVATE);


}
 else if(command =="3")  {
digitalWrite(D3 ,HIGH);
Particle.publish("D3_Off", "1",PRIVATE);
}
}
int Radio(String command) {
    
 if(command =="4")  {
digitalWrite(D4 ,LOW);
Particle.publish("D1_On", "1",PRIVATE);
Particle.publish("Radio_Relay","1",PRIVATE);
delay(10000);
}
 else if(command =="5")  {
digitalWrite(D4 ,HIGH);
Particle.publish("D1_Reset", "0",PRIVATE);
Particle.publish("Radio_Relay","0",PRIVATE);
}
return 1 ;

}

Now to see if it stop transmitting after 10 or 15 Publishes

Got about 45 publishes in and it stopped

Think the particle went off line for a second …Cant ping it

In my limited experience, my crashes were usually caused by Div/0.
You can try to add some safeguards to prevent this before your calculations.

Are you sure you have enough time between different sensor readings for the I2C bus to “settle down” ?
Sometimes you may not actually be receiving a reading which “might” cause Div/0 or other problems.

It’s going to be hard to troubleshoot while testing a remote device since you cant see the SOS code.

I could try Delays before readings

But it seems to read ok

Just gonna let it settle in for a little bit

Why would that be?
snprintf() works fine with floats and doubles.
But I'd rather use "%.2f" to limit the decimal places to two.

And this is rather poor style

const char *message = "SolarRelay1";
...
void loop() {
    if (millis() - previousMillis >= (interval )) {  // enough time has passed so read the sensors   
  char message[120];
  ...
  sprintf(message, "PRTBATT %f :TEMP %f :RC %f : RV %f : BL %f : BC %f : SLR %f : SCR %f",fuel.getSoC(),tempC,current0p03 ,inputVoltage3 ,inputVoltage2 ,current0p02 ,inputVoltage1 ,current0p01);
  Particle.publish("String", message,  PRIVATE);
  
    previousMillis = millis();  // Update the time for the last sensor reading
  }
} // End Loop

It's rather confusing when you redefine different variables with the same names.
Also since you are not limiting your decimal places for "%f" your 120 bytes may be too short (I'd assume floats with 10 char minimum).
That's exactly why you should be using snprintf(), otherwise you may corrupt the stack and hence see unexpected behaviour.

  snprintf(message, sizeof(message), "PRTBATT %f :TEMP %f :RC %f : RV %f : BL %f : BC %f : SLR %f : SCR %f",fuel.getSoC(),tempC,current0p03 ,inputVoltage3 ,inputVoltage2 ,current0p02 ,inputVoltage1 ,current0p01);

And looking at operations like these

  current10 = ADCcur * (25E-3) / 10.0; //10mA max, unit is mA
  current1 = ADCcur * (25E-3) / 1.0; //100mA max, unit is mA
  current0p1 = ADCcur * (25E-3) / 0.1; //1A max, unit is mA
  current0p02 = ADCcur * (25E-6) / 0.01;//10A max, unit is A

I'd suggest you go for double instead of float and also avoid the divisions, but substitute them for multiplications. (x / 0.01 should better be x * 100)

3 Likes