No LoRa transmission on Vs power (Solar powered device)

Hi, I’m built a simple device for water consumption monitoring. Every 1 liter a reed switch fires an interrupt and a Lora message has sent. On usb power it work fine, but if i connect a 6V power supply on Vs pin to simulate a solar panel there is no more LoRa Transmission. I tested this behavior on two different board.
Also power consumption is disappointing in deep sleep 9mA! (No serial, no external device; Vex off).
Any idea?
Down below the code:
#include “Arduino.h”

#include “LoRa_APP.h”

#include “LoRaWan_APP.h”

#define INT_GPIO USER_KEY

=========================================================================

definizioni per trasmissione Lora

=========================================================================

*/

#ifndef LoraWan_RGB

#define LoraWan_RGB 0

#endif

#define RF_FREQUENCY 868000000 // Hz

#define TX_OUTPUT_POWER 23 // dBm

#define LORA_BANDWIDTH 0 // [0: 125 kHz,

                                                          //  1: 250 kHz,

                                                          //  2: 500 kHz,

                                                          //  3: Reserved]

#define LORA_SPREADING_FACTOR 7 // [SF7…SF12]

#define LORA_CODINGRATE 1 // [1: 4/5,

                                                          //  2: 4/6,

                                                          //  3: 4/7,

                                                          //  4: 4/8]

#define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx

#define LORA_SYMBOL_TIMEOUT 0 // Symbols

#define LORA_FIX_LENGTH_PAYLOAD_ON false

#define LORA_IQ_INVERSION_ON false

#define RX_TIMEOUT_VALUE 1000

#define BUFFER_SIZE 100 //34 Define the payload size here

char txpacket[BUFFER_SIZE];

char rxpacket[BUFFER_SIZE];

static RadioEvents_t RadioEvents;

void OnTxDone( void );

void OnTxTimeout( void );

void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr );

String String_to_send;

String msg_received;

int imax, i;

int last_msg =0;

typedef enum

{

LOWPOWER,

RX,

TX

}States_t;

int16_t txNumber;

States_t state;

bool sleepMode = false;

int16_t Rssi,rxSize;

bool inviare_lettura_1l = false;

int tempo_acqua_chiusa = 0.3;

int ultimo_dato;

int hold_time = 4000; //tempo di attesa in ms tra una lettura e l’altra per evitare doppie letture

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

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

#define REED_PIN USER_KEY //REED switch on user button pin

uint8_t lowpower=1;

void onSleep()

{

//Serial.printf(“Going into lowpower mode. Press user key to wake up\r\n”);

delay(5);

lowpower=1;

}

void onWakeUp()

{

detachInterrupt(REED_PIN);

delay(10);

inviare_lettura_1l = true; // Flag for LoRa msg send

//Serial.println(“un litro”);

attachInterrupt(INT_GPIO,onWakeUp,FALLING);

}

void setup() {

lowpower=0;

// put your setup code here, to run once:

//Serial.begin(115200);

pinMode(INT_GPIO,INPUT);

attachInterrupt(INT_GPIO,onWakeUp,FALLING);

//TimerInit( &sleep, onSleep );

//Serial.printf(“Going into lowpower mode. Press user key to wake up\r\n”);

delay(5);

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

txNumber=0;

Rssi=0;

//RadioEvents.TxDone = OnTxDone;

// RadioEvents.TxTimeout = OnTxTimeout;

// RadioEvents.RxDone = OnRxDone;

Radio.Init( &RadioEvents );

Radio.SetChannel( RF_FREQUENCY );

Radio.SetSyncWord(0x12);

Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH,

                               LORA_SPREADING_FACTOR, LORA_CODINGRATE,

                               LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON,

                               true, 0, 0, LORA_IQ_INVERSION_ON, 3000 );

Radio.SetRxConfig( MODEM_LORA, LORA_BANDWIDTH, LORA_SPREADING_FACTOR,

                               LORA_CODINGRATE, 0, LORA_PREAMBLE_LENGTH,

                               LORA_SYMBOL_TIMEOUT, LORA_FIX_LENGTH_PAYLOAD_ON,

                               0, true, 0, 0, LORA_IQ_INVERSION_ON, true );

state=TX;

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

}

void loop() {

attachInterrupt(INT_GPIO,onWakeUp,FALLING);

if ((millis() - ultimo_dato) > (tempo_acqua_chiusa * 60 * 1000))

{

//Serial.println("L'acqua è stata chiusa");

lowpower=1; // Going to sleep

}

if (inviare_lettura_1l)

  {

    ultimo_dato = millis();

   // Serial.println("invio lettura contatore acqua");

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

String_to_send=“consumo:2:reed:1:V:”+String(getBatteryVoltage())+":"; //Stringa per test su lowpower

//String_to_send=“contatore_acqua:2:reed:1:V:”+String(getBatteryVoltage())+":"; stribga corretta per contatore

    imax = String_to_send.length();

    //Serial.println(imax);

    for (i = 0; i < imax; i++)

    {

      txpacket[i] = String_to_send[i];

      //Serial.print(txpacket[i]);

    }

    //Serial.printf("\r\nsending packet \"%s\" , length %d\r\n",txpacket, strlen(txpacket));

    Radio.Send( (uint8_t *)txpacket, strlen(txpacket) );

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

    inviare_lettura_1l = false;

    delay(hold_time);// Lasciare per evitare false letture contatore acqua

}

if(lowpower){

digitalWrite(Vext, HIGH);//#####################

Radio.Sleep( );

lowPowerHandler();

}
}

