And here is the RX code:
#include <T2WhisperNode.h>
#include <RH_RF69.h>
String inputString = ""; // a String to hold incoming data
boolean stringComplete = false; // whether the string is complete
//Define bedroom variables
float bedroomtemp;
float bedroomhum;
int bedroombatvolt;
int bedroomsupvolt;
// LED
T2Led myLedBlue(T2_WPN_LED_1);
T2Led myLedYellow(T2_WPN_LED_2);
// RFM69 Radio
#define RADIO_FREQUENCY 433.0
#define RADIO_TX_POWER 13
#define RADIO_ENCRYPTION_KEY { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x00, 0x05, 0x01, 0x02, 0x03, 0x05 }
RH_RF69 myRadio;
uint8_t radioBuf[(T2_MESSAGE_HEADERS_LEN + T2_MESSAGE_MAX_DATA_LEN)];
// T2 Message
T2Message myMsg;
//Define node addresses
#define nodeBedRoom 0x91
#define baseAddr 0x0C
// T2 Data Buffer
T2DataBuffer myDataBuffer;
void serialEvent() {
while (Serial.available()) {
// get the new byte:
char inChar = (char)Serial.read();
// add it to the inputString:
inputString += inChar;
inputString.trim();
// if the characters get recognized jump to main code and execute printing
if (inChar == '\n') {
stringComplete = true;
}
}
}
void setup()
{
// Serial
Serial.begin(115200);
// reserve 200 bytes for the inputString:
inputString.reserve(200);
Serial.println(F("Probe base node for receiving data from probes:"));
// Radio
myRadio.init();
myRadio.setModemConfig(RH_RF69::FSK_Rb125Fd125);
myRadio.setFrequency(RADIO_FREQUENCY);
uint8_t myRadioEncryptionKey[] = RADIO_ENCRYPTION_KEY;
myRadio.setEncryptionKey(myRadioEncryptionKey);
myRadio.setTxPower(RADIO_TX_POWER);
// LED Example
myLedYellow.setBlink(20, 3000, -1); // LED will lit for 20ms every 3000ms, forever
}
void loop()
{
if (stringComplete) {
if (inputString == "getbedroom") {
Serial.print("bedroomth: ");
Serial.print(bedroomtemp/100.0, 2);
Serial.print(',');
Serial.print(bedroomhum/100.0, 2);
Serial.print(" bedroombatvolt: ");
Serial.print(bedroombatvolt);
Serial.print("mV");
Serial.print(" bedroomsupvolt: ");
Serial.print(bedroomsupvolt);
Serial.println("mV");
}
// clear the string:
inputString = "";
stringComplete = false;
}
// LED Example
myLedBlue.run();
myLedYellow.run();
// Run the Receiving function
runReceiver();
}
void runReceiver()
{
/* RFM69 Receive */
uint8_t radioBufLen = sizeof(radioBuf);
if(myRadio.recv(radioBuf, &radioBufLen))
{
myMsg.setSerializedMessage(radioBuf, radioBufLen);
// The next is for debugging only to print every message. Uncomment bellow to print every received message, just be careful as
// delays here can cause messages to be lost.
myMsg.printMessage();
// If the message is initiated with sdx = 0x0a we know this is the temperature message
if(myMsg.idx == 0x05 && myMsg.sdx == 0x0a && myMsg.src == nodeBedRoom && myMsg.dst == baseAddr)
{
// Lets blink something
myLedBlue.setBlink(10, 0, 1); // LED will lit for 10ms only once, so the interval doesn't matter
switch(myMsg.sdx)
{
default:
// Read the part from the message that holds the temp reding and save it to a variable
bedroomtemp = myMsg.data[2] * 256 + myMsg.data[3];
break;
}
}
// If the message is initiated with sdx = 0x0b we know this is the humidity message
else if(myMsg.idx == 0x05 && myMsg.sdx == 0x0b && myMsg.src == nodeBedRoom && myMsg.dst == baseAddr)
{
// Lets blink something
myLedBlue.setBlink(10, 0, 1); // LED will lit for 10ms only once, so the interval doesn't matter
switch(myMsg.sdx)
{
default:
// Read the part from the message that holds the hum reding and save it to a variable
bedroomhum = myMsg.data[2] * 256 + myMsg.data[3];
break;
}
}
// If the message has idx = 0x06 we know that this is the voltage readings from probe node
else if(myMsg.idx == 0x06 && myMsg.src == nodeBedRoom && myMsg.dst == baseAddr)
{
// Lets blink something
myLedBlue.setBlink(10, 0, 1); // LED will lit for 10ms only once, so the interval doesn't matter
switch(myMsg.sdx)
{
case 0x64: // Battery Voltage
// Concatenate 2 bytes into a uint16_t variable
bedroombatvolt = myMsg.data[2] << 8;
bedroombatvolt |= myMsg.data[3];
break;
case 0x65: // Power Supply Voltage
// Concatenate 2 bytes into a uint16_t variable
bedroomsupvolt = myMsg.data[2] << 8;
bedroomsupvolt |= myMsg.data[3];
break;
}
}
}
}
}
}
And what comes to this weird way of filling the message on the TX end:
// Prepare Temperature Message and send
myMsg.cmd = 0x03; // Return Data
myMsg.idx = 0x05; // HID and Sensors
myMsg.sdx = 0x0a; // Temperature
myMsg.data[0] = 0x01; // Operation Temp in Celcius * 100
myMsg.data[1] = 0x01; // Sensor ID - we only have 1 in this case
myMsg.data[2] = t >> 4;
myMsg.data[2] = h >> 4;
myMsg.data[3] = t;
myMsg.data[3] = h;
myMsg.len = 8; // Update length
sendMessage();
Yep it does not make any sense but could this work by just making the message longer and having temperature and humidity in their own “data slots” and then on the receiving end just read both and multiply myMsg.data[2] and myMsg.data[3] by 256 to get the decimal values?:
// Prepare Temperature Message and send
myMsg.cmd = 0x03; // Return Data
myMsg.idx = 0x05; // HID and Sensors
myMsg.sdx = 0x0a; // Temperature
myMsg.data[0] = 0x01;
myMsg.data[1] = 0x01;
myMsg.data[2] = t >> 8; //temperature
myMsg.data[3] = h >> 8; //humidity
myMsg.len = 4; // Update length
sendMessage();