using RFM2PI to send packets from another program.

Hi.

Maybe this question is trivial, but my knownledge in programing is self-learned and I can only understand some pieces of code.

My configuration is: Raspberry plus RFM2PI (v2), emoncms running and php gateway installed.

This is in the emoncms side, I want the raspberry to remote operate my opensprinkler. OpenSprinkler (rayshobby.net) is a garden watering project, the diy version of the board has a RFM12B socket wich is not used, what I think it would be great is to take the part of the code where the valves are opened:

def setShiftRegister(srvals):
    GPIO.output(pin_sr_clk, False)
    GPIO.output(pin_sr_lat, False)
    for s in range(num_stations):
        GPIO.output(pin_sr_clk, False)
        GPIO.output(pin_sr_dat, srvals[num_stations-1-s])
        GPIO.output(pin_sr_clk, True)
    GPIO.output(pin_sr_lat, True)

(this comes from https://github.com/rayshobby/opensprinkler/blob/master/OpenSprinkler%20Pi/software/demos/interval_program/OSPi/ospi.py LINE 397)

and insert the code to send a single packet to a remote node using the RFM2PI gateway.

 

I can spend hours trying, but maybe someone can just say if it is possible or I have to use other gateway (phyton one or oem one)..... or may be someone just know how to code it it just a minute ;)

 

Thanks for reading

 

 

Robert Wall's picture

Re: using RFM2PI to send packets from another program.

I don't know about the RFM12Pi, but the standard RFM12 is certainly capable of that. In fact, a pair of sketches that will do almost exactly what you want with a pair of emonTxs was mentioned only yesterday: RF_checker_tx.ino and RF_checker_rx.ino). In these the Tx sketch sends "0" and "1" alternately - you would obviously send "1" when you want the sprinker on, and "0" when you want it off. I can't tell you how to do that with the RPi, but no doubt somebody round here can.

At the receiving end (and you can use an emonTx or an Arduino) you wire a solenoid operated valve where the LED is (or on another output if you wish), but you may need to interpose a high power driver circuit between the digital output and the coil.

xz81's picture

Re: using RFM2PI to send packets from another program.

On the end side I have no problem, in fact, there are several options, I am planning to made a very similar circuit of the OpenSprinkler but with one Moteino ( lowpowerlab.com ), a shift register and some transistors, I have already started it in a proto board:

but I supose this is for the hardware subforum ;)

Mattia Rossi's picture

Re: using RFM2PI to send packets from another program.

Whatever solution/code you use, please keep in mind that you are substituting a piece of code that talks directly with the gpios with something that has the possibility of not being received for whatever reason on the other end, so in order to avoid the sprinklers not starting (or even worse not stopping) at a given time you will have to introduce some checks in order to make sure that the commands you send are received and acknowledged...

xz81's picture

Re: using RFM2PI to send packets from another program.

First of all I have to know how to interact with RFM2PI, I though on that, later I can look to the data format I send, for example, instead of sending the opening/close command I can send the interval program to run (valve1 time=240 sec) and in the end side read that and open the valve only certain time without waiting for the closing order

Jérôme's picture

Re: using RFM2PI to send packets from another program.

I think everything is in place to let you do that.

I understand you have everything on the end side, and the control on the code, so you can decide of the protocol.

On the RPi side, you're using the RFM2Pi through a software gateway (in your case, the php code) that holds the serial port. I don't think you can use another program in parallel on the same serial port (and if you can, expect trouble), so you'd rather adapt the code of the gateway to do that.

Perhaps the design choice depends on what kind of inputs you want, how you want to command the sprinklers: will it be automatic (a script) ? or via a web GUI ? a "heavy" software client ? a ssh connection ?

I developped an alternative gateway (which I think is usable already with approximately no regression from the php script) and someone asked recently for an equivalent feature:

https://github.com/Jerome-github/oem_gateway/issues/10#issuecomment-2475...

It is interesting and it will probably be done. It's quite simple, actually.

Basically, it would add the possibility for the software gateway to listen to a socket for data frames to repeat with the RFM2Pi.

The use case is a third party software (script or any interface) that formats the data to be sent (Node ID, values) and feeds it to the gateway. Then the gateway repeats it on the RF link when it gets the time, ensuring there is no access conflict to the RFM2Pi.

This may be an acceptable solution for you.

manicmoddin's picture

Re: using RFM2PI to send packets from another program.

