LPP WiMod error

Dear All,

I have connected a WiMod LoRa module to Actility and trying to connect it to Cayenne dashboard through LPP.
When I run the script I get the following error :

CayenneLPP::~CayenneLPP(void) {

^

C:\Users\Spiros\Documents\Arduino\libraries\CayenneLPP-master\src\CayenneLPP.cpp:15:1: note: code may be misoptimized unless -fno-strict-aliasing is used

collect2.exe: error: ld returned 1 exit status

Any ideas please? The code is attached in a text file

Has anyone come acroos this error please?

Please find the code below:

#include <CayenneLPP.h>
#include <WiMODLoRaWAN.h>
#if defined(ARDUINO_ARCH_AVR)
#include <avr/pgmspace.h>
#endif



// Set your AppEUI and AppKey
const char *appEui = "";
const char *appKey = ")";

#define loraSerial Serial1
#define debugSerial Serial

// Replace REPLACE_ME with TTN_FP_EU868 or TTN_FP_US915
//#define freqPlan REPLACE_ME

//TheThingsNetwork ttn(loraSerial, debugSerial, freqPlan);
//CayenneLPP lpp(51);

//-----------------------------------------------------------------------------
// platform defines
//-----------------------------------------------------------------------------
/*
* Note: This sketch is for Arduino devices with two separate serial interfaces
* (e.g. DUE). One interface is connected to a PC and one is used for WiMOD.
*
* For single serial interface boards (e.g. UNO) it is recommended to disbale
* the PC / Debug messages
*/

#define WIMOD_IF    Serial3         // for WiMODino use: SerialWiMOD
#define PC_IF    Serial          // for WiMODino use: SerialUSB

//-----------------------------------------------------------------------------
// constant values
//-----------------------------------------------------------------------------

/*
* OTAA Parameters
*/

// application  key (64bit)
const unsigned char APPEUI[] = {  };

// application  key (128bit)
const unsigned char APPKEY[] = {  };



int txdata = 30;


//-----------------------------------------------------------------------------
// user defined types
//-----------------------------------------------------------------------------

typedef enum TModemState
{
    ModemState_Disconnected = 0,
    ModemState_ConnectRequestSent,
    ModemState_Connected,
    ModemState_FailedToConnect,
} TModemState;


typedef struct TRuntimeInfo
{
    TModemState ModemState;
} TRuntimeInfo;


//-----------------------------------------------------------------------------
// section RAM
//-----------------------------------------------------------------------------

/*
* Create in instance of the interface to the WiMOD-LR-Base firmware
*/
WiMODLoRaWAN wimod(WIMOD_IF);  // use the Arduino Serial3 as serial interface

TRuntimeInfo RIB = {  };

static uint32_t loopCnt = 0;
static TWiMODLORAWAN_TX_Data txData;



//-----------------------------------------------------------------------------
// section code
//-----------------------------------------------------------------------------

/*****************************************************************************
* Function for printing out some debug infos via serial interface
****************************************************************************/
void debugMsg(String msg)
{
    PC_IF.print(msg);  // use default Arduino serial interface
}

void debugMsg(int a)
{
  PC_IF.print(a, DEC);
}

void debugMsgChar(char c)
{
  PC_IF.print(c);
}

void debugMsgHex(int a)
{
    if (a < 0x10) {
        PC_IF.print(F("0"));
    }
    PC_IF.print(a, HEX);
}


/*****************************************************************************
* join tx indication callback
****************************************************************************/

void onJoinTx(TWiMODLR_HCIMessage& rxMsg) {
    TWiMODLORAWAN_TxIndData txData = {};
    wimod.convert(rxMsg, &txData);

    debugMsg(F("joining attempt: "));
    if (txData.FieldAvailability == LORAWAN_OPT_TX_IND_INFOS_INCL_PKT_CNT) {
        debugMsg((int) txData.NumTxPackets);
    }
    debugMsg(F("\n"));
}

/*****************************************************************************
* joined network indication
****************************************************************************/

void onJoinedNwk(TWiMODLR_HCIMessage& rxMsg) {
    TWiMODLORAWAN_RX_JoinedNwkData joinedData;

    debugMsg(F("Join-Indication received.\n"));

    if (wimod.convert(rxMsg, &joinedData)) {
        if ((LORAWAN_JOIN_NWK_IND_FORMAT_STATUS_JOIN_OK == joinedData.StatusFormat)
                || (LORAWAN_JOIN_NWK_IND_FORMAT_STATUS_JOIN_OK_CH_INFO == joinedData.StatusFormat)){
            //Ok device is now joined to nwk (server)
            RIB.ModemState = ModemState_Connected;

            debugMsg(F("Device has joined a network.\n"));
            debugMsg(F("New Device address is: "));
            debugMsg((int) joinedData.DeviceAddress);
            debugMsg(F("\n"));
        } else {
            // error joining procedure did not succeed
            RIB.ModemState = ModemState_FailedToConnect;

            debugMsg(F("Failed to join a network.\n"));
        }
    }
}

/*****************************************************************************
* rx data callback
****************************************************************************/
void onRxData(TWiMODLR_HCIMessage& rxMsg) {
    TWiMODLORAWAN_RX_Data radioRxMsg;
    int i;

    debugMsg("Rx-Data Indication received.\n");

    // convert/copy the raw message to RX radio buffer
    if (wimod.convert(rxMsg, &radioRxMsg)) {

    if (radioRxMsg.StatusFormat & LORAWAN_FORMAT_ACK_RECEIVED) {
      // yes, this is an ack
      debugMsg(F("Ack-Packet received."));
    }
        // print out the received message as hex string
        if (radioRxMsg.Length > 0) {
            // print out the length
            debugMsg(F("Rx-Message: ["));
            debugMsg(radioRxMsg.Length);
            debugMsg(F("]: "));

            // print out the payload
            for (i = 0; i < radioRxMsg.Length; i++) {
                debugMsgHex(radioRxMsg.Payload[i]);
                debugMsg(F(" "));
            }
            debugMsg(F("\n"));
        } else {
            // no payload included
//            debugMsg(F("Rx-Message with no Payload received; Status: "));
//      debugMsg((int) radioRxMsg.StatusFormat);
          debugMsg(F("\n"));
        }
    }
}

/*****************************************************************************
* print out a welcome message
****************************************************************************/
void printStartMsg()
{
    debugMsg(F("==================================================\n"));
    debugMsg(F("This is FileName: "));
    debugMsg(F(__FILE__));
    debugMsg(F("\r\n"));
    debugMsg(F("Starting...\n"));
    debugMsg(F("This simple demo will try to "));
    debugMsg(F("do the OTAA procedure and "));
    debugMsg(F("send a demo message each 30 sec.\n"));
    debugMsg(F("==================================================\n"));
}



/*****************************************************************************
* Arduino setup function
****************************************************************************/
void setup()
{
                  loraSerial.begin(57600);
                  debugSerial.begin(9600);

                  DynamicJsonDocument jsonBuffer(4096);
  CayenneLPP lpp(160);

  JsonArray root = jsonBuffer.to<JsonArray>();

  Serial.begin(115200);
  Serial.println();
  
    // wait for the PC interface to be ready (max 10 sec); usefull for USB
    while (!PC_IF && millis() < 10000 ){}

    // init / setup the serial interface connected to WiMOD
    WIMOD_IF.begin(WIMOD_LORAWAN_SERIAL_BAUDRATE);
    // init the communication stack
    wimod.begin();

    // debug interface
    PC_IF.begin(115200);

    printStartMsg();

    // do a software reset of the WiMOD
    delay(100);
    wimod.Reset();
    delay(100);
    // deactivate device in order to get a clean start for this demo
    wimod.DeactivateDevice();

    // do a simple ping to check the local serial connection
    debugMsg(F("Ping WiMOD: "));
    if (wimod.Ping() != true) {
        debugMsg(F("FAILED\n"));
    } else {
        debugMsg(F("OK\n"));


    // try to register the device at network server via OTAA procedure
    debugMsg(F("Starting join OTAA procedure...\n"));

    TWiMODLORAWAN_JoinParams joinParams;

    //setup OTAA parameters
    memcpy(joinParams.AppEUI, APPEUI, 8);
    memcpy(joinParams.AppKey, APPKEY, 16);

    // transfer parameters to WiMOD
    wimod.SetJoinParameter(joinParams);

    // Register callbacks for join related events
    wimod.RegisterJoinedNwkIndicationClient(onJoinedNwk);
    wimod.RegisterJoinTxIndicationClient(onJoinTx);

    // send join request
    if (wimod.JoinNetwork()) {
      RIB.ModemState = ModemState_ConnectRequestSent;
      debugMsg(F("...waiting for nwk response...\n"));
    } else {
      debugMsg("Error sending join request: ");
      debugMsg((int) wimod.GetLastResponseStatus());
      debugMsg(F("\n"));
    }
    }



  // Wait a maximum of 10s for Serial Monitor
 while (!debugSerial && millis() < 10000)
    ;

  debugSerial.println("-- STATUS");


   lpp.reset();
   lpp.addUnixTime(1, 135005160);
  lpp.addTemperature(1, 22.5);
  //lpp.addBarometricPressure(2, 1073.21);
  //lpp.addGPS(3, 52.37365, 4.88650, 2);

}


/*****************************************************************************
* Arduino loop function
****************************************************************************/

void loop()
{
  // check of OTAA procedure has finished
    if (RIB.ModemState == ModemState_Connected) {

        // send out a hello world every 30 sec ( =6* 50*100 ms)
      // (due to duty cycle restrictions 30 sec is recommended
        if ((loopCnt > 1) && (loopCnt % (6*50)) == 0) {
          // send out a simple HelloWorld messsage
            debugMsg(F("Sending HelloWorld message...\n"));

            // prepare TX data structure
            txData.Port = 0x01;
            txData.Length = strlen_P(PSTR("Hello World!"));
            strcpy_P((char*) txData.Payload, PSTR("Hello World!"));

            // try to send a message
            if (false == wimod.SendUData(&txData)) {
                // an error occurred

                 // check if we have got a duty cycle problem
                 if (LORAWAN_STATUS_CHANNEL_BLOCKED == wimod.GetLastResponseStatus()) {
                     // yes; it is a duty cycle violation
                     // -> try again later
                     debugMsg(F("TX failed: Blocked due to DutyCycle...\n"));
                 }
            }
        }
    }

    // check for any pending data of the WiMOD
    wimod.Process();

    delay(100);
    loopCnt++;

    debugSerial.println("-- LOOP");


  // Send it off
// ttn.sendBytes(lpp.getBuffer(), lpp.getSize());

  delay(10000);
}

is this the board you are using? https://www.youtube.com/watch?v=gP7_U7jog3E you can find the link to the library in the video description and inside the library there is exmaple code on cayenne.

Hi,

No the biard I am using is

The board succesfully registers in Actillity but when using its OTAA example conf in conjuction with LPP script, I get the error messages I mentionned.

can you share only the code which connect to actility without any other cayenne code.

Please find the code below:

/*
 * This is a simple example file to show how to use the WiMOD Arduino
 * library to communicate with a WiMOD Module by IMST GmbH
 *
 * http://www.wireless-solutions.de
 *
 */

/*
 * Example:
 *
 * This example demonstrates how to start a LoRaWAN OTAA procedure to "register"
 * the WiMOD to a LoRaWAN server
 *
 * Setup requirements:
 * -------------------
 * - 1 WiMOD module running WiMOD_LoRaWAN_EndNode_Modemfirmware
 *
 * Usage:
 * -------
 * - Change the keys according to your LoRaWAN server before starting
 * - Start the program and watch the serial monitor @ 115200 baud
 */


// make sure to use only the WiMODLoRaWAN.h
// the WiMODLR_BASE.h must not be used for LoRaWAN firmware.
#include <WiMODLoRaWAN.h>
#if defined(ARDUINO_ARCH_AVR)
#include <avr/pgmspace.h>
#endif

//-----------------------------------------------------------------------------
// platform defines
//-----------------------------------------------------------------------------
/*
 * Note: This sketch is for Arduino devices with two separate serial interfaces
 * (e.g. DUE). One interface is connected to a PC and one is used for WiMOD.
 *
 * For single serial interface boards (e.g. UNO) it is recommended to disbale
 * the PC / Debug messages
 */

#define WIMOD_IF    Serial3         // for WiMODino use: SerialWiMOD
#define PC_IF		Serial          // for WiMODino use: SerialUSB

//-----------------------------------------------------------------------------
// constant values
//-----------------------------------------------------------------------------

/*
 * OTAA Parameters
 */

// application  key (64bit)
const unsigned char APPEUI[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };

// application  key (128bit)
const unsigned char APPKEY[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
                         0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0f, 0x10 };




//-----------------------------------------------------------------------------
// user defined types
//-----------------------------------------------------------------------------

typedef enum TModemState
{
    ModemState_Disconnected = 0,
    ModemState_ConnectRequestSent,
    ModemState_Connected,
    ModemState_FailedToConnect,
} TModemState;


typedef struct TRuntimeInfo
{
    TModemState ModemState;
} TRuntimeInfo;


//-----------------------------------------------------------------------------
// section RAM
//-----------------------------------------------------------------------------

/*
 * Create in instance of the interface to the WiMOD-LR-Base firmware
 */
WiMODLoRaWAN wimod(WIMOD_IF);  // use the Arduino Serial3 as serial interface

TRuntimeInfo RIB = {  };

static uint32_t loopCnt = 0;
static TWiMODLORAWAN_TX_Data txData;



//-----------------------------------------------------------------------------
// section code
//-----------------------------------------------------------------------------

/*****************************************************************************
 * Function for printing out some debug infos via serial interface
 ****************************************************************************/
void debugMsg(String msg)
{
    PC_IF.print(msg);  // use default Arduino serial interface
}

void debugMsg(int a)
{
	PC_IF.print(a, DEC);
}

void debugMsgChar(char c)
{
	PC_IF.print(c);
}

void debugMsgHex(int a)
{
    if (a < 0x10) {
        PC_IF.print(F("0"));
    }
    PC_IF.print(a, HEX);
}


/*****************************************************************************
 * join tx indication callback
 ****************************************************************************/

void onJoinTx(TWiMODLR_HCIMessage& rxMsg) {
    TWiMODLORAWAN_TxIndData txData = {};
    wimod.convert(rxMsg, &txData);

    debugMsg(F("joining attempt: "));
    if (txData.FieldAvailability == LORAWAN_OPT_TX_IND_INFOS_INCL_PKT_CNT) {
        debugMsg((int) txData.NumTxPackets);
    }
    debugMsg(F("\n"));
}

/*****************************************************************************
 * joined network indication
 ****************************************************************************/

void onJoinedNwk(TWiMODLR_HCIMessage& rxMsg) {
    TWiMODLORAWAN_RX_JoinedNwkData joinedData;

    debugMsg(F("Join-Indication received.\n"));

    if (wimod.convert(rxMsg, &joinedData)) {
        if ((LORAWAN_JOIN_NWK_IND_FORMAT_STATUS_JOIN_OK == joinedData.StatusFormat)
                || (LORAWAN_JOIN_NWK_IND_FORMAT_STATUS_JOIN_OK_CH_INFO == joinedData.StatusFormat)){
            //Ok device is now joined to nwk (server)
            RIB.ModemState = ModemState_Connected;

            debugMsg(F("Device has joined a network.\n"));
            debugMsg(F("New Device address is: "));
            debugMsg((int) joinedData.DeviceAddress);
            debugMsg(F("\n"));
        } else {
            // error joining procedure did not succeed
            RIB.ModemState = ModemState_FailedToConnect;

            debugMsg(F("Failed to join a network.\n"));
        }
    }
}

/*****************************************************************************
 * rx data callback
 ****************************************************************************/
void onRxData(TWiMODLR_HCIMessage& rxMsg) {
    TWiMODLORAWAN_RX_Data radioRxMsg;
    int i;

    debugMsg("Rx-Data Indication received.\n");

    // convert/copy the raw message to RX radio buffer
    if (wimod.convert(rxMsg, &radioRxMsg)) {

  	if (radioRxMsg.StatusFormat & LORAWAN_FORMAT_ACK_RECEIVED) {
  		// yes, this is an ack
  		debugMsg(F("Ack-Packet received."));
  	}
        // print out the received message as hex string
        if (radioRxMsg.Length > 0) {
            // print out the length
            debugMsg(F("Rx-Message: ["));
            debugMsg(radioRxMsg.Length);
            debugMsg(F("]: "));

            // print out the payload
            for (i = 0; i < radioRxMsg.Length; i++) {
                debugMsgHex(radioRxMsg.Payload[i]);
                debugMsg(F(" "));
            }
            debugMsg(F("\n"));
        } else {
            // no payload included
//            debugMsg(F("Rx-Message with no Payload received; Status: "));
//	    debugMsg((int) radioRxMsg.StatusFormat);
          debugMsg(F("\n"));
        }
    }
}

/*****************************************************************************
 * print out a welcome message
 ****************************************************************************/
void printStartMsg()
{
    debugMsg(F("==================================================\n"));
    debugMsg(F("This is FileName: "));
    debugMsg(F(__FILE__));
    debugMsg(F("\r\n"));
    debugMsg(F("Starting...\n"));
    debugMsg(F("This simple demo will try to "));
    debugMsg(F("do the OTAA procedure and "));
    debugMsg(F("send a demo message each 30 sec.\n"));
    debugMsg(F("==================================================\n"));
}

/*****************************************************************************
 * Arduino setup function
 ****************************************************************************/
void setup()
{
    // wait for the PC interface to be ready (max 10 sec); usefull for USB
    while (!PC_IF && millis() < 10000 ){}

    // init / setup the serial interface connected to WiMOD
    WIMOD_IF.begin(WIMOD_LORAWAN_SERIAL_BAUDRATE);
    // init the communication stack
    wimod.begin();

    // debug interface
    PC_IF.begin(115200);

    printStartMsg();

    // do a software reset of the WiMOD
    delay(100);
    wimod.Reset();
    delay(100);
    // deactivate device in order to get a clean start for this demo
    wimod.DeactivateDevice();

    // do a simple ping to check the local serial connection
    debugMsg(F("Ping WiMOD: "));
    if (wimod.Ping() != true) {
        debugMsg(F("FAILED\n"));
    } else {
        debugMsg(F("OK\n"));


		// try to register the device at network server via OTAA procedure
		debugMsg(F("Starting join OTAA procedure...\n"));

		TWiMODLORAWAN_JoinParams joinParams;

		//setup OTAA parameters
		memcpy(joinParams.AppEUI, APPEUI, 8);
		memcpy(joinParams.AppKey, APPKEY, 16);

		// transfer parameters to WiMOD
		wimod.SetJoinParameter(joinParams);

		// Register callbacks for join related events
		wimod.RegisterJoinedNwkIndicationClient(onJoinedNwk);
		wimod.RegisterJoinTxIndicationClient(onJoinTx);

		// send join request
		if (wimod.JoinNetwork()) {
			RIB.ModemState = ModemState_ConnectRequestSent;
			debugMsg(F("...waiting for nwk response...\n"));
		} else {
		  debugMsg("Error sending join request: ");
		  debugMsg((int) wimod.GetLastResponseStatus());
		  debugMsg(F("\n"));
		}
    }

}


/*****************************************************************************
 * Arduino loop function
 ****************************************************************************/

void loop()
{
	// check of OTAA procedure has finished
    if (RIB.ModemState == ModemState_Connected) {

        // send out a hello world every 30 sec ( =6* 50*100 ms)
    	// (due to duty cycle restrictions 30 sec is recommended
        if ((loopCnt > 1) && (loopCnt % (6*50)) == 0) {
        	// send out a simple HelloWorld messsage
            debugMsg(F("Sending HelloWorld message...\n"));

            // prepare TX data structure
            txData.Port = 0x01;
            txData.Length = strlen_P(PSTR("Hello World!"));
            strcpy_P((char*) txData.Payload, PSTR("Hello World!"));

            // try to send a message
            if (false == wimod.SendUData(&txData)) {
                // an error occurred

                 // check if we have got a duty cycle problem
                 if (LORAWAN_STATUS_CHANNEL_BLOCKED == wimod.GetLastResponseStatus()) {
                     // yes; it is a duty cycle violation
                     // -> try again later
                     debugMsg(F("TX failed: Blocked due to DutyCycle...\n"));
                 }
            }
        }
    }

    // check for any pending data of the WiMOD
    wimod.Process();

    delay(100);
    loopCnt++;
}

try this. there are no complile error:

/*
 * This is a simple example file to show how to use the WiMOD Arduino
 * library to communicate with a WiMOD Module by IMST GmbH
 *
 * http://www.wireless-solutions.de
 *
 */

/*
 * Example:
 *
 * This example demonstrates how to start a LoRaWAN OTAA procedure to "register"
 * the WiMOD to a LoRaWAN server
 *
 * Setup requirements:
 * -------------------
 * - 1 WiMOD module running WiMOD_LoRaWAN_EndNode_Modemfirmware
 *
 * Usage:
 * -------
 * - Change the keys according to your LoRaWAN server before starting
 * - Start the program and watch the serial monitor @ 115200 baud
 */


// make sure to use only the WiMODLoRaWAN.h
// the WiMODLR_BASE.h must not be used for LoRaWAN firmware.
#include <WiMODLoRaWAN.h>
#if defined(ARDUINO_ARCH_AVR)
#include <avr/pgmspace.h>
#endif

#include <Cayenne/CayenneLPP.h>
#include <math.h>


//-----------------------------------------------------------------------------
// platform defines
//-----------------------------------------------------------------------------
/*
 * Note: This sketch is for Arduino devices with two separate serial interfaces
 * (e.g. DUE). One interface is connected to a PC and one is used for WiMOD.
 *
 * For single serial interface boards (e.g. UNO) it is recommended to disbale
 * the PC / Debug messages
 */

#define WIMOD_IF    Serial3         // for WiMODino use: SerialWiMOD
#define PC_IF    Serial          // for WiMODino use: SerialUSB

//-----------------------------------------------------------------------------
// constant values
//-----------------------------------------------------------------------------

/*
 * OTAA Parameters
 */

// application  key (64bit)
const unsigned char APPEUI[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };

// application  key (128bit)
const unsigned char APPKEY[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
                         0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0f, 0x10 };




//-----------------------------------------------------------------------------
// user defined types
//-----------------------------------------------------------------------------

typedef enum TModemState
{
    ModemState_Disconnected = 0,
    ModemState_ConnectRequestSent,
    ModemState_Connected,
    ModemState_FailedToConnect,
} TModemState;


typedef struct TRuntimeInfo
{
    TModemState ModemState;
} TRuntimeInfo;


//-----------------------------------------------------------------------------
// section RAM
//-----------------------------------------------------------------------------

/*
 * Create in instance of the interface to the WiMOD-LR-Base firmware
 */
WiMODLoRaWAN wimod(WIMOD_IF);  // use the Arduino Serial3 as serial interface

TRuntimeInfo RIB = {  };

static uint32_t loopCnt = 0;
static TWiMODLORAWAN_TX_Data txData;

// Cayenne related buffer and objects
#define BUF_SIZE_CAYENNE   20
static uint8_t bufCayenne[BUF_SIZE_CAYENNE];

// cayenne translation object
CayenneLPP cayenne(bufCayenne, BUF_SIZE_CAYENNE);



//-----------------------------------------------------------------------------
// section code
//-----------------------------------------------------------------------------

/*****************************************************************************
 * Function for printing out some debug infos via serial interface
 ****************************************************************************/
void debugMsg(String msg)
{
    PC_IF.print(msg);  // use default Arduino serial interface
}

void debugMsg(int a)
{
  PC_IF.print(a, DEC);
}

void debugMsgChar(char c)
{
  PC_IF.print(c);
}

void debugMsgHex(int a)
{
    if (a < 0x10) {
        PC_IF.print(F("0"));
    }
    PC_IF.print(a, HEX);
}


/*****************************************************************************
 * join tx indication callback
 ****************************************************************************/

void onJoinTx(TWiMODLR_HCIMessage& rxMsg) {
    TWiMODLORAWAN_TxIndData txData = {};
    wimod.convert(rxMsg, &txData);

    debugMsg(F("joining attempt: "));
    if (txData.FieldAvailability == LORAWAN_OPT_TX_IND_INFOS_INCL_PKT_CNT) {
        debugMsg((int) txData.NumTxPackets);
    }
    debugMsg(F("\n"));
}

/*****************************************************************************
 * joined network indication
 ****************************************************************************/

void onJoinedNwk(TWiMODLR_HCIMessage& rxMsg) {
    TWiMODLORAWAN_RX_JoinedNwkData joinedData;

    debugMsg(F("Join-Indication received.\n"));

    if (wimod.convert(rxMsg, &joinedData)) {
        if ((LORAWAN_JOIN_NWK_IND_FORMAT_STATUS_JOIN_OK == joinedData.StatusFormat)
                || (LORAWAN_JOIN_NWK_IND_FORMAT_STATUS_JOIN_OK_CH_INFO == joinedData.StatusFormat)){
            //Ok device is now joined to nwk (server)
            RIB.ModemState = ModemState_Connected;

            debugMsg(F("Device has joined a network.\n"));
            debugMsg(F("New Device address is: "));
            debugMsg((int) joinedData.DeviceAddress);
            debugMsg(F("\n"));
        } else {
            // error joining procedure did not succeed
            RIB.ModemState = ModemState_FailedToConnect;

            debugMsg(F("Failed to join a network.\n"));
        }
    }
}

/*****************************************************************************
 * rx data callback
 ****************************************************************************/
void onRxData(TWiMODLR_HCIMessage& rxMsg) {
    TWiMODLORAWAN_RX_Data radioRxMsg;
    int i;

    debugMsg("Rx-Data Indication received.\n");

    // convert/copy the raw message to RX radio buffer
    if (wimod.convert(rxMsg, &radioRxMsg)) {

    if (radioRxMsg.StatusFormat & LORAWAN_FORMAT_ACK_RECEIVED) {
      // yes, this is an ack
      debugMsg(F("Ack-Packet received."));
    }
        // print out the received message as hex string
        if (radioRxMsg.Length > 0) {
            // print out the length
            debugMsg(F("Rx-Message: ["));
            debugMsg(radioRxMsg.Length);
            debugMsg(F("]: "));

            // print out the payload
            for (i = 0; i < radioRxMsg.Length; i++) {
                debugMsgHex(radioRxMsg.Payload[i]);
                debugMsg(F(" "));
            }
            debugMsg(F("\n"));
        } else {
            // no payload included
//            debugMsg(F("Rx-Message with no Payload received; Status: "));
//      debugMsg((int) radioRxMsg.StatusFormat);
          debugMsg(F("\n"));
        }
    }
}

/*****************************************************************************
 * print out a welcome message
 ****************************************************************************/
void printStartMsg()
{
    debugMsg(F("==================================================\n"));
    debugMsg(F("This is FileName: "));
    debugMsg(F(__FILE__));
    debugMsg(F("\r\n"));
    debugMsg(F("Starting...\n"));
    debugMsg(F("This simple demo will try to "));
    debugMsg(F("do the OTAA procedure and "));
    debugMsg(F("send a demo message each 30 sec.\n"));
    debugMsg(F("==================================================\n"));
}

/*****************************************************************************
 * Arduino setup function
 ****************************************************************************/
void setup()
{
    // wait for the PC interface to be ready (max 10 sec); usefull for USB
    while (!PC_IF && millis() < 10000 ){}

    // init / setup the serial interface connected to WiMOD
    WIMOD_IF.begin(WIMOD_LORAWAN_SERIAL_BAUDRATE);
    // init the communication stack
    wimod.begin();

    // debug interface
    PC_IF.begin(115200);

    printStartMsg();

    // do a software reset of the WiMOD
    delay(100);
    wimod.Reset();
    delay(100);
    // deactivate device in order to get a clean start for this demo
    wimod.DeactivateDevice();

    // do a simple ping to check the local serial connection
    debugMsg(F("Ping WiMOD: "));
    if (wimod.Ping() != true) {
        debugMsg(F("FAILED\n"));
    } else {
        debugMsg(F("OK\n"));


    // try to register the device at network server via OTAA procedure
    debugMsg(F("Starting join OTAA procedure...\n"));

    TWiMODLORAWAN_JoinParams joinParams;

    //setup OTAA parameters
    memcpy(joinParams.AppEUI, APPEUI, 8);
    memcpy(joinParams.AppKey, APPKEY, 16);

    // transfer parameters to WiMOD
    wimod.SetJoinParameter(joinParams);

    // Register callbacks for join related events
    wimod.RegisterJoinedNwkIndicationClient(onJoinedNwk);
    wimod.RegisterJoinTxIndicationClient(onJoinTx);

    // send join request
    if (wimod.JoinNetwork()) {
      RIB.ModemState = ModemState_ConnectRequestSent;
      debugMsg(F("...waiting for nwk response...\n"));
    } else {
      debugMsg("Error sending join request: ");
      debugMsg((int) wimod.GetLastResponseStatus());
      debugMsg(F("\n"));
    }
    }

}


/*****************************************************************************
 * Arduino loop function
 ****************************************************************************/
float temperature;
int cnt = 0;
int x;

void loop()
{
  // check of ABP procedure has finished
    if (RIB.ModemState == ModemState_Connected) {

        // send out a hello world every 30 sec ( =6* 50*100 ms)
      // (due to duty cycle restrictions 30 sec is recommended
        if ((loopCnt > 0) && (loopCnt % (6*50)) == 0) {

            // prepare TX data structure

            temperature = sin( (float)cnt / 4.0f )*25.0f + 25.0f;
            cnt++;
            debugMsg(F("Temp: "));
            debugMsg(temperature);
            debugMsg(F("\n"));

            // reset old data
            cayenne.reset();
            // add the simulated temperature value
            cayenne.addTemperature(1, temperature);
            // add a simulated digital input value
            if (cnt % 2) {
                   cayenne.addDigitalInput(2, 1);
            } else {
                   cayenne.addDigitalInput(2, 0);
            }
            // add a simulated digital output value
            cayenne.addDigitalOutput(3, cnt);

            // setup plain data to send via LoRaWAN link
            txData.Port = 0x02;
            txData.Length = cayenne.getSize();
            cayenne.copy(txData.Payload);

            debugMsg("Raw-Payload-bytes: ");

            // try to send a message
            if (false == wimod.SendUData(&txData)) {
                // an error occurred

                 // check if we have got a duty cycle problem
                 if (LORAWAN_STATUS_CHANNEL_BLOCKED == wimod.GetLastResponseStatus()) {
                     // yes; it is a duty cycle violation
                     // -> try again later
                     debugMsg(F("TX failed: Blocked due to DutyCycle...\n"));
                 }
            }
        }
    }

    // check for any pending data of the WiMOD
    wimod.Process();

    delay(100);
    loopCnt++;
}

Dear Shramik,

Thank you very much for your assistance, I tried to connect my LoRA enabled device to Cayenne using LPP.

Thank you again

May I ask where do you think I could find sufficient info on hot to use a sleep timer with my ESP32?

I manage to get it working but the timer puts the device to sleep before transmission of LPP has started unfortunately,

Should I post such a question in the forum or it could be out of scope you think?

Best

Spyros

image002.jpg

It sounds like the LPP transmission is running asynchronous. There should be a callback for that function, call your sleep timer from there. If not you can always just add a dirty solution and use delay for an amount that always ends after the transmission finishes.

Hi again.

I did make some progress using a LTE board and the sensor , all connected to Cayenne.

I used a counter and and IF - ELSE statement within the loop that produces the sensor measurements as well as controls the sleep function.

I managed to get the sensor operating for some time interval and its results transported to Cayenne before the sleep command was enabled.

I am afraid tat the timer of the sleep command does not always work as I set to go to sleep in 6 minutes (360 sec) and the sleep is enabled at around 30 sec of board’s operation.

Have I understood correctly that the enable sleep is the function that controls in waht time interval the sensor will go to sleep or it controls how much time the sensor WILL SPEND in sleep?

Please find the code below

#define RX 32
#define TX 33

#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial

#define uS_TO_S_FACTOR 1000000 /* Conversion factor for micro seconds to seconds /
#define TIME_TO_SLEEP 5 /
Time ESP32 will go to sleep (in seconds) */

RTC_DATA_ATTR int bootCount = 0;

#define VIRTUAL_CHANNEL 0

//char ssid = “”;
//char wifiPassword="";

/* For Arduinoboards with multiple serial ports like DUEboard, interpret above two pieces of code and
directly use Serial1 serial port*/
int dist; //actual distance measurements of LiDAR
int strength; //signal strength of LiDAR
float temprature;
int check; //save check value
int i;
int uart[9]; //save data measured by LiDAR
const int HEADER=0x59; //frame header of data package

// Your GPRS credentials (leave empty, if missing)

const char apn = “”; // Your APN

const char gprsUser = “”; // User

const char gprsPass = “”; // Password

const char simPIN = “”; // SIM card PIN code, if any

// TTGO T-Call pin definitions

#define MODEM_RST 5

#define MODEM_PWKEY 4

#define MODEM_POWER_ON 23

#define MODEM_TX 27

#define MODEM_RX 26

#define I2C_SDA 21

#define I2C_SCL 22

// Set serial for debug console (to the Serial Monitor, default speed 115200)

#define SerialMon Serial

// Set serial for AT commands (to the module)

#define SerialAT Serial1

// Configure TinyGSM library

#define TINY_GSM_MODEM_SIM800 // Modem is SIM800

#define TINY_GSM_RX_BUFFER 1024 // Set RX buffer to 1Kb

#include <CayenneMQTTGSM.h>

char username = “”;

char password = “d”;

char clientID = “”;

// Define the serial console for debug prints, if needed

//#define TINY_GSM_DEBUG SerialMon

//#define DUMP_AT_COMMANDS

#include <Wire.h>

#include <TinyGsmClient.h>

TinyGsm modem(SerialAT);

void print_wakeup_reason(){
esp_sleep_wakeup_cause_t wakeup_reason;

wakeup_reason = esp_sleep_get_wakeup_cause();

switch(wakeup_reason)
{
case ESP_SLEEP_WAKEUP_EXT0 : Serial.println(“Wakeup caused by external signal using RTC_IO”); break;
case ESP_SLEEP_WAKEUP_EXT1 : Serial.println(“Wakeup caused by external signal using RTC_CNTL”); break;
case ESP_SLEEP_WAKEUP_TIMER : Serial.println(“Wakeup caused by timer”); break;
case ESP_SLEEP_WAKEUP_TOUCHPAD : Serial.println(“Wakeup caused by touchpad”); break;
case ESP_SLEEP_WAKEUP_ULP : Serial.println(“Wakeup caused by ULP program”); break;
default : Serial.printf(“Wakeup was not caused by deep sleep: %d\n”,wakeup_reason); break;
}
}

void GSM_SETUP() {

// Set console baud rate

SerialMon.begin(9600);

delay(10);

// Set-up modem reset, enable, power pins

pinMode(MODEM_PWKEY, OUTPUT);

pinMode(MODEM_RST, OUTPUT);

pinMode(MODEM_POWER_ON, OUTPUT);

digitalWrite(MODEM_PWKEY, LOW);

digitalWrite(MODEM_RST, HIGH);

digitalWrite(MODEM_POWER_ON, HIGH);

// Set GSM module baud rate and UART pins

SerialAT.begin(115200, SERIAL_8N1, MODEM_RX, MODEM_TX);

delay(3000);

// Restart takes quite some time

// To skip it, call init() instead of restart()

SerialMon.println(“Initializing modem…”);

modem.restart();

// Or, use modem.init() if you don’t need the complete restart

String modemInfo = modem.getModemInfo();

SerialMon.print("Modem: ");

SerialMon.println(modemInfo);

// Unlock your SIM card with a PIN if needed

if (strlen(simPIN) && modem.getSimStatus() != 3 ) {

modem.simUnlock(simPIN);
Serial.println("SIM Unlocked");

}

Cayenne.begin(username, password, clientID, SerialAT, apn, gprsUser, gprsPass, simPIN);

}

void GSM_LOOP() {

// Put ESP32 into deep sleep mode (with timer wake up)

Cayenne.loop();

}

void TFMINI_SETUP()
{
//Serial.begin(9600); //set bit rate of serial port connecting Arduino with computer
//Serial1.begin(115200); //set bit rate of serial port connecting LiDAR with Arduino
Serial2.begin(115200, SERIAL_8N1, RX, TX);

}

void TFMINI_LOOP() {

for (int k = 1; k <= 120; k++){

if (k <= 120 )
{
Cayenne.loop();

if (Serial2.available()) { //check if serial port has data input
//Serial.print("*");
if(Serial2.read() == HEADER) { //assess data package frame header 0x59
uart[0]=HEADER;
if (Serial2.read() == HEADER) { //assess data package frame header 0x59
uart[1] = HEADER;
for (i = 2; i < 9; i++) { //save data in array
uart[i] = Serial2.read();
}
check = uart[0] + uart[1] + uart[2] + uart[3] + uart[4] + uart[5] + uart[6] + uart[7];
if (uart[8] == (check & 0xff)){ //verify the received data as per protocol
dist = uart[2] + uart[3] * 256; //calculate distance value
strength = uart[4] + uart[5] * 256; //calculate signal strength value
temprature = uart[6] + uart[7] *256;//calculate chip temprature
temprature = temprature/8 - 256;
//Serial.println(“HEllo5”);

Serial.print("dist = ");

Serial.println(dist); //output measure distance value of LiDAR
Serial.print(“Loop Counter k:”);
Serial.println(k);
}

else {

// Increment boot number and print it every reboot
++bootCount;
Serial.println("Boot number: " + String(bootCount));

// Print the wakeup reason for ESP32
print_wakeup_reason();

esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
Serial.println(“Setup ESP32 to sleep for every " + String(TIME_TO_SLEEP) +
" Seconds”);

//Serial.println(“Going to sleep now”);

Serial.println(“Before SerialFlush”);
//Serial.flush();
Serial.println(“After SerialFlush”);
Serial.println(“Before Deep Sleep”);
esp_deep_sleep_start();
Serial.println(“After Deep Sleep”);
Serial.println(“This will never be printed”);

}
}
}
}
}

}

}

void setup() {
GSM_SETUP();
TFMINI_SETUP();
//SLEEP_SETUP();

}

void loop() {
GSM_LOOP();
TFMINI_LOOP();
//SLEEP_LOOP();
}

CAYENNE_OUT_DEFAULT(){
// Write data to Cayenne here. This example just sends the current uptime in milliseconds on virtual channel 0.

Cayenne.virtualWrite(VIRTUAL_CHANNEL, dist);

}

Thanks in advance

please do not create multiple post on same topic.