Tapatalk

myRadio.waitPacketSent() timing out

myRadio.waitPacketSent() timing out

14

PostNov 28, 2017#1

Hi,

I'm writing some demo programs. When they're done I was going to send them to Talk2 to use as part of their library for demo purposes (just to add some more choices for new users of the Talk2).

This program times out on the waitPacketSent() function (in the transmitVoltages() function) even if the timeout is set to 15 seconds! What am I doing wrong? I'd be grateful if someone could have a look. This program is the slave end. I've already written the master end, but I can't test it as I can't get the radio to send any data.

Many thanks

Mark

Code: Select all

/*
 * Talk2 Example: Wake periodic, transmit data, and go to sleep.
 *
 * This example demonstrates how you can use the Talk2 Library to transmit
 * data over the air, and power down all peripherals and the radio between 
 * transmissions.
 * 
 * The CPU wakes up every 8 seconds and increments a counter. When the counter
 * has been incremented 8 times (thus, every 64 seconds) the CPU will read
 * the VBAT and VIN supply voltages and send them over the air.
 * When the transmission is complete the CPU powers the radio down and then 
 * puts itself back to sleep.
 * 
 * The Sketch will uses a digitalWrite to blink the LEDs while transmitting
 *
 * This sketch is written specifically for the Talk2 Whisper Node, available
 * from http://talk2.wisen.com.au
 * 
 * Copyright 2017 by Mark Wills (markwills1970@gmail.com)
 *
 * This sketch is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 */
#include <T2WhisperNode.h>
#include <LowPower.h>


/* You need to configure the Whisper Node Version */
//#define T2_WPN_BOARD T2_WPN_VER_RF69
#define T2_WPN_BOARD T2_WPN_VER_LORA

#if T2_WPN_BOARD == T2_WPN_VER_RF69
  #include <RH_RF69.h>
  RH_RF69 myRadio;
#elif T2_WPN_BOARD == T2_WPN_VER_LORA
  #include <RH_RF95.h>
  RH_RF95 myRadio;
#endif


// flash memory handler object
T2Flash myFlash;


// Radio
uint8_t packetBuffer[(T2_MESSAGE_HEADERS_LEN + T2_MESSAGE_MAX_DATA_LEN)];

#define RADIO_FREQUENCY 868.1
#define RADIO_TX_POWER 13
#define HIGH_POWER true


// T2 Message
T2Message myMsg;
#define MASTER_ADDRESS 0x00
#define SLAVE_ADDRESS  0x01

uint16_t wakeCount; // counter for the number of times we've woken up


void setup()
{
  Serial.begin(115200);
  Serial.println(F("Example: Send data over radio and put radio and CPU to sleep "));
  Serial.println(F("This program sends the battery voltage (VBAT) and the main power"));
  Serial.println(F("supply voltage (VIN) over the air every 64 seconds (approximately)."));
  Serial.println(F("The CPU wakes up every 8 seconds and checks if 64 seconds has"));
  Serial.println(F("has elasped. If not, the CPU, flash, and radio go back to sleep."));
  Serial.println(F("If 64 seconds HAS elapsed, the voltages are checked, and then"));
  Serial.println(F("transmitted over the air, then everything goes back to sleep again.\n"));
  
  // Radio - Initialize the radio and put it to sleep to save energy
  if(myRadio.init()) {
    myRadio.setFrequency(RADIO_FREQUENCY);
    myRadio.setTxPower(RADIO_TX_POWER, HIGH_POWER); // we're using the high power Talk2 module
    
    // Flash - We're not using, so just power it down to save energy
    myFlash.init(T2_WPN_FLASH_SPI_CS);
    myFlash.powerDown();
    
    pinMode(6,OUTPUT); // set led pin as an output 
    Serial.println(F("Radio successfully initialised."));
  } else
      Serial.println(F("** Fatal error: Cannot intialise radio. **"));
}



void loop()
{
  // code starts running from here when the CPU wakes up
  
  if((++wakeCount)%8==0) {
    // ~64 seconds has elapsed... time to do some work
    Serial.println(F("I'm awake!"));
    transmitVoltages();
  } else
      Serial.println("Woke up. Nothing to do!");
  
  // put the radio and the CPU back to sleep
  Serial.println(F("Going back to sleep! ZZZZzzzz....\n"));
  Serial.flush();
  myRadio.sleep();
  LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF); 
}


void transmitVoltages() {
  uint16_t vBat, vIn;

  digitalWrite(6,HIGH); // led on
  
  // read the battery and supply voltages
  vBat=T2Utils::readVoltage(T2_WPN_VBAT_VOLTAGE, T2_WPN_VBAT_CONTROL);
   vIn=T2Utils::readVoltage(T2_WPN_VIN_VOLTAGE, T2_WPN_VIN_CONTROL);
  
  Serial.print(F("Battery voltage (mV):"));
  Serial.println(vBat);
  Serial.print(F(" Supply voltage (mV):"));
  Serial.println(vIn);
  
  uint8_t packetBufferLen = 0;
  
  // prepare a message to transmit over the air
  myMsg.cmd = 0xAA;
  myMsg.idx = 0x06;
  myMsg.src = SLAVE_ADDRESS;
  myMsg.dst = MASTER_ADDRESS;
  myMsg.data[0] = vBat >> 8;  // most significant 8 bits
  myMsg.data[1] = vBat;       // lower 8 bits
  myMsg.data[2] = vIn >> 8;   // most significant 8 bits
  myMsg.data[3] = vIn;        // lower 8 bits
  myMsg.len = 4; // set number of data items in message
  
  // Encode Message into a radio packet and get the full length
  myMsg.getSerializedMessage(packetBuffer, &packetBufferLen);
  
  // Send it (this turns the radio on automatically)
  myRadio.send(packetBuffer, packetBufferLen);
  bool success=myRadio.waitPacketSent(15000);

  if(success)
    Serial.println(F("Message sent succesfully."));
  else
    Serial.println(F("Timeout while sending message."));
  
  digitalWrite(6,LOW); // led off
}



PostNov 28, 2017#2

Update: The voltage-node demo program that comes with the WhisperNode library also locks up.

I'll try re-installing the libraries.

1885
1885

PostNov 28, 2017#3

Hi Mark,

Could you please confirm which board do you have, if it's a RF69 or a Lora (RF95)? You send another question earlier about your board supporting the RF96 drivers, which I've tested and it does not work. So I'm wondering if you really have the LoRa board, specially because you mentioned a "high power" version and the LoRa board has a single power configuration.

If you could provide a picture or the details written on the RF Module IC, it would assist identifying it. Alternatively, the order number is also possible to track it.

Regards

14

PostNov 28, 2017#4

Hi! Thanks for the reply. Sure - here's a some pics of the top and the bottom of the board.

Mark

IMG_20171128_154457063.jpg (4.17MiB)

IMG_20171128_154509544.jpg (4.41MiB)

PostNov 28, 2017#5

So, after your suggestion that I may have the wrong boards, I compared mine to the photos on the Wisen store and.... I've got the wrong boards!

Arse!

I'll have to order some more boards!

(how embarrassing! 😞)

PostNov 28, 2017#6

However, on a more positive note: At least I know why it isn't working!

I'll develop the code I was working on using these boards. They're just on my bench anyway!

Mark

1885
1885

PostNov 28, 2017#7

No worries Mark. You should be able to get your solution up and running on those boards and easily migrate to LoRa if you stick with the RadioHead library. The only thing won't work is if you decide try the LoRaWAN stack, which requires LoRa hardware.