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
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
}