I have been using CubeCells in applications with solar panels for a while now, so a couple of comments…

First, are you using a battery as well as your solar panel? I don’t believe that the module will run on just a solar panel (input on Vs).

Second, the sketch you have provided doesn’t appear to use the ‘state machine’ the way the examples I have seen do, so I wonder if your CubeCell is really going to sleep.

Here are the essential parts of the code I am running. Maybe you can get some idea about what might be happening from this.

static RadioEvents_t RadioEvents;
void OnTxDone( void );
void OnTxTimeout( void );

// LowPower stuff
// const int reportInterval = 60000;   // Report values every 60000 milliseconds (60 seconds)

#define wakeTime 1000
#define sleepTime 60000
static TimerEvent_t sleep;
static TimerEvent_t wakeUp;

typedef enum
{
    LOWPOWER,
    TX
} States_t;

States_t state;

int16_t rssi,rxSize;

void onSleep()
{
  Serial.printf("[onSleep] Go into LowPower mode for %d ms\r\n",sleepTime);
  state = LOWPOWER;
  digitalWrite(Vext, HIGH);               // Turn the external power off before sleeping
  TimerSetValue( &wakeUp, sleepTime );
  TimerStart( &wakeUp );
}

void onWake()
{
  Serial.println(); 
  Serial.printf("[onWake] Wake for %d ms, then go back into LowPower mode.\r\n",wakeTime);
  state = TX;
  TimerSetValue( &sleep, wakeTime );
  TimerStart( &sleep );
}

void setup() {
  boardInitMcu( );
  Serial.begin(115200);
  delay(200);                         //Let things settle down..
  
  RadioEvents.TxDone = OnTxDone;
  RadioEvents.TxTimeout = OnTxTimeout;

  Radio.Init( &RadioEvents );
  Radio.SetChannel( RF_FREQUENCY );
  Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH,
                                 LORA_SPREADING_FACTOR, LORA_CODINGRATE,
                                 LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON,
                                 true, 0, 0, LORA_IQ_INVERSION_ON, 3000 );

  Radio.Sleep( );
    
  Serial.println("[setup] LoRa initialisation complete");
  
  TimerInit( &sleep, onSleep );
  TimerInit( &wakeUp, onWake );
  onWake();

  Serial.println("[setup] Set-up Complete");
  Serial.println(); 
}

void loop()
{
 // Serial.println("[loop] Enter Loop");
	switch(state)
	{
		case TX:
    {

[do stuff in here]      
 
      state=LOWPOWER;
	    break;
    }
		case LOWPOWER:
    {
      lowPowerHandler();
      break;
    }
    default:
        break;
	}
//    Radio.IrqProcess( );
}

void OnTxDone( void )
{
  Serial.println("[OnTxDone] TX done!");
  Radio.Sleep( );
}

void OnTxTimeout( void )
{
  Serial.println("[OnTxTimeout] TX Timeout...");
  Radio.Sleep( );
}

Thanks for your help. Yes I have a battery connected in solar mode.
When you speak of “state machine” are you referring to the state variable (States_t type)?
In your example it is used in the switch sentence, and in case of LOWPOWER it calls the lowPowerHandler() function, I’m wrong? The lowPowerHandler() function is the equivalent of esp_deep_sleep_start() I use with ESP32 board? In my my sketch this function is called at the end of transmission. It seems comparable to your example.

Sorry, I did’t see your question until now… As far as the state machine goes, yes, the States_t type is set to determine the path through the loop and, yes, when LOWPOWER state is set the sketch calls the lowPowerHandler() function. And yes, the lowPowerHandler() function is, more or less, equivalent to the ESP32 deep sleep function, but in the two cases, ESP32 and CubeCell, there are slightly different considerations that need to be taken into account.

The fact that you are seeing 9mA in deep sleep suggests to me that the CubeCell is not actually entering deep sleep. There were a couple of things I had to do to get my sketches working the way they should and I can’t remember the exact sequence. But the order in which things are done in the leadup to entering low power mode is important. My recollection is that if there is anything going on in the background when the low power handler is called, it may not activate correctly—it cycles something like six times before actually going to sleep. I don’t know exactly why, but it seemed that if it gets interrupted during that process, i.e. if tasks in the lead up to calling the low power handler are not exectued in the correct sequence, it doesn’t seem to enter deep sleep. I don’t recall if it was the actual sequence or simply one task that needed to be completed before calling the low power handler, but whatever the requirement ended up being, it is implicit in the code fragment I posted above.

My complete sketches and a description of their applications, are available via this link (that links to just one of the applications, but you can see the others from there). That link is just to my project notes, so it’s not a tutorial or anything like that, just notes on various aspects of the projects that I thought might be relevant. There are some notes in the Software section relating to the CubeCell, but I think I covered those in my original reply.