Argon sleeping mode

Hello I did some tests to use the sleeping commands, I can't understand why,
if I activate the sleeping method (hibernate or stop) it doesn't publish on the console.
Code:

// Include Particle Device OS APIs
#include "Particle.h"
int ledPin = D7;
// Let Device OS manage the connection to the Particle Cloud
SYSTEM_MODE(AUTOMATIC);
int PressV=30;
void setup()
{
 Serial.begin(9600);
 pinMode(ledPin, OUTPUT);     // sets the pin as output
 Particle.variable("PressV",PressV);
}
void loop(){
Particle.publish("PressV",PressV);
  digitalWrite(ledPin,HIGH);
  delay(5000);
  digitalWrite(ledPin,LOW);
  delay(1000);
  
/*SystemSleepConfiguration config;
config.mode(SystemSleepMode::HIBERNATE)
      .gpio(D2, RISING);
System.sleep(config);*/
/*SystemSleepConfiguration config;
config.mode(SystemSleepMode::STOP)
      .gpio(D2, FALLING)
      .duration(30000);
System.sleep(config);*/
 }

What version of Device OS are you targeting? If 6.2.0 or later, that should work. If earlier, you should also enable

SYSTEM_THREAD(ENABLED);

Due to the way delay() works in non-threaded mode, it's possible that the publish does not complete before sleep.

The other thing that could help is adding the WAIT_CLOUD flag to make sure the publish completes before sleep:

SystemSleepConfiguration config;
config.mode(SystemSleepMode::STOP)
      .flag(SystemSleepFlag::WAIT_CLOUD)
      .duration(15min);
[quote="rickkas7, post:2, topic:69717"]

SystemSleepConfiguration config;
config.mode(SystemSleepMode::STOP)
.flag(SystemSleepFlag::WAIT_CLOUD)
.duration(15min);

[/quote]

Thanks for the suggestions, I have done the changes but nothing is published to the console using the SystemSleepConfiguration, doing a rem to these steps works. For your info I have an Argon the firmware version is 6.2.1.

Does it publish if you remove the sleep? Don't leave it that way too long since you'll use a lot of data operations publishing every 6 seconds.

You could also add:

SerialLogHandler logHandler(LOG_LEVEL_TRACE);

and monitor the output using particle serial monitor --follow to see what's going on.

Yes it will be published if I remove the suspension, unfortunately I can't do anything for a week, I'll start working on it again when I get back. Thanks

Oh, think I see what's wrong. If you are using Device OS 6.2.0 or later, or SYSTEM_THREAD(ENABLED), at least the first publish occurs before you've connected to the cloud so it fails, then you go to sleep. Try inserting before the Particle.publish call in loop():

if (!Particle.connected()) {
  return;
}