I too am looking for a way to do this.

I use the Home easy setup through out the house and on One PC (Pi) have the emoncms, but it is a little unstable as the cpu load is 3+, so am looking at moving onto another PC that is already on all the time.

This PC currently has a Arduino clone attached via USB and is used to send commands from this to the home easy remote sockets dotted around the house, and also is used as a backup emoncms server that is fead from the pi.

Also this 2nd PC has the event module on it which interfaces with its own webserver to talk to the arduino over the USB/SERIAL port.

I cannot workout how the raspberry pi module works to put the serial commands into the php script so that I can issue the home easy command over the serial when it is needed.

 

I am trying to avoid getting a jee link etc to do this, or making a usb2Serial -> max232 -> rfm12pi which would work, but take 2 usb ports.

calypso_rae's picture

Re: using RFM2PI to send packets from another program.

The pair of sketches that Robert mentioned are simply to check out an RF-link.  An alternating HIGH/LOW signal is transmitted, and used to drive an LED on/off at the remote end.  If the RF-link fails, the LED will remain in its previous state forever - not good for a water sprinkling project.  Nor would it be good when diverting surplus power; if the remote load were to remain 'on' for any reason, the customer would have to pick up the bill.

In my sketch for the remote end of a Mk2 Router system, there is a timeout period (3 seconds I think), after which the load will automatically turn off if RF transmission is lost.  A refresh signal is normally sent by the transmitted every second.  A similar kind of "watchdog" approach may be useful here.

manicmoddin's picture

Re: using RFM2PI to send packets from another program.

I cannot workout how the raspberry pi module works to put the serial commands into the php script so that I can issue the home easy command over the serial when it is needed.

Ok, I think I have an idea,

I know how to parse a text file in PHP, also how to create and write to one so here goes my idea.

With there being a while loop in there that is always true

while (true)

This is a good place to put any logic of the sort. In this I will write a little routine that checks a text file and then depending on the contents of the file writes to the serial port for the Arduino to pick up and then parse in the same way as before.

This I will post on here if it works fine so that it can be developed further if needs be.

 

Jimmy

manicmoddin's picture

Re: using RFM2PI to send packets from another program.

It does seam to work, saving 0l to the file ook.txt in the raspberrypi folder I can turn the status light on and off...

This is the code i used

      //parse a text file for info on whether to issue a command over serial or not
      $ookName = "/var/www/emoncms/Modules/raspberrypi/ook.txt";
      $ookSize = filesize($ookName);
      
      if($ookSize != 0){
        $ookFile = fopen($ookName, "c");
        $ookData = file_get_contents($ookName);
        fclose($ookFile);
        $ookFile = fopen($ookName, "w+");
        fclose($ookFile);
        echo $ookData;
        // put the commands to send to the Adruino here
        fprintf($f,$ookData); 
      }

and the start of this is on line 155 just before it starts to read the serial data.

Now to write the other bit that will write to this file, shouldnt be too bad to amend as I am already telling it to write directly to the Serial port.

Is there a better way to document this at all?

Oh and to start off with I did create the file first and give the ook.txt full permissions (Chmod 777) this then made it work.

Jérôme's picture

Re: using RFM2PI to send packets from another program.

Hi.

Not 100% sure I'm relevant here, but I added a new feature to the python gateway.

Basically, I extended the action of the piece of code that communicates with the RFM2Pi through the serial port, so that it also listens to a socket for data frames to repeat on the RF link.

Typical use case: send data to a RF Node on the network.

Just configure an unused port in the config file, and send data frames from an external program of your choice.

An exemple of such a program in python is provided:

https://github.com/Jerome-github/oem_gateway/blob/master/examples/OemGat...

 

manicmoddin's picture

Re: using RFM2PI to send packets from another program.

Hi,

I know this has been dormant for a while, but recently as I have come out of hibernation, I have found myself wanting to bring down the bills further, and in a means to this, I have setup another EmonCMS server to have a play around on, so I don't kill the working one.

However I found that just echoing the command to the energy monitor worked.
Personally I use a JeenodeUSB and have two relays on a home brewed transmitter and can turn both relays on with the following command in Linux.

echo "1,1,17s" > /dev/ttyUSB0

Again, had to make sure that the serial port (/dev/ttyUSB0) has 777 permissions, but this meant that I can just write scripts and call them from cron jobs

Jimmy

Comment viewing options

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