Sending a packet from RFM12Pi to Nodes

Hi,

i have build some wireless sensors (http://nathan.chantrell.net/tinytx-wireless-sensor/) to work with my Raspberry Pi and RFM12Pi modul I bought on OpenEnergyMonitor Shop.

I have uploaded a receiver sketch from github https://github.com/nathanchantrell/TinyTX/blob/master/TinyTX_Water_RX/Ti....

Everythings works fine with the wireless nodes! I can use them as a sender and receiver.

The question is how to send a packet / value to a specific node? So for example the sketch above expects value 999 or 100.

To send it with RFM12Pi I tried the following in terminal window:

999,30a

It this correct, because the receiver does not react? How can I send single values and how are the values decoded/splited on the receiver side?

Best regards,

Christian

 

pfeilc's picture

Re: Sending a packet from RFM12Pi to Nodes

Can anyone help me?

pb66's picture

Re: Sending a packet from RFM12Pi to Nodes

It looks like the payload structure expected by the TinyTX_Water_RX.ino is 2 integers, "sensor value" and "tx voltage"  which is 4 bytes.

You can only send values 0 to 255, if you try to send 999 directly it will probably get truncated at 8bits and become 231. to send 999 you need to send 2 byte values 231,3, (231 + 3*256),.there should also be 2 bytes for voltage eg 3.1volts would be 28,12, (28 + 12*256 = 3100 mV). the complete payload would then be 231,3,28,12,

Looking at line 56 of the TinyTX_Water_RX.ino it seems to be listening for node 1 set in line 21.

So you could try experimenting with 231,3,28,12,1a and see how you get on,

Paul

 

 

 

 

mharizanov's picture

Re: Sending a packet from RFM12Pi to Nodes

I have a wireless relay project that is controlled by rfm2pi board, my code (for atmega32u4) is here https://github.com/mharizanov/new_Funky/blob/master/examples/wireless_relay/wireless_relay.ino

 

you can adapt it to your need, but it has all you need to get going.

to turn the relay I send a "1,0,7s", to turn it off "0,0,7s"

 

pfeilc's picture

Re: Sending a packet from RFM12Pi to Nodes

Hi guys,

thank you very much! I hope this will help to fix my problem.
I will try it this evening.

I will also realize a wireless relais. I found out that there is a bistable relais boad which can be directly poerwerde by the TinyTX board. http://shop.ciseco.co.uk/3v-to-5v-bistable-latching-relay-kit/

Christian

[Two further copies of this post deleted. Moderator - RW]

pfeilc's picture

Re: Sending a packet from RFM12Pi to Nodes

Hi,

I think I finally solved the problem. Thank you su much guys! It took me days to find this out :-)

So I always have to send two comma seperated values for one payload variable in my sketch, is that correct? If i use these values with RFM2Pi and the sketch below, everthing works fine. I can control each PIN output and set it to low or high.

 

Channel 1 = ON
1,0,1,0,30a
 
Channel 1 = OFF
1,0,0,0,30a
 
Sketch (Attiny84)
 

//----------------------------------------------------------------------------------------------------------------------
// Using the TinyTX as a receiver for Status controls
//
// Licenced under the Creative Commons Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0) licence:
// http://creativecommons.org/licenses/by-sa/3.0/
//----------------------------------------------------------------------------------------------------------------------

//#define DEBUG     //uncomment enable serial printing

#include <JeeLib.h> // https://github.com/jcw/jeelib

#define MYNODE 30            //node ID of the receiever
#define freq RF12_433MHZ     //frequency
#define group 210            //network group

// Channel 4 = ON =  4,0,1,0,30a
// Channel 4 = OFF = 4,0,0,0,30a

 typedef struct {
          int channel;
          int channelState;
 } Payload;
 Payload rx;

 int nodeID;    //node ID of tx, extracted from RF datapacket. Not transmitted as part of structure

void setup () {

 pinMode(0, OUTPUT); 
 pinMode(3, OUTPUT); 
 pinMode(7, OUTPUT); 
 pinMode(8, OUTPUT); 
 pinMode(9, OUTPUT); 
 pinMode(10, OUTPUT); 
 
 rf12_initialize(MYNODE, freq,group); // Initialise the RFM12B

}

void loop() {

 if (rf12_recvDone() && rf12_crc == 0 ) {

  nodeID = rf12_hdr & 0x1F;  // get node ID
   
  rx = *(Payload*) rf12_data;

  int channel = rx.channel;
  int channelState = rx.channelState;

   if (RF12_WANTS_ACK) {                  // Send ACK if requested
     rf12_sendStart(RF12_ACK_REPLY, 0, 0);
   }

  digitalWrite(8, HIGH);
  delay(100);
  digitalWrite(8, LOW);
  
  if (channel == 1 && channelState == 1) {
    digitalWrite(0, HIGH);
  } else if (channel == 1 ) {
    digitalWrite(0, LOW); 
  }

  if (channel == 2 && channelState == 1) {
    digitalWrite(3, HIGH);
  } else if (channel == 2 ) {
    digitalWrite(3, LOW); 
  }

  if (channel == 3 && channelState == 1) {
    digitalWrite(7, HIGH);
  } else if (channel == 3 ) {
    digitalWrite(7, LOW); 
  }
  
  if (channel == 4 && channelState == 1) {
    digitalWrite(8, HIGH);
  } else if (channel == 4 ) {
    digitalWrite(8, LOW); 
  }

    
  if (channel == 5 && channelState == 1) {
    digitalWrite(0, HIGH);
  } else if (channel == 5 ) {
    digitalWrite(9, LOW); 
  }

  if (channel == 6 && channelState == 1) {
    digitalWrite(10, HIGH);
  } else if (channel == 6 ) {
    digitalWrite(10, LOW); 
  }

 }
 

}


Robert Wall's picture

Re: Sending a packet from RFM12Pi to Nodes

I don't believe you mean this:

if (channel == 5 && channelState == 1) {
digitalWrite(0, HIGH);
} else if (channel == 5 ) {
digitalWrite(9, LOW);
}

(the dangers of copy-and-paste!)

And I think you could make that selection code much clearer if you used 'switch' and the ternary operator.

digitalWrite(8, HIGH);
delay(100);
digitalWrite(8, LOW);

switch (channel)
{
   case 1 : digitalWrite(0, channelState == 1 ? HIGH : LOW);
   break;

   case 2 : digitalWrite(3, channelState == 1 ? HIGH : LOW);
   break;

etc...

}

pfeilc's picture

Re: Sending a packet from RFM12Pi to Nodes

I don't believe you mean this

 

Hi Paul! Of course a copy-and-paste problem. Thank you!

 

And I think you could make that selection code much clearer if you used 'switch' and the ternary operator.

 

Thank you, this will reduce the sketch size for the attiny84.

Many thanks!

Best regards, Christian
 

pb66's picture

Re: Sending a packet from RFM12Pi to Nodes

They are actually Roberts suggestions.

So I always have to send two comma seperated values for one payload variable in my sketch, is that correct? 

Only because the sketches declared "type def" structure dictates, for example if you change the "ints" for "chars" you would only need to send 1 value per payload variable and if you use Roberts suggestion you could just send one value to toggle the channels state, so just the 1 value would be required.

Paul 

pfeilc's picture

Re: Sending a packet from RFM12Pi to Nodes

Hi Paul,

excellent thank you!

I am new to programming Attiny's, but its really interesting!

Best regards,
Christian

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.