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();
}
}