I printed the readings in the setup() and loop() functions. Readings are normal until I get to DEVICE_STATE_SEND it starts printing zeros and abnormal values. Loop function is below, denoted the last place where data is normal.
void loop()
{
switch( deviceState )
{
case DEVICE_STATE_INIT:
{
#if(AT_SUPPORT)
getDevParam();
#endif
printDevParam();
LoRaWAN.init(loraWanClass,loraWanRegion);
deviceState = DEVICE_STATE_JOIN;
break;
}
case DEVICE_STATE_JOIN:
{
LoRaWAN.join();
///////////////////////////// here is the last place where data is normal ////////////////
break;
}
case DEVICE_STATE_SEND:
{
//////////////////////////////////////////////// here it outputs zeros and weird values ///////////////
pinMode(PWM2,INPUT);
pulse1 = pulseIn(PWM2, HIGH);
sensor1 = pulse1/147;
printReadings();
prepareTxFrame( appPort );
LoRaWAN.send();
deviceState = DEVICE_STATE_CYCLE;
break;
}
case DEVICE_STATE_CYCLE:
{
// Schedule next packet transmission
txDutyCycleTime = appTxDutyCycle + randr( 0, APP_TX_DUTYCYCLE_RND );
LoRaWAN.cycle(txDutyCycleTime);
deviceState = DEVICE_STATE_SLEEP;
break;
}
case DEVICE_STATE_SLEEP:
{
LoRaWAN.sleep();
break;
}
default:
{
deviceState = DEVICE_STATE_INIT;
break;
}
}
}